From 238beee823828a5fad152c8bb4d2400d1bc45438 Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 27 Jul 2012 15:38:08 +1200 Subject: [PATCH] Fix another silly edge case: Spiderfy 2 markers, remove one from the clusterer, the other would disappear. --- src/MarkerCluster.Spiderfier.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js index 60cc22b71..60dbe0623 100644 --- a/src/MarkerCluster.Spiderfier.js +++ b/src/MarkerCluster.Spiderfier.js @@ -254,6 +254,16 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? { } setTimeout(function () { + //If we have only <= one child left then that marker will be shown on the map so don't remove it! + var stillThereChildCount = 0; + for (i = childMarkers.length - 1; i >= 0; i--) { + m = childMarkers[i]; + if (m._spiderLeg) { + stillThereChildCount++; + } + } + + for (i = childMarkers.length - 1; i >= 0; i--) { m = childMarkers[i]; @@ -265,7 +275,9 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? { m.setOpacity(1); m.setZIndexOffset(0); - L.FeatureGroup.prototype.removeLayer.call(group, m); + if (stillThereChildCount > 1) { + L.FeatureGroup.prototype.removeLayer.call(group, m); + } map.removeLayer(m._spiderLeg); delete m._spiderLeg;