我正在尝试使用 Mapbox 渲染多个点,但它只显示最后一个点。我已经添加了功能参数,但什么也没有。这应该渲染两个标记,但我不知道为什么不渲染。我在控制台中没有收到任何错误。
我被困住了,找不到解决的方法。帮忙?
这是负责点的代码:
map.on('load', function() {
map.loadImage('images/celltower.png', function(error, image) {
if (error) throw error;
map.addImage('tower', image);
map.addLayer({
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [21.42559803007430, 42.00038270989050]
},
"geometry": {
"type": "Point",
"coordinates": [21.38529272846381, 42.0080397578202]
}
}]
}
},
"layout": {
"icon-image": "tower",
"icon-size": 0.25
}
});
});
});
谢谢:)
最佳答案
您有一个重复的geometry
键。从 features
是一个数组的事实来看,我猜这是正确的方法:
map.on('load', function() {
map.loadImage('images/celltower.png', function(error, image) {
if (error) throw error;
map.addImage('tower', image);
map.addLayer({
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [21.42559803007430, 42.00038270989050]
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [21.38529272846381, 42.0080397578202]
}
}]
}
},
"layout": {
"icon-image": "tower",
"icon-size": 0.25
}
});
});
});
根据GeoJSON specification ,应该有一种方法来指定多个点。例如:
"features": [{
"type": "Feature",
"geometry": {
"type": "MultiPoint",
"coordinates": [
[21.42559803007430, 42.00038270989050],
[21.38529272846381, 42.0080397578202]
]
}
}]
关于javascript - Mapbox:它渲染最后一个点而不是所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48470646/