[Pkg-javascript-commits] [leaflet-markercluster] 109/479: Fix addLayer (was broken since making everything in to a tree)

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:16 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 43a1742b89afbfece07f78aec5c9d3120a30b569
Author: danzel <danzel at localhost.geek.nz>
Date:   Wed Jul 25 16:32:23 2012 +1200

    Fix addLayer (was broken since making everything in to a tree)
---
 src/MarkerCluster.js      | 34 +++++++++++++++++++++++++++++-----
 src/MarkerClusterGroup.js | 10 ++++++----
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index e510902..37012ec 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -81,9 +81,9 @@ L.MarkerCluster = L.Marker.extend({
 
 	//layer: The layer to try add
 	//returns:
-	//  true: was able to put this marker in, but don't know its current visible parents position
+	//  true: was able to put this marker in, but don't know its current visible parents position (If returned externally, add this marker at its position)
 	//  false: wasn't able to put this marker in
-	//  a Marker/MarkerCluster: the visible parent of the marker (or the marker itself if it should be visible)
+	//  a MarkerCluster: the visible parent of the marker
 	_recursivelyAddLayer: function (layer, zoom) {
 		var result = false;
 
@@ -103,11 +103,37 @@ L.MarkerCluster = L.Marker.extend({
 		if (!result && (this._canAcceptPosition(layer.getLatLng(), zoom) || this._zoom)) {
 
 			//Add to ourself instead
-			result = this._group._clusterOne(this._markers, layer, zoom);
+			result = this._group._clusterOne(this._markers, layer, zoom + 1);
 
 			if (result) {
 				result._baseInit();
+				this._childCount--;
 				this._addChild(result);
+
+				//We may be above the zoom that these 2 markers would initially cluster at
+				// so push the new cluster as deep as it can go
+				var wantedZoom = this._group._map.getZoom() - 1,
+					maxZoom = this._group._map.getMaxZoom(),
+					newResult,
+					finalResult = (zoom === wantedZoom) ? result : true;
+				while (zoom < maxZoom) {
+					zoom++;
+					newResult = this._group._clusterOne([result._markers[0]], layer, zoom + 1);
+
+					if (newResult == null) {
+						break;
+					}
+					newResult._baseInit();
+					result._markers = [];
+					result._childClusters.push(newResult);
+					result = newResult;
+
+					if (zoom == wantedZoom) {
+						finalResult = result;
+					}
+				}
+				result = finalResult;
+
 			} else {
 				this._addChild(layer);
 				result = true;
@@ -123,8 +149,6 @@ L.MarkerCluster = L.Marker.extend({
 		if (result === true) {
 			if (this._icon) {
 				result = this;
-			} else if ((this._markers.length > 0 && this._markers[0]._icon) || (this._childClusters.length > 1 && this._childClusters[0]._icon)) {
-				result = layer;
 			}
 		}
 
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 6f57ab0..0577f09 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -257,9 +257,11 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
 		this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel - this._topClusterLevel._zoom + 1, this._getExpandedVisibleBounds());
 	},
 	_animationAddLayer: function (layer, newCluster) {
-		L.FeatureGroup.prototype.addLayer.call(this, layer);
-		if (newCluster !== true && newCluster._childCount === 2) {
-			newCluster._recursivelyRemoveChildrenFromMap(newCluster._bounds, 1);
+		if (newCluster === true) {
+			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
 		}
 	}
 } : {
@@ -398,7 +400,7 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
 				this._forceLayout();
 
 				me._animationStart();
-				me._animationZoomOutSingle(newCluster, 0, 1);
+				me._animationZoomOutSingle(newCluster, 0, this._map.getMaxZoom());
 			}
 		}
 	},

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