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 @@ + + +
+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); });