Ana*_*lov 8 javascript mapbox-gl-js
我使用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]);
}
});
Run Code Online (Sandbox Code Playgroud)
关于jsfiddle的工作示例 https://jsfiddle.net/L3hm8rur/
ash*_*ish 14
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);
})
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3040 次 |
| 最近记录: |