[Pkg-javascript-commits] [leaflet-markercluster] 78/479: Spiderfier basically done. Need to add a non animated version for suckers

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:12 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 eebf8e9e814cfbc3644c47b101dfabbb8398c4cb
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Jul 23 16:08:44 2012 +1200

    Spiderfier basically done. Need to add a non animated version for suckers
---
 src/MarkerCluster.Spiderfier.js | 55 ++++++++++++++++++++++++++++++++++++-----
 src/MarkerClusterGroup.js       |  4 +++
 2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js
index 0d67acc..7814a20 100644
--- a/src/MarkerCluster.Spiderfier.js
+++ b/src/MarkerCluster.Spiderfier.js
@@ -22,6 +22,10 @@ L.MarkerCluster.include({
 			center = map.latLngToLayerPoint(this._latlng),
 			markerOffsets,
 			i, m;
+
+		this._group._unspiderfy();
+		this._group._spiderfied = this;
+
 		//TODO Maybe: childMarkers order by distance to center
 
 		if (childMarkers.length >= this._circleSpiralSwitchover) {
@@ -49,23 +53,45 @@ L.MarkerCluster.include({
 
 				m.setLatLng(map.layerPointToLatLng(markerOffsets[i]));
 				m.setOpacity(1);
-
-				var leg = new L.Polyline([me._latlng, m._latlng], { weight: 1.5, color: '#222' });
-				map.addLayer(leg);
 			}
 			me.setOpacity(0.3);
 
 			setTimeout(function () {
+				//Add Legs. TODO: Fade this in!
+				for (i = childMarkers.length - 1; i >= 0; i--) {
+					m = childMarkers[i];
+					var leg = new L.Polyline([me._latlng, m._latlng], { weight: 1.5, color: '#222' });
+					map.addLayer(leg);
+					m._spiderLeg = leg;
+				}
+
+
 				group._animationEnd();
 			}, 250);
 		}, 0);
 	},
 
 	unspiderfy: function () {
-		if (false) {
-			return;
+		var group = this._group,
+			map = group._map,
+			childMarkers = this.getAllChildMarkers(),
+			m, i;
+
+		this.setOpacity(1);
+		for (i = childMarkers.length - 1; i >= 0; i--) {
+			m = childMarkers[i];
+
+			m.setLatLng(m._backupPosSpider);
+			delete m._backupPosSpider;
+			m.setZIndexOffset(0);
+
+			L.FeatureGroup.prototype.removeLayer.call(group, m);
+
+			map.removeLayer(m._spiderLeg);
+			delete m._spiderLeg;
 		}
-		//TODO
+
+		this._group._spiderfied = null;
 	},
 
 	_generatePointsCircle: function (count, centerPt) {
@@ -100,4 +126,21 @@ L.MarkerCluster.include({
 		}
 		return res;
 	}
+});
+
+L.MarkerClusterGroup.include({
+	//The MarkerCluster currently spiderfied (if any)
+	_spiderfied: null,
+
+	_spiderfierOnAdd: function () {
+		console.log('asdasd');
+		this._map.on('click zoomstart', this._unspiderfy, this);
+	},
+
+	_unspiderfy: function () {
+		console.log('in _unspiderfy');
+		if (this._spiderfied) {
+			this._spiderfied.unspiderfy();
+		}
+	},
 });
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 3390b8d..21cae41 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -133,6 +133,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		this._generateInitialClusters();
 		this._map.on('zoomend', this._zoomEnd, this);
 		this._map.on('moveend', this._moveEnd, this);
+
+		if (this._spiderfierOnAdd) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely
+			this._spiderfierOnAdd();
+		}
 	},
 
 	//Takes a list of markers and clusters the new marker in to them

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