问题最接近post。但似乎它还没有解决(我无法评论),我想提供更多信息。
首先,我正在使用Inline GeoJSON,尝试分配一些随机点,例如:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
99.140625,
9.44906182688142
]
}
};
结果始终为[0,0]。它与经度和纬度无关。
顺便说一句,作者的例子是一个边界,经过测试,也没有显示出来。但在这里我想首先测试一个点。
我错过了什么?
答案 0 :(得分:0)
我不知道你的代码的其余部分是什么,但你提供的geojson工作正常。
检查此剪辑
var format = new ol.format.GeoJSON();
var myGeoJsonFeatures = format.readFeatures(
myGeoJson,
{featureProjection: 'EPSG:3857'}
);
vector.getSource().addFeatures(myGeoJsonFeatures);
还有一个工作小提琴fiddle。
也许它与您在地图上投影的投影有关
答案 1 :(得分:0)
"source": {
"type": "GeoJSON",
"geojson": {
"object": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "op",
"properties": {
"name": "aaa"
},
"geometry": {
"type": "Point",
"coordinates": [
-9.520376,
38.231155
]
}
}
]
},
"projection": "EPSG:4326"
}
显然,有必要指定投影信息! 感谢pavlos,因为他的代码提示......