Search code examples
google-maps-api-3addeventlistenermarkerclusterer

how to add listener for markerclusterer finished loading?


I already added a map load listener after which i start adding markers to the cluster. I wanna display a loading screen till the markerclusterer finishes the marker loading. so how do i do that ? this is my hide loading screen code which hides on map tiles load.

google.maps.event.addListener(map, 'tilesloaded', function() {
$("#loading").hide();
});

Solution

  • I know it's an old one but for anyone in the same situation I sort of found a solution.

    Right after you are creating your cluster

    markerCluster = new MarkerClusterer(map,
        markers,
        {
            imagePath:
                "/img/m/"
        });
    

    Add a listener for 'zoom_changed' like that:

    google.maps.event.addListenerOnce(map,
        'zoom_changed',
        function(event) {
            console.log("zoom occured");
        });
    

    (The listener once being key here, you don't want it to run every time the user zooms, you don't even need to set a different zoom value, nothing will happen visually)

    and then:

    map.setZoom(10);
    

    I am using the same value (10) as in my InitMap function, so the user doesn't see any zoom in or outs.