Search code examples
google-mapsmarkerclusterer

Get the top 5 clusters by markers size inside it - MarkerclusterPlus


Am using MarkerclusterPlus for clsutering on google maps api. I need to find out the top 5 clusters formed based on the cluster size(marker size).

var totalCluster = that.markerCluster.getTotalClusters();

Using this i can get the total clusters how can i move from here to get that.


Solution

  • The method getClusters() of the markerClusterer returns an array containing all clusters.

    when you iterate over this array you may access the markers inside the cluster by using the method getMarkers() of the cluster. The length-property of the returned array gives you the number of markers in the current cluster.

    Create an array from these informations , sort it and then use Array.slice() on the resulting array to fetch the top n.