Mapbox GL JS:获取MultiPoint几何中的点索引

时间:2017-12-22 11:10:37

标签: javascript mapbox mapbox-gl-js

我有一个geojson.MultiPoint我正在Mapbox地图中显示:

let geojson = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {"type": "MultiPoint", "coordinates": [[1, 2], [3, 4], [...]]},
        "properties": {"status": "status"}
    }]
}

然后我添加了一个geojson源和一个圆圈层:

    map.addSource("gps-points", {
        type: "geojson",
        data: geojson,
    });

    map.addLayer({
        id: "gps-points",
        type: "circle",
        source: "gps-points",
        paint: {
            "circle-radius": 3,
            "circle-color": "#1f77b4",
        }
    });

我现在要做的是获取点击处理程序中点击的点的索引,如:

map.on("click", "gps-points", function(e) {
    // get the index of this point in the coordinates array
});

我知道我可以使用Point代替MultiPoint轻松完成此操作,但我必须可视化大量的点,Point不具备可扩展性。是否可以使用MultiPoint在Mapbox GL JS中执行此操作?

0 个答案:

没有答案