Don't fade between 2 clusters when zooming if they are the same

This commit is contained in:
danzel
2012-07-17 16:52:59 +12:00
parent 808b58738f
commit 71662891aa
2 changed files with 21 additions and 4 deletions
+6
View File
@@ -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;
}
});
+15 -4
View File
@@ -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();
}
}