Google maps v3 marker manager doesn't hide markers if I zoom out automatically after initialization

1.6k Views Asked by At

I draw a polyline to a google maps, and put markers to every point of it. I want to hide these markers higher zoom levels, therefore I use the Marker Manager. It's works well.

After draw everything, the map zoom to the bound of the polyline with the google.map.fitBound command. But if it zoom to far, where the markers would be hided, they don't. They still visible. If I drag or zoom again, they are hiding.

I use the markermanager in the simple way:

var aMarkers [...array of markers...],
markerMgr = new MarkerManager(map);

google.maps.event.addListener(markerMgr, 'loaded', function() {
    markerMgr.addMarkers(aMarkers[0], 15, 0);
    markerMgr.addMarkers(aMarkers[1], 12, 0);
    markerMgr.addMarkers(aMarkers[2], 10, 0);
    markerMgr.refresh();
});

Is anybody met this problem before? Thank is advance!

2

There are 2 best solutions below

1
geocodezip On

Why do you have the maximum zoom for the markers set to 0?

MarkerManager.addMarkers(aMarkers[0], minZoom, maxZoom(optional))

Try (that parameter is optional per the documentation):

var aMarkers [...array of markers...],
markerMgr = new MarkerManager(map);

google.maps.event.addListener(markerMgr, 'loaded', function() {
    markerMgr.addMarker(aMarkers[0], 15);
    markerMgr.addMarker(aMarkers[1], 12);
    markerMgr.addMarker(aMarkers[2], 10);
    markerMgr.refresh();
});

Working Example

0
user2195309 On

I had this same problem. When creating your markers, don't set the "map" parameter in the marker options. The MarkerManager will add the markers to your map as you zoom in and out.

For example:

var newMarker = new google.maps.Marker({
    //map: map
    position: markerPosition,
    icon: icon
});
mgr.addMarker( newMarker, 9 );