Clear the cache on Strategy.Cluster when features are removed.

This prevents reappearing the removed features after zooming.
This commit is contained in:
Xavier Mamano
2012-10-16 18:43:53 +02:00
parent 0b46f19ba6
commit 3c416a4d60
+7 -1
View File
@@ -79,6 +79,7 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
if(activated) { if(activated) {
this.layer.events.on({ this.layer.events.on({
"beforefeaturesadded": this.cacheFeatures, "beforefeaturesadded": this.cacheFeatures,
"featuresremoved": this.clearCache,
"moveend": this.cluster, "moveend": this.cluster,
scope: this scope: this
}); });
@@ -100,6 +101,7 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
this.clearCache(); this.clearCache();
this.layer.events.un({ this.layer.events.un({
"beforefeaturesadded": this.cacheFeatures, "beforefeaturesadded": this.cacheFeatures,
"featuresremoved": this.clearCache,
"moveend": this.cluster, "moveend": this.cluster,
scope: this scope: this
}); });
@@ -134,7 +136,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
* Clear out the cached features. * Clear out the cached features.
*/ */
clearCache: function() { 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.layer.removeAllFeatures();
this.clustering = false;
if(clusters.length > 0) { if(clusters.length > 0) {
if(this.threshold > 1) { if(this.threshold > 1) {
var clone = clusters.slice(); var clone = clusters.slice();