From 4b12ba627491ea9dab3ee2f4c6e5409974c18238 Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 14 Sep 2012 10:41:37 +1200 Subject: [PATCH] Add another edge test case and fix. --- example/old-bugs/remove-add-clustering.html | 75 +++++++++++++++++++++ src/MarkerClusterGroup.js | 11 +++ 2 files changed, 86 insertions(+) create mode 100644 example/old-bugs/remove-add-clustering.html diff --git a/example/old-bugs/remove-add-clustering.html b/example/old-bugs/remove-add-clustering.html new file mode 100644 index 000000000..7ee36fc42 --- /dev/null +++ b/example/old-bugs/remove-add-clustering.html @@ -0,0 +1,75 @@ + + + + Leaflet debug page + + + + + + + + + + + + + + + + + + +
+

Whenever a marker is clicked it is removed from the clusterer and added directly to the map instead.

+

Click Marker on Left, zoom out 1 layer, click marker on right.

+

Expected behaviour: Both markers are shown. Bugged behaviour: Both markers are on map with opacity 0.

+

+
+	
+
+
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 212c5ced7..26aeceacc 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -108,6 +108,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 		if (layer._icon) {
 			L.FeatureGroup.prototype.removeLayer.call(this, layer);
+			layer.setOpacity(1);
 		}
 		return this;
 	},
@@ -646,6 +647,16 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
 		//When the animations are done, tidy up
 		setTimeout(function () {
 
+			//This cluster stopped being a cluster before the timeout fired
+			if (cluster._childCount == 1) {
+				var m = cluster._markers[0];
+				//If we were in a cluster animation at the time then the opacity and position of our child could be wrong now, so fix it
+				m.setLatLng(m.getLatLng());
+				m.setOpacity(1);
+
+				return;
+			}
+
 			cluster._recursively(bounds, newZoomLevel, 0, function (c) {
 				c._recursivelyRemoveChildrenFromMap(bounds, previousZoomLevel + 1);
 			});