Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Api v3 - how to remove cluster icons?

Tags:

how can i remove all cluster icons (cluster markers) from map? tryed with advices like:

Google Maps API v3: How to remove all markers?

... but it did not worked.

can you help me how to achieve that?

thank you in advance!

UPDATE (2010-11-23)

markers are stored in array with

var markersClust = Array(); 

... and are added with (combination with php):

markersClust.push(marker_<?php echo $team["Team"]["id"]; ?>);  var markerClusterer = new MarkerClusterer(MyMap.map, markersClust, clusterOptions); 

and it works fine.

but, i can not remove them from a map, and it drives me...

tryed to remove markers (and i did) with

for ( var i=0; i < markersClust.length; i++) {     markersClust[i].setMap(null); } markersClust = [];  

but cluster icons are stil on the map.

also i tryed things like:

markerClusterer.clearMarkers(); 

and like

MyMap.preventDefault(); MyMap.stopPropagation(); MyMap.clearMarkers(); 

but, again, icons of the clusters are still there, on a map.

what else do i have to do to remove those cluster icons from my map? please help...

like image 555
user198003 Avatar asked Nov 22 '10 20:11

user198003


People also ask

How do I remove a marker cluster from Google Maps?

Removing all markers You can then clear all the markers using clearMarkers something like this: markerClusterer. clearMarkers(); markers = [];

How do I remove a marker from Google Maps API?

You can delete the markers by removing them from the map and then setting the array's length to 0 , which removes all references to the markers.


2 Answers

This is the right way to do it:

// Unset all markers var i = 0, l = markers.length; for (i; i<l; i++) {     markers[i].setMap(null) } markers = [];  // Clears all clusters and markers from the clusterer. markerClusterer.clearMarkers(); 

Demo: http://jsfiddle.net/HoffZ/gEzxx/

Documentation: https://googlemaps.github.io/js-marker-clusterer/docs/reference.html

like image 90
HoffZ Avatar answered Sep 19 '22 19:09

HoffZ


I had the same problem as well. I fixed it by only declaring my MarkerClusterer once during initialization:

markerCluster = new MarkerClusterer(map); 
like image 32
Sergey Serduk Avatar answered Sep 18 '22 19:09

Sergey Serduk