简体   繁体   English

MarkerClusterer是群集中的标记?

[英]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. 我有15个标记。 10 of these are in clusters in the map. 其中10个在地图中成簇。 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 (ie 5 infoboxes have to be visible)? 如何定义像isInCluster(marker)这样的函数,信息框只​​在标记中打开,不在任何集群中(即5个信息框必须可见)?

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. 如果标记的地图位于群集中, MarkerClusterer会将标记的地图设置为null ,以便它不再显示在地图上。 The MarkerClusterer will then set the marker's map back to map anytime it is no longer in a cluster. 然后MarkerClusterer将标记的地图设置回map只要它不再在群集中。 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. 显然,在放大,缩小或任何其他视口更改后,标记的状态可能会发生变化,因此您必须在视口更改后重新检查。

Look this example http://88.196.132.133/markerclusterer/ , it does not work properly with infoboxes. 看看这个例子http://88.196.132.133/markerclusterer/ ,它与信息框无法正常工作。 It is necessary that all the markers (if they are out of clusters) is always displayed with infoboxes. 所有标记(如果它们不在簇中)必须始终显示信息框。 The problem is also that all the infoboxes open for a moment when loading a page. 问题还在于加载页面时所有信息框都会打开一会儿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM