6

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

4

2 回答 2

8

MarkerClusterer标记的地图设置为null是否在集群中,以便它不再显示在地图上。然后MarkerClusterer将标记的地图设置回map它不再在集群中的任何时间。您可以尝试检查每个标记:

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...

显然,标记的状态可能会在放大、缩小或任何其他视口更改后发生变化,因此您必须在视口更改后重新检查。

于 2012-05-09T10:58:01.883 回答
-2

看这个例子http://88.196.132.133/markerclusterer/,它不能与信息框一起正常工作。必须始终使用信息框显示所有标记(如果它们不在群集中)。问题还在于加载页面时所有信息框都会打开片刻。

于 2012-05-10T12:00:03.063 回答