Leafletjs - GeoJSON 层未显示
Leafletjs - GeoJSON layer not showing
我已经创建了代码的 jsfiddle,但我不知道为什么标记没有显示。
var map = L.map('map', {
center: [8.99665, 38.81573],
zoom: 13,
});
var addis = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
id: 'addis',
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
var aa = {
"type": "Feature",
"properties": {
"name": "Megenagna",
},
"geometry": {
"type": "Point",
"coordinates": [9.019720, 38.802933]
}
};
new L.GeoJSON(aa).addTo(map);
这是 jsfiddle url:http://jsfiddle.net/m2ju1m3v/
拜托,有人可以对此有所启发吗?
谢谢!
GeoJSON 中的坐标被指定为 [longitude, latitude]
形式的数组,与 Leaflet 相反,它是 [latitude, longitude]
.
因此,您只需将坐标更改为:
"coordinates": [38.802933, 9.019720]
已更新 jsfiddle:http://jsfiddle.net/m2ju1m3v/2/
注意:请使用 Leaflet 版本 0.7.7 而不是 0.6.4。
实际上,添加了标记,但它位于 Sardina(意大利)的南部。那是因为 GeosJON 坐标顺序:第一个 longitude
,第二个 latitude
.
为什么只使用 GeoJSON 添加标签?您可以只使用 marker
方法来实现它:
new L.marker([8.99665, 38.81573]).addTo(map);
我已经创建了代码的 jsfiddle,但我不知道为什么标记没有显示。
var map = L.map('map', {
center: [8.99665, 38.81573],
zoom: 13,
});
var addis = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
id: 'addis',
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
var aa = {
"type": "Feature",
"properties": {
"name": "Megenagna",
},
"geometry": {
"type": "Point",
"coordinates": [9.019720, 38.802933]
}
};
new L.GeoJSON(aa).addTo(map);
这是 jsfiddle url:http://jsfiddle.net/m2ju1m3v/
拜托,有人可以对此有所启发吗? 谢谢!
GeoJSON 中的坐标被指定为 [longitude, latitude]
形式的数组,与 Leaflet 相反,它是 [latitude, longitude]
.
因此,您只需将坐标更改为:
"coordinates": [38.802933, 9.019720]
已更新 jsfiddle:http://jsfiddle.net/m2ju1m3v/2/
注意:请使用 Leaflet 版本 0.7.7 而不是 0.6.4。
实际上,添加了标记,但它位于 Sardina(意大利)的南部。那是因为 GeosJON 坐标顺序:第一个 longitude
,第二个 latitude
.
为什么只使用 GeoJSON 添加标签?您可以只使用 marker
方法来实现它:
new L.marker([8.99665, 38.81573]).addTo(map);