markerclusterer check if marker is in cluster

jaget picture jaget · Nov 23, 2011 · Viewed 12k times · Source

I have a web based map that is using the jquery-ui-map and markerclusterer plugin to make a google map.

I filter out which markers should be shown or not then update the map.

I need to create a list of unclustered markers and so to this end need a way to check clusters against markers and find out which are not clustered.

Is there any techniques to do this?

I have tried to cycle through clusters and manually check the markers against clusters but get an error telling me the clusters property var_clusterer.clusters_ is not defined.

Answer

hitautodestruct picture hitautodestruct · Jan 2, 2012

NOTE: This solution uses the MarkerClustererPlus library

You can use the getClusters() method to dish out an array of all the cluster objects currently being handled by MarkerClusterer.

var clusterManager = new MarkerClusterer( googleMap, markersArray, clusterOptions ); // setup a new MarkerClusterer

var clusters = clusterManager.getClusters(); // use the get clusters method which returns an array of objects

for( var i=0, l=clusters.length; i<l; i++ ){
    for( var j=0, le=clusters[i].markers_.length; j<le; j++ ){
        marker = clusters[i].markers_[j]; // <-- Here's your clustered marker
    }
}

After you get the array using getClusters() loop through the cluster objects. For each cluster you can pull the current markers_ array and retrieve your clustered marker.

getClusters() is now in the docs: MarkerClustererPlus docs