diff --git a/lib/OpenLayers/Strategy/Cluster.js b/lib/OpenLayers/Strategy/Cluster.js index 50a14b7859..026a0c63af 100644 --- a/lib/OpenLayers/Strategy/Cluster.js +++ b/lib/OpenLayers/Strategy/Cluster.js @@ -79,6 +79,7 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { if(activated) { this.layer.events.on({ "beforefeaturesadded": this.cacheFeatures, + "featuresremoved": this.clearCache, "moveend": this.cluster, scope: this }); @@ -100,6 +101,7 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { this.clearCache(); this.layer.events.un({ "beforefeaturesadded": this.cacheFeatures, + "featuresremoved": this.clearCache, "moveend": this.cluster, scope: this }); @@ -134,7 +136,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { * Clear out the cached features. */ clearCache: function() { - this.features = null; + if(!this.clustering) { + this.features = null; + } }, /** @@ -169,7 +173,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { } } } + this.clustering = true; this.layer.removeAllFeatures(); + this.clustering = false; if(clusters.length > 0) { if(this.threshold > 1) { var clone = clusters.slice();