Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarkerClusterer is marker in cluster?

I put markers into clusters:

var markerClusterer = new MarkerClusterer(map, markers, {
    zoomOnClick : false,
    maxZoom : 13,
    gridSize : 100
});

And i have 15 markers. 10 of these are in clusters in the map. How to determine if the marker is in a clusters.

var clusteredMarkers = markerClusterer.getTotalMarkers();
for(i = 0; i < clusteredMarkers.length; i++) {
    if(isInCluster((clusteredMarkers[i])) {
        clusteredMarkers[i].infobox.close();        
    }
}

How to define a function like isInCluster(marker) that infobox is open in only markers, that are not in any cluster (i.e. 5 infoboxes have to be visible)?

like image 626
iff Avatar asked May 09 '12 05:05

iff


People also ask

What are cluster markers?

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 map?

Stay organized with collections Save and categorize content based on your preferences. By clustering your markers, you can put a large number of markers on a map without making the map hard to read.


1 Answers

The MarkerClusterer will set a marker's map to null if it is in a cluster, so that it is no longer displayed on the map. The MarkerClusterer will then set the marker's map back to map anytime it is no longer in a cluster. You could try checking each of your markers:

var mapOptions = {            // Notice that mapZoom is not set
    center: new google.maps.LatLng( 19, 19 ),
    mapTypeId: google.maps.MapTypeId.ROADMAP };

map = new google.maps.Map( document.getElementById( "map_canvas" ), mapOptions );
var markerClusterer = new MarkerClusterer( map, markers, { ... });

//Whenever the map completes panning or zooming, the function will be called:
google.maps.event.addListener( map, "idle", function() {
    for ( var i = 0; i < markers.length; i++ ) {
        var mrkr = markers[i];
        if ( mrkr.getMap() != null ) {
            mrkr.infobox.open(); 
        }
        else {
            mrkr.infobox.close(); 
        }
    }
}

//Now that map, markerClusterer, and the "idle" event callback are in place,
//set the zoom, which will trigger the "idle" event callback 
//after the zoom activity completes,
map.setZoom( 19 ); //Or whatever is appropriate

//Thereafter, the callback will run after any pan or zoom...

Obviously, the state of the markers is likely to change after a zoom-in, zoom-out, or any other viewport change, so you will have to re-check after viewport changes.

like image 158
Sean Mickey Avatar answered Sep 18 '22 17:09

Sean Mickey