[Pkg-javascript-commits] [leaflet-markercluster] 133/479: Support being added and removed to the map

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:20 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 e0d2616925f7fcf66732ada034536d3cff57435b
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Jul 30 11:59:05 2012 +1200

    Support being added and removed to the map
---
 src/MarkerCluster.Spiderfier.js |  4 ++++
 src/MarkerClusterGroup.js       | 16 +++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js
index 60dbe06..c9776a6 100644
--- a/src/MarkerCluster.Spiderfier.js
+++ b/src/MarkerCluster.Spiderfier.js
@@ -302,6 +302,10 @@ L.MarkerClusterGroup.include({
 		}
 	},
 
+	_spiderfierOnRemove: function () {
+		this._map.off('click zoomstart', this._unspiderfy, this);
+	},
+
 	_unspiderfy: function () {
 		if (this._spiderfied) {
 			this._spiderfied.unspiderfy();
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 9b850d5..30886d9 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -67,7 +67,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	onAdd: function (map) {
 		L.FeatureGroup.prototype.onAdd.call(this, map);
 
-		this._generateInitialClusters();
+		if (!this._topClusterLevel) {
+			this._generateInitialClusters();
+		}
 		this._map.on('zoomend', this._zoomEnd, this);
 		this._map.on('moveend', this._moveEnd, this);
 
@@ -78,6 +80,18 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		this._bindEvents();
 	},
 
+	//Overrides FeatureGroup.onRemove
+	onRemove: function (map) {
+		this._map.off('zoomend', this._zoomEnd, this);
+		this._map.off('moveend', this._moveEnd, this);
+
+		if (this._spiderfierOnRemove) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely
+			this._spiderfierOnRemove();
+		}
+
+		L.FeatureGroup.prototype.onRemove.call(this, map);
+	},
+
 	//Overrides FeatureGroup._propagateEvent
 	_propagateEvent: function (e) {
 		if (e.target instanceof L.MarkerCluster) {

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