From 5719cb94ffc0001eab2e2a7fa149c566e46b9da3 Mon Sep 17 00:00:00 2001 From: Duncan Parkes Date: Wed, 17 Oct 2012 12:08:22 +0100 Subject: [PATCH] Fix issue #79. When a MarkerClusterGroup has been on a map, but isn't any longer, we still need to clear out its markers. (cherry picked from commit 2a90a86326aee1afd0392efd019d9cdb3f6dd0d0) Conflicts: dist/leaflet.markercluster.js --- dist/leaflet.markercluster-src.js | 10 +++++++--- src/MarkerClusterGroup.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dist/leaflet.markercluster-src.js b/dist/leaflet.markercluster-src.js index 2c4a3e632..0f02a59a9 100644 --- a/dist/leaflet.markercluster-src.js +++ b/dist/leaflet.markercluster-src.js @@ -190,7 +190,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //If we aren't on the map yet, just blow away the markers we know of if (!this._map) { this._needsClustering = []; - return this; + this._gridClusters = undefined; + this._gridUnclustered = undefined; + // return this; } if (this._unspiderfy) { @@ -204,8 +206,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ } } - //Reset _topClusterLevel and the DistanceGrids - this._generateInitialClusters(); + if (this._map) { + //Reset _topClusterLevel and the DistanceGrids + this._generateInitialClusters(); + } return this; }, diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index c4affab81..f92745dc1 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -183,7 +183,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //If we aren't on the map yet, just blow away the markers we know of if (!this._map) { this._needsClustering = []; - return this; + this._gridClusters = undefined; + this._gridUnclustered = undefined; + // return this; } if (this._unspiderfy) { @@ -197,8 +199,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ } } - //Reset _topClusterLevel and the DistanceGrids - this._generateInitialClusters(); + if (this._map) { + //Reset _topClusterLevel and the DistanceGrids + this._generateInitialClusters(); + } return this; },