0

i need to iterate over all clusters that are currently present in markercluster using leaflet. there's a method called markercluster.getClusters() in googlemaps to do this job.

is there something similar in leaflet too?

  • pls help..it's urgent!! – Akshay Jan 7 '15 at 16:46
4

To expand on @toms answer

map.eachLayer(function(layer){     //iterate over map rather than clusters
 if (layer.getChildCount){         // if layer is markerCluster
  console.log(layer._childCount);  // return count of points within each cluster
  }
});
2

if you mean iterate over all the individual points in an L.markerClusterGroup(), you can use something like this to access the individual layers

markers.eachLayer(function(layer){
  console.log(layer)
});

If you want to get at the points/layers in an individual cluster, you can use getAllChildMarkers()

markers.on('clusterclick', function (a) {
    console.log('cluster ' + a.layer.getAllChildMarkers().length);
});

additional documentation here

  • hey thanks for your early reply..i want to iterate over clusters not over markers in the markercluster.eg: if say suppose currently i can see 2 clusters on the screen, then i want to retive those two individual clusters. refer getClusters() method in google maps – Akshay Jan 8 '15 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.