this is the first time i use OpenLayers and i don't understand what i'm doing wrong.
I try to display a simple point parsed from GeoJSON. The data seems to be parsed correctly (i checked with the console) but whatever point i give, it always displays at a position i guess to be LonLat(0,0) on my vector layer.
What am i doing wrong ?
var map, baseLayer, placesLayer, geojsonParser ; // data below have been simplified and reformated to enhance readability var geojsonData = { "type":"Feature", "geometry": { "type":"Point", "coordinates":[-4.0280599594116,5.3411102294922] }, "properties": { "id":273, "name":"ABIDJAN" } }; $(document).ready(function(){ map = new OpenLayers.Map('map'); baseLayer = new OpenLayers.Layer.OSM(); placesLayer = new OpenLayers.Layer.Vector(); geojsonParser = new OpenLayers.Format.GeoJSON(); placesLayer.addFeatures(geojsonParser.read(geojsonData)); map.addLayers([baseLayer,placesLayer]); map.setCenter( new OpenLayers.LonLat(-4, 5.3).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 5 ); }); // document ready
This is the right solution:
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
source: https://gist.github.com/1118357
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With