From 4e4cba28cb2b820837225cb050aa137dad3326d2 Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 27 Jul 2012 14:01:30 +1200 Subject: [PATCH] unspiderfy before adding/removing a layer --- src/MarkerClusterGroup.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 52a51b6cd..5fb9852a7 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -36,6 +36,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //If we have already clustered we'll need to add this one to a cluster + if (this._unspiderfy) { + this._unspiderfy(); + } + var newCluster = this._topClusterLevel._recursivelyAddLayer(layer, this._topClusterLevel._zoom - 1); this._animationAddLayer(layer, newCluster); @@ -44,7 +48,15 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ }, removeLayer: function (layer) { - this._topClusterLevel._recursivelyRemoveLayer(layer); + if (this._unspiderfy) { + this._unspiderfy(); + } + + if (!this._topClusterLevel._recursivelyRemoveLayer(layer)) { + //If this happens you are doing something bad + //If you've moved a marker that is in the cluster then that would be why + //console.log('failed to remove'); + } return this; },