Google Maps InfoWindow on Clusters

后端 未结 2 1628
青春惊慌失措
青春惊慌失措 2020-12-29 12:54

I have a map with lots of markers. All these markers have a InfoWindow. With the Markers Cluster Lib, (http://google-maps-utility-library-v3.googlecode.com/svn/trunk/marker

2条回答
  •  一整个雨季
    2020-12-29 13:25

    I ended up solving this problem this way, adding the following code:

    var clusterOptions = {
        zoomOnClick: false
    }
    
    markerCluster = new MarkerClusterer(map, markers, clusterOptions);
    
    google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
    if (map.getZoom() < map.maxZoom ){
    
        map.setCenter(cluster.center_);
    
        map.setZoom(map.getZoom() + 2);
    } else {
    
        var content = '';
        // Convert the coordinates to an MVCObject
        var info = new google.maps.MVCObject;
        info.set('position', cluster.center_);
        //Get markers
        var marks_in_cluster = cluster.getMarkers();
    
        console.log(marks_in_cluster);
    
        for (var z = 0; z < marks_in_cluster.length; z++) {
            content = makeClusterInfo(marks_in_cluster,z); 
        }
    
        infowindow.close(); // closes previous open ifowindows
        infowindow.setContent(content); 
        infowindow.open(map, info);
        google.maps.event.addListener(map, 'zoom_changed', function() {
            infowindow.close()
        });
        } 
    });
    

提交回复
热议问题