From e0d2616925f7fcf66732ada034536d3cff57435b Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 30 Jul 2012 11:59:05 +1200 Subject: [PATCH] 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 60dbe0623..c9776a660 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 9b850d5e9..30886d95d 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) {