我有 5 个 geojson 层 - 每个层都有一行。我想用 map.getSource 或 map.getLayer 获取线的坐标,但我没有看到任何几何属性。 我可以用这个得到坐标:
var features = map.queryRenderedFeatures({layers:[layerName]});
console.log(features[0].geometry);
我的 geojson 是:
var layer = map.addLayer({
"id": layerName,
"type": "line",
"source": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": line
}
}
},
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "red",
"line-width": 13
}
});
最佳答案
getSource
和 getLayer
并不是用来检索源数据的;访问源数据的唯一方法是使用 queryRenderedFeatures
或 querySourceFeatures
关于mapbox - 在 mapbox gl 中使用 getSource 或 getLayer 获取几何(坐标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45962573/