diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js index c41c5af30c..a477496284 100644 --- a/src/MarkerCluster.js +++ b/src/MarkerCluster.js @@ -229,5 +229,11 @@ L.MarkerCluster = L.Marker.extend({ childClusters[k]._recursivelyRemoveChildrenFromMap(depth - 1); } } + }, + + //Returns true if we are the parent of only one cluster and that cluster is the same as us + _isSingleParent: function () { + //Don't need to check this._markers as the rest won't work if there are any + return this._childClusters.length > 0 && this._childClusters[0]._childCount == this._childCount; } }); \ No newline at end of file diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 4b18466651..98041da025 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -430,9 +430,14 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? { c = startingClusters[i]; startPos = c.getLatLng(); - //Fade out old cluster - c.setOpacity(0); - c._recursivelyAddChildrenToMap(startPos, depth, bounds); + if (c._isSingleParent()) { + L.FeatureGroup.prototype.removeLayer.call(this, c); + c._recursivelyAddChildrenToMap(null, depth, bounds); + } else { + //Fade out old cluster + c.setOpacity(0); + c._recursivelyAddChildrenToMap(startPos, depth, bounds); + } } //Remove all markers that aren't visible any more @@ -484,7 +489,13 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? { c._recursivelyAnimateChildrenIn(this._map.latLngToLayerPoint(c.getLatLng()).round(), depth); if (bounds.contains(c._latlng)) { //Add the new cluster but have it be hidden (so it gets animated, display=none stops transition) - c.setOpacity(0); + + if (c._isSingleParent()) { //If we are the same as our parent, don't do an animation, just immediately appear + c.setOpacity(1); + c._recursivelyRemoveChildrenFromMap(depth); + } else { + c.setOpacity(0); + } c._addToMap(); } }