Google Maps Api v3 - how to remove cluster icons?

我们两清 提交于 2019-11-29 01:16:48

Iterate over each marker and set that marker's map to null. That will remove the marker from the map.

HoffZ

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

Sergey Serduk

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

markerCluster = new MarkerClusterer(map);

This is what I do. I have many markers but when I switch to heatmap I want to remove all markers and clusterer. When i create marker I add it to global markers array

 markers.push(marker);

I define clustere like this

markerCluster = new MarkerClusterer(map, markers);
markerCluster.setIgnoreHidden(true);

When i click button to show heatmap

$.each(markers, function(k, v){
    v.setVisible(false);
});
markerCluster.repaint();

When repaint() is called with ignore hidden it hides all cluster icons.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!