Is MarkerClusterer a marker in a cluster?

I put tokens in clusters:

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

And I have 15 markers. 10 of them are in clusters on the map. How to determine if a marker is in 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, such as isInCluster (marker), that the info box is open only in markers that are not in any cluster (i.e. 5 info boxes should be visible)?

+5
source share
2 answers

MarkerClustererwill install the marker map in nullif it is in the cluster so that it no longer appears on the map. MarkerClustererthen it will return the marker card to mapany time when it is no longer in the cluster. You can 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...

, , , , , .

+7
0

All Articles