我正在使用Leaflet.markercluster。
这是我的代码,基于各种相关问题:
// Takes an L.markerClusterGroup as input parameter
Self.GetNumMarkersInClusterGroup = function(clusterGroup)
{
Self.map.eachLayer(function (layer) {
if (layer.getChildCount) {
// somehow need to check here for our desired cluter group
console.log('Cluster group has ' + layer._childClusters.length + 'layers') ;
console.log('With a total of ' + layer._childCount + ' markers');
}
});
} // GetNumMarkersInClusterGroup()但是,layer.getChildCount是没有定义的:-(我做错了什么?
相关问题:
发布于 2021-01-16 06:06:08
的确,在如何使用Leaflet.markercluster插件时可能会出现一些混淆:
L.markerClusterGroup()时得到的如果您的clusterGroup实际上是一个MCG,那么您可以简单地使用这样一个事实:它扩展了传单标准特性组和层组,特别是它有一个方法
返回添加到组中的所有层的数组。
因此,如果您想要在您的MCG中的标记总数,您可以做例如clusterGroup.getLayers().length
为了完整起见,MCG还拥有Leaflet.markercluster文档中提到的“分组方法”方法。
方法 (和getAllChildMarkers())是用于集群标记的,例如,当您使用"clusterclick"事件时,这些标记就是这样的。
https://stackoverflow.com/questions/65744569
复制相似问题