mapbox - 在 mapbox gl 中使用 getSource 或 getLayer 获取几何(坐标)

标签 mapbox mapbox-gl-js

我有 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
        }
    });

最佳答案

getSourcegetLayer 并不是用来检索源数据的;访问源数据的唯一方法是使用 queryRenderedFeaturesquerySourceFeatures

关于mapbox - 在 mapbox gl 中使用 getSource 或 getLayer 获取几何(坐标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45962573/

相关文章:

reactjs - mapbox 图层的正确类型( typescript )在哪里?

swift - MapBox IOS SDK swift : how to show the user annotations from specific zoomLevel without delete and add again?

reactjs - 使用 React 在 Mapbox GL 中自定义标记

javascript - 动态 MySQL 查询以填充要在 MapBox GL-JS 中显示的 GeoJson 数据缓存

android - 加载自定义 .mbtiles 文件时出现 "No data"错误

javascript - 延迟加载不适用于由 leaflet/mapbox 添加的图像

javascript - 在现有示例的 Mapbox gl 上进行过滤

mapbox-gl-js - 是否可以动态添加到 kepler.gl 中的数据集

javascript - 基于本地 geojson 文件的 mapbox 3D 拉伸(stretch)

javascript - 在传单中寻找最短路径