I used to make GML vector like this:
layer = new OpenLayers.Layer.GML("based",
"./parser2.php",
{
isBaseLayer: true,
format: OpenLayers.Format.GeoJSON,
styleMap: new OpenLayers.StyleMap(mystyle),
units:"m",
maxResolution: 0.2,
minResolution: 0.01
})
map.addLayer(layer);
but is now depreciated an for multiple raison i need to use OpenLayers.Layer.Vector but i can't succed to read a geoJon file.
I tried like this:
var test = new OpenLayers.Layer.Vector("test", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
isBaseLayer: true,
url: "data.json",
styleMap: myStyles,
format: new OpenLayers.Format.JSON()
})
});
map.addLayer(test);
but unfortunately it's not working.
do you have any clue?
Thanks
I use the steps described in the following web page to add GeoJSON format data to a layer: http://thinkwhere.wordpress.com/2011/06/26/geocommons-geojson-in-openlayers/
As your GeoJSON is already correct format do not add {"type": "FeatureCollection", "features": ...} around the GeoJSON string, as shown in this example.
In plain English, the steps are:
Create a new OpenLayers.Layer.Vector layer without options to read data.
You read the URL yourself.
In the callback function called when reading is complete you create a OpenLayers.Format.GeoJSON() object, use it to read features from the GeoJSON string, then add the features to the layer.
Related
I am trying to find a way to pass a string variable (coming from a dictionary) into my website's data layer.
My array is built using the following snippet:
[{foreach from=$orderArticles item="currOrderArticle"}]
[{assign var="currBasePrice2" value=$currOrderArticle-getBasePrice()}]
product_list.push(
{
id: "[{$currOrderArticle-oxorderarticles__oxartnum->value}]",
price: [{$currBasePrice2->getBruttoPrice()}],
quantity: [{$currOrderArticle-oxorderarticles__oxamount->value}]
}
);
products_info.push(
{
transaction_id: '[{$order->oxorder__oxordernr-value}]',
transaction_cid: '[{$order->oxorder__oxuserid-value}]',
item_id: '[{$currOrderArticle-oxorderarticles__oxartnum->value}]',
item_value: '[{$basket-getDiscountedNettoPrice()}]',
item_quantity: '[{$currOrderArticle-oxorderarticles__oxamount->value}]'
}
);
[{/foreach}]
If I want to pass it to the data layer, I do the following:
dataLayer.push({
ProductsInfo: products_info
});
This works fine, the issue is that I actually want to modify this array.
I would like to apply the following to it before passing it into the data layer:
products_info|json_encode|escape:'url'
But when I try to do it during the push, it does not work:
dataLayer.push({
ProductsInfo: products_info|json_encode|escape:'url'
});
As I told you in another post, Smarty expressions must be enclosed in delimiters, in your case [{ and }]
Also, as you're using the string in javascript, it must be enclosed within quotes:
dataLayer.push({
ProductsInfo: '[{products_info|json_encode|escape:'url'}]'
});
I was wondering if it would be possible to format strings (in this case the string displayed in the field OrderDate) using the "attributes:{}" thing ( I do not know how I should call that. A tag? A property?)
NOTE: This is inside a kendogrid which gets JSON data from a remote server.
NOTE 2 : The attributes:{style:text-align:center;"} works just fine.
field : "OrderDate",
title : "Orderdatum",
attributes:{style:"text-align:center;"},
width : 170,
If there is anything else that I need to provide you with, do say so.
Thanks in advance everyone! And if this looks like I haven't searched or something, then I can assure you I have.
I thought this might help people get an idea of how it looks. What I want to achieve in my case is that IF the data is 3-3-2009 (the selected cell/row) that it shows as 03-03-2009. Is it possible to achieve it using attributes ?
Again, thanks in advance.
Edit 2:
This link tells me it is not possible to do it in CSS3. So my guess now is that I accidently have created a duplicate question. So let me rephrase my quesion: How can I format the string, not necessarily using attributes, so it looks how I explained I want it to look?
Edit 3:
I was supposed to include this.
As you can see what I get is a string and not a number.
schema: {
type : "json",
data : "SalesOrders.SalesOrder",
model: {
fields: {
OrderNo : {type: "string"},
OrderDate : {type: "string"},
DeliveryWeek : {type: "number"},
OrderTotal : {type: "number"},
OBJECTID : {type: "number"},
},
Yet again, thanks for your time to read my question.
In this scenario, you are unable to format the string using CSS3 (Like totally impossibru...)
Therefore, you need to format your JSON object once its loaded, before its passed into the grid for display.
Formatting of data (This link give you some idea on how you format the datasource)
http://www.telerik.com/forums/datasource-number-format
Formatting dates (This link give you idea on how to format dates)
http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting
If you are not comfortable with kendo formatting of dates (Yes, I hate it), you can use the sweet momentJS
http://momentjs.com/
BTW (EDITED)
Kendo grid date column not formatting
this is a quicker and cleaner way of using "template" attribute for formatting
We can combine the functionality (described in the following Kendo UI documentation) to reformat the date during the DataBound event:
http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting
http://docs.telerik.com/kendo-ui/api/web/grid#events-dataBound
[update]
Here's some generic code to convey the idea:
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "age" }
],
dataSource: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
],
dataBound: function(e) {
console.log("put your Date conversion logic here in the dataBound event");
}
});
I am attempting to use Leaflet with Leaflet Vector Layers (http://geojason.info/leaflet-vector-layers/) and ArcGIS Server. I've set up the popup template and I can view the features as expected. But, when I click on a feature to get information I receive an error: 'cannot read property 'y' of undefined.' Any suggestions would be greatly appreciated. The code I use to create the layer in question is below:
lyrHospitals = new lvector.AGS({
url: oHospitals.url + '/' + oHospitals.layerIds,
fields: '*',
//uniqueField: "onemap_prod.SDEADMIN.hls.OBJECTID",
popupTemplate: function (properties) {
return '<p>hello there</p>';
},
scaleRange: [10, 20],
symbology: {
type: 'single',
vectorOptions: {
icon: baseballIcon
}
},
singlePopup: true
});
I just updated Leaflet Vector Layers to work with Leaflet v0.4.x. Can you try with the latest Leaflet Vector Layers and let me know if you're still having this issue?
I am trying to create one map. I am using OSM as base layer and now I am trying to overlay my road network as GeoJSON. There is no error in my code (Checked by Firebug). I can view nice map of OSM but problem is there is not any road network on my OSM map. I do not know what I have done worng. Bellow, I have given my code.
I used following command to create GeoJSON from my console. I am using OSGeo Live (Ubuntu).
$ ogr2ogr -f "GeoJSON" roads.json roads.shp roads
JavaScript Code----
//OSM Layer-----------------------------------------------
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
map.addLayer(layer);
//GeoJSON Layer-------------------------------------------
var vector_format = new OpenLayers.Format.GeoJSON({});
var vector_protocol = new OpenLayers.Protocol.HTTP({
url: 'ml/roads.json',
format: vector_format
});
var vector_strategies = [new OpenLayers.Strategy.Fixed()];
var vector_layer = new OpenLayers.Layer.Vector('More Advanced Vector Layer',{
protocol: vector_protocol,
strategies: vector_strategies
});
map.addLayer(vector_layer);
//Projection-----------------------------------------------
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Thanks, in advance.
Is your GeoJSONĀ in EPSG:900913? You should try to set the projection of the map explicitely in your map constructor.
First you may try to set visibility to the layer once added to the map using layer.setVisibility(true)
Second you should look using firebug if the request to ml/road.json is done and that you got data for the part of the map you're looking.
Then you may want to refresh the layer, here is what I used in a pas project :
layer.refresh({force:true});
Finally you may try putting the layers directly in the Map constructor :
//OSM Layer-----------------------------------------------
var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
//GeoJSON Layer-------------------------------------------
var vector_format = new OpenLayers.Format.GeoJSON({});
var vector_protocol = new OpenLayers.Protocol.HTTP({
url: 'ml/roads.json',
format: vector_format
});
var vector_strategies = [new OpenLayers.Strategy.Fixed()];
var vector_layer = new OpenLayers.Layer.Vector('More Advanced Vector Layer',{
protocol: vector_protocol,
strategies: vector_strategies,
isBaseLayer: false
});
var options = {
layers: [layer, vector_layer]
};
var map = new OpenLayers.Map("Map", options);
//Projection-----------------------------------------------
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
I think your issue is one of projections. You could use OGRINFO to get data about the roads.shp file but probably the easiest for what it sounds like you are doing is to make OGR2OGR use the Spherical Mercator projection. You would do this by running OGR2OGR with the -t switch. This should look like
$ ogr2ogr -f "GeoJSON" roads.json roads.shp roads -t_srs EPSG:900913
Then make sure your map is using the Spherical Mercator projection
var map = new OpenLayers.Map('map',
{projection: new OpenLayers.Projection("EPSG:3857"),
sphericalMercator: true });
This is probably the easiest way to integrate everything with OSM using the same GCS, EPSG900913 and EPSG:3857 should be synonymous.
I'm new to Dojo, and I'm trying to get my head wrapped around some pretty basic concepts before my partner and I embark on a new project. I've been successful in using the ItemFileWriteStore to get data returned from an ajax request into a DataGrid, but I would like to use the new Memory store instead. I am using the ObjectStore adapter to wrap the Memory store, and data is being populated in the grid.
One thing has me worried. In the example code I'm running, there is some nested nodes in the JSON object I'm using to populate the grid. It's one of the Countries JSON object they use in the dojo documentation. Here's a little snippet of that object:
'items': [
{ 'name':'Africa', 'type':'continent', children:[
{ 'name':'Egypt', 'type':'country' },
{ 'name':'Kenya', 'type':'country', children:[
{ 'name':'Nairobi', 'type':'city' },
{ 'name':'Mombasa', 'type':'city' } ]
},
{ 'name':'Sudan', 'type':'country', 'children':
{ 'name':'Khartoum', 'type':'city' }
} ]
},
]
In the DataGrid instantiation, I send in a query and then I set the qureyOptions to {deep:true} like so:
var grid = new DataGrid({
style: "width: 500px; height: 300px;",
store: this._geoStore,
structure: layoutGeo,
rowSelector: '20px',
columnReordering: true,
query: {},
queryOptions: { deep: true },
rowsPerPage: 20
}, document.createElement("div"));
When I use the old ItemFileWriteStore, this works fine, and ALL the nested data is essentially flattened out and placed in the grid as I would expect. However, when I switch it over to a Memory store wrapped in an ObjectStore adapter, the only data displayed in the grid is the top most parent of the data object. In the case of the sample data, only the data associated with Africa, but none of its children, are displayed. So it seems that the queryOptions {deep:true} statement has no affect when using the Memory store.
Is there some way of getting nested data within the JSON objects into a data grid using a Memory store wrapped in an ObjectStore? I would have thought that the wrapper class would have taken care of this, and it might, but I don't know how to fix it.
For all who help, thank you very much for your time and willingness to share your expertise. I really have studied the dojo docs and web for a long time trying to figure this stuff out. I fear I may have glossed over something obvious and am hoping you all can help.
I blogged about the store changes at http://swingingcode.blogspot.com/2012/03/dojo-implementing-viewmodelstore.html
The code here uses the new store object but brings the reference notation from the data api. All objects would be considered top level objects and query-able. I did not implement the logic to pull out nested objects.