我目前正在做一个使用angular- leaflet -directive +leaflet markercluster插件的项目。
我想做的是,在某个事件上(例如,+/-缩放级别或当聚类组改变时),我希望有一个函数运行,它返回当前未聚类的所有标记。
这样做的原因是因为我想让所有可见的标记都有一个围绕它的圆路径(20海里,但这真的不重要)。
有没有人知道这是否可能?
谢谢你的帮助。请让我知道您可能需要的其他信息,我会尽我最大的努力将其提供给您。
干杯!
发布于 2015-10-05 22:07:32
创建markerClusterGroup后,您可以执行以下操作:
// Let's assume you have a global map variable that refers to the Leaflet Map
MyClusterGroup.eachLayer(function(feature) {
// the cluster group holds all the features
// but only the ones not clustered are added to the map
if (map.hasLayer(feature)) {
feature.setStyle({ // Only feature not clustered will have their style re-render
fillColor : "red"
});
// Do whatever your want with this feature, you have full access to it
}
});就性能而言,这可能不是最好的做法,但我猜这对您的情况很好。否则,您应该潜入标记插件代码,并直接修改/扩展它以满足您的需求。
发布于 2019-11-06 00:49:36
这个问题很老了,但我也有同样的问题。
我的解决方案是遍历我的标记,并检查它们是否在边界内。如果标记是群集的,则标记的属性映射为null。
var bounds = map.getBounds();
for (var i = 0; i < markers.length; i++) {
if(typeof markers[i] !== "undefined"){
if( bounds.contains(markers[i].getPosition()) && markers[i].map !== null){
console.log(markers[i])
}
}
}https://stackoverflow.com/questions/32793019
复制相似问题