Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

markerclusterer check if marker is in cluster

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.

like image 746
jaget Avatar asked Nov 23 '11 16:11

jaget


People also ask

What is a cluster marker?

Marker clusters is the concept of sampling the data values into larger blocks in order to ease readability and increase performance. It is a simple solution to display a large number of markers on a map, or a chart. The number on a cluster shows how many markers it contains.

What is marker cluster in Google Maps?

When a user views the map at a high zoom level, the individual markers show on the map. When the user zooms out, the markers gather together into clusters, to make viewing the map easier. The marker clustering utility is part of the Maps SDK for Android Utility Library.


1 Answers

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

like image 65
hitautodestruct Avatar answered Oct 05 '22 23:10

hitautodestruct