Search code examples
google-mapsmarkerclusterer

Force an information window instead of zoom on click and change the icon


I'm using MarkerClusterer to group markers and I have 2 questions:

  1. What should I do to prevent the zoom on click and show an information window instead, like when you click a marker?
  2. Is there any way to change the icon of the cluster for the markers? I don't want to use the earthquake-like icon as a group icon for my markers.

Thanks in advance.

EDIT

var marker;
var gm_map;
var markerArray = [];
var address = 'Sweden';
var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'address': address }, function(results, status) {
    if(status == google.maps.GeocoderStatus.OK) {
        gm_map.setCenter(results[0].geometry.location);
        gm_map.fitBounds(results[0].geometry.bounds);
    } else {
        alert("Kunde inte genomföra den geologiska inställningen på grund av följande fel:\n\n" + status);
    }
});



function initialize() {
    var marker, i;

    var locations = [["content", 59.328626, 13.485686, 1]];


    var options_googlemaps = {
        minZoom: 4,
        maxZoom: 18,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: false
    }

    gm_map = new google.maps.Map(document.getElementById('google-maps'), options_googlemaps);


    var options_markerclusterer = {
        gridSize: 20,
        maxZoom: 18
    };

    var markerCluster = new MarkerClusterer(gm_map, [], options_markerclusterer, {zoomOnClick: false});
    google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
        alert('center of cluster: '+cluster.getCenter());
    });



    for(i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: gm_map
        });

        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
                $('#toggle-photolist').fadeIn();
                $('#close-overlay').fadeIn();
                $('#list-photos').html(locations[i][0]);
            }
        })(marker, i));

        markerArray.push(marker);
        markerCluster.addMarkers(markerArray, true);
    }
}



$(document).ready(function() {

    // INITIERA GOOGLE MAPS
    initialize();

});

WORKING zoomOnClick

var options_markerclusterer = {
    gridSize: 20,
    maxZoom: 18,
    zoomOnClick: false
};

var markerCluster = new MarkerClusterer(gm_map, [], options_markerclusterer);

Solution

  • re 1:

    var markerCluster = new MarkerClusterer(map, markers ,{zoomOnClick: false});
    google.maps.event.addListener(markerCluster,'clusterclick', 
        function(cluster){
          alert('center of cluster: '+cluster.getCenter())
        });
    

    The details for the cluster (what info can you get out of it) can be found here: https://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/markerclusterer/src/markerclusterer.js#801

    You can simply show an infoWidow with the center set to cluster.getCenter() in the callback and you will be all set.

    re2: Check out this sample with changed icons: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/advanced_example.html

    HTH