If we are added to the map, then removed, then a marker is removed from us. Previously that marker wouldn't be removed, now it is when we get re-added to the map.
This commit is contained in:
danzel
2013-04-26 09:58:40 +12:00
parent fc3edf2958
commit e7e1d5391f
+27 -10
View File
@@ -41,6 +41,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._inZoomAnimation = 0;
this._needsClustering = [];
this._needsRemoving = []; //Markers removed while we aren't on the map need to be kept track of
//The bounds of the currently shown area (from _getExpandedVisibleBounds) Updated on zoom/move
this._currentShownBounds = null;
},
@@ -94,7 +95,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
removeLayer: function (layer) {
if (!this._map) {
this._arraySplice(this._needsClustering, layer);
if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) {
this._needsRemoving.push(layer);
}
return this;
}
@@ -262,12 +265,18 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
return false;
}
if (this._needsClustering.length > 0) {
var anArray = this._needsClustering;
for (var i = anArray.length - 1; i >= 0; i--) {
if (anArray[i] === layer) {
return true;
}
var i, anArray = this._needsClustering;
for (i = anArray.length - 1; i >= 0; i--) {
if (anArray[i] === layer) {
return true;
}
}
anArray = this._needsRemoving;
for (i = anArray.length - 1; i >= 0; i--) {
if (anArray[i] === layer) {
return false;
}
}
@@ -315,13 +324,20 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Overrides FeatureGroup.onAdd
onAdd: function (map) {
this._map = map;
var i, l, layer;
if (!this._gridClusters) {
this._generateInitialClusters();
}
for (var i = 0, l = this._needsClustering.length; i < l; i++) {
var layer = this._needsClustering[i];
for (i = 0, l = this._needsRemoving.length; i < l; i++) {
layer = this._needsRemoving[i];
this._removeLayer(layer);
}
this._needsRemoving = [];
for (i = 0, l = this._needsClustering.length; i < l; i++) {
layer = this._needsClustering[i];
if (layer.__parent) {
continue;
}
@@ -329,6 +345,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
this._needsClustering = [];
this._map.on('zoomend', this._zoomEnd, this);
this._map.on('moveend', this._moveEnd, this);
@@ -377,7 +394,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
for (var i = anArray.length - 1; i >= 0; i--) {
if (anArray[i] === obj) {
anArray.splice(i, 1);
return;
return true;
}
}
},