From 755180b753ce3d00ce5996d3b208231e6fd0e567 Mon Sep 17 00:00:00 2001 From: danzel Date: Thu, 2 Aug 2012 10:16:02 +1200 Subject: [PATCH] Add clearLayers implementation. Refs #26 --- src/MarkerClusterGroup.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 65ed7cbaa..417612ea2 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -63,6 +63,22 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ return this; }, + clearLayers: function () { + //Need our own special implementation as the LayerGroup one doesn't work for us + + //Remove all the visible layers + for (var i in this._layers) { + if (this._layers.hasOwnProperty(i)) { + L.FeatureGroup.prototype.removeLayer.call(this, this._layers[i]); + } + } + + //Reset _topClusterLevel + this._generateInitialClusters(); + + return this; + }, + //Overrides FeatureGroup.onAdd onAdd: function (map) { L.FeatureGroup.prototype.onAdd.call(this, map); @@ -70,6 +86,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ if (!this._topClusterLevel) { this._generateInitialClusters(); } + this._map.on('zoomend', this._zoomEnd, this); this._map.on('moveend', this._moveEnd, this); @@ -199,6 +216,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ currentZoom = this._map.getZoom(); this._topClusterLevel = this._clusterToMarkerCluster(this._needsClustering, maxZoom); + this._needsClustering = []; //Generate to the top while (minZoom < this._topClusterLevel._zoom) {