gpt4 book ai didi

javascript - map 框。通过单击集群获取点列表

转载 作者:数据小太阳 更新时间:2023-10-29 04:01:23 29 4
gpt4 key购买 nike

我使用 Mapbox GL JS,但遇到了集群问题。我添加一些图层我想通过单击集群来获取集群点列表。

map.on('click', function(e) {
var cluster = map.queryRenderedFeatures(e.point, { layers: ["cluster"] });

if (cluster.length) {
// get clustered points here
console.log(cluster[0]);
}
});

jsfiddle 上的工作示例 https://jsfiddle.net/L3hm8rur/

最佳答案

Mabox GL JS 库现在支持该功能。

这是 API 文档 - https://www.mapbox.com/mapbox-gl-js/api/#geojsonsource#getclusterchildren

集群下如何获取积分?

map.on('click',/* cluster layer id */ 'clusters', function (e) {

var features = map.queryRenderedFeatures(e.point, { layers: ['clusters'] });
var clusterId = features[0].properties.cluster_id,
point_count = features[0].properties.point_count,
clusterSource = map.getSource(/* cluster layer data source id */'cluster-source');

// Get Next level cluster Children
//
clusterSource.getClusterChildren(clusterId, function(err, aFeatures){
console.log('getClusterChildren', err, aFeatures);
});

// Get all points under a cluster
clusterSource.getClusterLeaves(clusterId, point_count, 0, function(err, aFeatures){
console.log('getClusterLeaves', err, aFeatures);
})

});

关于javascript - map 框。通过单击集群获取点列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38651290/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com