这是我第一次使用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
2 回答
这是正确的解决方案:
来源:https://gist.github.com/1118357
嗨,听起来你需要将long / lat coordinaites转换为正确的显示坐标:
您可以声明投影,然后转换几何体特征:
或者“动态”获取 Map 投影更像是这样的:
显然,如果您使用的是我不同的输入投影,请将“ESPG:4326”更改为您需要的任何内容 .
HTH
C
编辑:
在你的情况下,你需要写如下: