[Pkg-javascript-commits] [leaflet-markercluster] 52/479: Working on animated zoom in. mostly works

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:08 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 ca214556d6e35714648bdfe28155d40c61694972
Author: danzel <danzel at localhost.geek.nz>
Date:   Thu Jul 19 15:32:50 2012 +1200

    Working on animated zoom in. mostly works
---
 src/MarkerClusterGroup.js | 70 ++++++++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 7b4f8d8..49ab22d 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -361,33 +361,40 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
 		var me = this,
 		    map = this._map,
 		    bounds = this._getExpandedVisibleBounds(),
-		    i, c, startPos;
+		    i, 
+		    depthToStartAt = 1 + previousZoomLevel - this._topClusterLevel._zoom,
+		    depthToDescend = newZoomLevel - previousZoomLevel;
+		console.log('animationZoomIn ' + depthToStartAt + ' ' + depthToDescend);
 
 		//Add all children of current clusters to map and remove those clusters from map
-		for (i = 0; i < startingClusters.length; i++) {
-			c = startingClusters[i];
-			startPos = c.getLatLng();
-
-			if (c._isSingleParent()) {
-				L.FeatureGroup.prototype.removeLayer.call(this, c);
-				c._recursivelyAddChildrenToMap(null, depth, bounds);
+		this._topClusterLevel._recursively(bounds, depthToStartAt, 0, function (c) {
+			var startPos = c._latlng,
+				markers = c._markers,
+				m;
+
+			if (c._isSingleParent()) { //Immediately add the new child and remove us
+				L.FeatureGroup.prototype.removeLayer.call(me, c);
+				c._recursivelyAddChildrenToMap(null, depthToDescend, bounds);
 			} else {
 				//Fade out old cluster
 				c.setOpacity(0);
-				c._recursivelyAddChildrenToMap(startPos, depth, bounds);
+				c._recursivelyAddChildrenToMap(startPos, depthToDescend, bounds);
 			}
-		}
 
-		//Remove all markers that aren't visible any more
-		for (i = startingUnclustered.length - 1; i >= 0; i--) {
-			c = startingUnclustered[i];
-			if (!bounds.contains(c._latlng)) {
-				L.FeatureGroup.prototype.removeLayer.call(this, c);
+			//Remove all markers that aren't visible any more
+			//TODO: Do we actually need to do this on the higher levels too?
+			for (i = markers.length - 1; i >= 0; i--) {
+				m = markers[i];
+				if (!bounds.contains(m._latlng)) {
+					L.FeatureGroup.prototype.removeLayer.call(this, m);
+				}
 			}
-		}
 
-		//Immediately fire an event to update the opacity (If we immediately set it they won't animate)
+		});
+
+		//Immediately fire an event to update the opacity and locations (If we immediately set it they won't animate)
 		setTimeout(function () {
+			//Update opacities
 			for (i in me._layers) {
 				var n = me._layers[i];
 
@@ -395,25 +402,26 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
 					n.setOpacity(1);
 				}
 			}
+
+			//update the positions of the just added clusters/markers
+			me._topClusterLevel._recursively(bounds, depthToStartAt, 0, function (c) {
+				c._recursivelyRestoreChildPositions(depthToDescend);
+			});
 		}, 0);
 
 		this._inZoomAnimation++;
-		//Start up a function to update the positions of the just added clusters/markers
-		//This must happen after otherwise they don't get animated
-		setTimeout(function () {
 
-			for (var j = 0; j < startingClusters.length; j++) {
-				startingClusters[j]._recursivelyRestoreChildPositions(depth);
-			}
+		//Remove the old clusters and close the zoom animation
+		
+		setTimeout(function () {
+			//update the positions of the just added clusters/markers
+			me._topClusterLevel._recursively(bounds, depthToStartAt, 0, function (c) {
+				L.FeatureGroup.prototype.removeLayer.call(me, c);
+			});
 
-			setTimeout(function () {
-				for (i = 0; i < startingClusters.length; i++) {
-					L.FeatureGroup.prototype.removeLayer.call(me, startingClusters[i]);
-				}
-				map._mapPane.className = map._mapPane.className.replace(' leaflet-cluster-anim', '');
-				me._inZoomAnimation--;
-			}, 250);
-		}, 0);
+			map._mapPane.className = map._mapPane.className.replace(' leaflet-cluster-anim', '');
+			me._inZoomAnimation--;
+		}, 250);
 	},
 	_animationZoomOut: function (previousZoomLevel, newZoomLevel) {
 		var map = this._map,

-- 
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