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:
OpenLayers.Layer.Vectorlayer without options to read data.OpenLayers.Format.GeoJSON()object, use it to read features from the GeoJSON string, then add the features to the layer.