[Pkg-javascript-commits] [leaflet-markercluster] 213/479: Get addLayer (after adding to map) working when using animateAddingMarkers:false

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:30 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 3ea3d08aed27cc9f35d141fcfcf35f81f0a3a0e7
Author: danzel <danzel at localhost.geek.nz>
Date:   Tue Sep 11 10:10:46 2012 +1200

    Get addLayer (after adding to map) working when using animateAddingMarkers:false
---
 src/MarkerCluster.js      |  4 ----
 src/MarkerClusterGroup.js | 29 +++++++++++++++++++++--------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index b19a9a7..b3bc491 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -87,10 +87,6 @@ L.MarkerCluster = L.Marker.extend({
 
 		for (i = markers.length - 1; i >= 0; i--) {
 			if (markers[i] === marker) {
-				if (markers[i]._icon) {
-					L.FeatureGroup.prototype.removeLayer.call(group, markers[i]);
-				}
-
 				markers.splice(i, 1);
 				
 				var p = this;
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 56a8e67..cc995f5 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -76,14 +76,23 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			this._unspiderfy();
 		}
 
-		var newCluster = this._addLayer(layer, this._maxZoom);
+		this._addLayer(layer, this._maxZoom);
+
+		//Work out what is visible
+		var visibleLayer = layer,
+			currentZoom = this._map.getZoom();
+		if (layer.__cluster) {
+			while ((visibleLayer.__cluster || visibleLayer._parent)._zoom >= currentZoom) {
+				visibleLayer = (visibleLayer.__cluster || visibleLayer._parent); //TODO Make __cluster the same name as _parent to make this simpler
+			}
+		}
 
 		//TODO: Find the highest visible blah
 
 		if (this.options.animateAddingMarkers) {
-			this._animationAddLayer(layer, newCluster);
+			this._animationAddLayer(layer, visibleLayer);
 		} else {
-			this._animationAddLayerNonAnimated(layer, newCluster);
+			this._animationAddLayerNonAnimated(layer, visibleLayer);
 		}
 		return this;
 	},
@@ -332,7 +341,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			if (closest) {
 				closest._addChild(layer);
 				layer.__cluster = closest;
-				return closest;
+				return;
 			}
 
 			//Try find a marker close by to form a new cluster with
@@ -366,14 +375,14 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 					}
 				}
 
-				return newCluster;
+				return;
 			}
 			
 			//Didn't manage to cluster in at this zoom, record us as a marker here and continue upwards
 			gridUnclustered[zoom].addObject(layer, markerPoint);
 		}
 
-		return layer;
+		return;
 	},
 
 	//Merge and split any existing clusters that are too big or small
@@ -506,12 +515,16 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 	//Shared animation code
 	_animationAddLayerNonAnimated: function (layer, newCluster) {
-		if (newCluster === true) {
+		if (newCluster === layer) {
 			L.FeatureGroup.prototype.addLayer.call(this, layer);
 		} else if (newCluster._childCount === 2) {
 			newCluster._addToMap();
-			newCluster._recursivelyRemoveChildrenFromMap(newCluster._bounds, this._map.getMaxZoom()); //getMaxZoom will always get all children
+
+			var markers = newCluster.getAllChildMarkers();
+			L.FeatureGroup.prototype.removeLayer.call(this, markers[0]);
+			L.FeatureGroup.prototype.removeLayer.call(this, markers[1]);
 		}
+		//TODO else update icon?
 	}
 });
 

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