In OpenLayers I want to create a map from Vector data only like in the example http://openlayers.org/dev/examples/all-overlays.html .
My code is the following:
var map
function init() {
map = new OpenLayers.Map({div: "map",
allOverlays: true,
maxExtent: new OpenLayers.Bounds(-2.3261712491512,0.14062285423279,2.2441412508488,4.2363278567791)});
var vector_layer = new OpenLayers.Layer.Vector('GeoJSON Test',
{
protocol: new OpenLayers.Protocol.HTTP({
url: 'geojsontest.json',
format: new OpenLayers.Format.GeoJSON({})
}),
strategies: [new OpenLayers.Strategy.Fixed()],
});
map.addLayers(vector_layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
if(!map.getCenter()){
map.zoomToMaxExtent();
}
}
</script>
</head>
<body onload='init();'>
<div id='map' style='width: 500px; height: 500px;'></div>
</body>
Which tells me that I have no baselayer defined. Do I define the bounds right? My TestGeoJSON file is
{"type": "FeatureCollection",
"features": [{"type":"Feature", "properties":{}, "geometry" {"type":"Point", "coordinates":[0.9843747317791, 2.2441412508488]}},
{"type":"Feature", "properties":{}, "geometry":{"type":"Point", "coordinates":[4.2363278567791, -2.3261712491512]}},
{"type":"Feature", "properties":{}, "geometry":{"type":"Point", "coordinates":[-2.2675783932209, -0.04101499915123]}},
{"type":"Feature", "properties":{}, "geometry":{"type":"Point", "coordinates":[0.14062285423279, 1.0781300067902]}}
]
}
The jsonfile and layer were rendered correctly when I had an OSM baselayer beyond it, so the error is somewhere else? I just wanted to set the "allOverlays: true" parameter to the map-function and set the bounds. I know that it is possible but I am somehow stuck on this - can you help me?
Thanks so much! Steve
I have solved the problem:
source is now:
var map;
function init() {
map = new OpenLayers.Map({
div: "map",
allOverlays: true,
maxExtent: new OpenLayers.Bounds(
-90,-180,90,180
)
});
var vectors = new OpenLayers.Layer.Vector("Lines", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "geojsontest.json",
format: new OpenLayers.Format.GeoJSON()
}),
});
map.addLayer(vectors);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
works fine. :) cheerio!