OpenLayers:解析的GeoJSON点始终显示在coords(0,0)

m_x*_*m_x 4 point vector openlayers coordinates geojson

这是我第一次使用OpenLayers而且我不明白我做错了什么.

我尝试显示一个从GeoJSON解析的简单点.数据似乎正确解析(我用控制台检查)但无论我给出什么点,它总是显示在我猜测我的矢量图层上的LonLat(0,0)的位置.

我究竟做错了什么 ?

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

小智 7

这是正确的解决方案:

var geojson_format = new OpenLayers.Format.GeoJSON({
                'internalProjection': new OpenLayers.Projection("EPSG:900913"),
                'externalProjection': new OpenLayers.Projection("EPSG:4326")
            });
Run Code Online (Sandbox Code Playgroud)

来源:https://gist.github.com/1118357