[Pkg-javascript-commits] [leaflet-markercluster] 29/479: Don't fade between 2 clusters when zooming if they are the same

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet-markercluster.

commit 71662891aa0559cfc82a35e63d005e61fcff88e8
Author: danzel <danzel at localhost.geek.nz>
Date:   Tue Jul 17 16:52:59 2012 +1200

    Don't fade between 2 clusters when zooming if they are the same
---
 src/MarkerCluster.js      |  6 ++++++
 src/MarkerClusterGroup.js | 19 +++++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index c41c5af..a477496 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 4b18466..98041da 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();
 			}
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git



More information about the Pkg-javascript-commits mailing list