[Pkg-javascript-commits] [leaflet-markercluster] 290/479: Fix up some bugs that happen when removing and adding a MarkerClusterGroup from the map.

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:40 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 f875421fc43e50aff7d13aca348e4008a93a2727
Author: danzel <danzel at localhost.geek.nz>
Date:   Thu Nov 22 17:05:44 2012 +1300

    Fix up some bugs that happen when removing and adding a MarkerClusterGroup from the map.
    
    Was leaving layers in _layers which meant they'd get added again when we were re-added. Wasn't unbinding our events from almost anything.
    Fixes #94
---
 src/MarkerClusterGroup.js | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index b631968..7e24d8b 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -321,6 +321,8 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		this._map.off('zoomend', this._zoomEnd, this);
 		this._map.off('moveend', this._moveEnd, this);
 
+		this._unbindEvents();
+
 		//In case we are in a cluster animation
 		this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', '');
 
@@ -329,6 +331,13 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		}
 
 		L.FeatureGroup.prototype.onRemove.call(this, map);
+
+		//Clean up all the layers we added to the map
+		for (var i in this._layers) {
+			if (this._layers.hasOwnProperty(i)) {
+				L.FeatureGroup.prototype.removeLayer.call(this, this._layers[i]);
+			}
+		}
 	},
 
 
@@ -485,6 +494,23 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		}
 	},
 
+	_unbindEvents: function () {
+		var spiderfyOnMaxZoom = this.options.spiderfyOnMaxZoom,
+			showCoverageOnHover = this.options.showCoverageOnHover,
+			zoomToBoundsOnClick = this.options.zoomToBoundsOnClick,
+			map = this._map;
+
+		if (spiderfyOnMaxZoom || zoomToBoundsOnClick) {
+			this.off('clusterclick', null, this);
+		}
+		if (showCoverageOnHover) {
+			this.off('clustermouseover', null, this);
+			this.off('clustermouseout', null, this);
+			map.off('zoomend', null, this);
+			map.off('layerremove', null, this);
+		}
+	},
+
 	_zoomEnd: function () {
 		if (!this._map) { //May have been removed from the map by a zoomEnd handler
 			return;

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