Well, it turns out that this feature is not available in OpenLayers version 2.11RC1. Therefore, I myself implemented this as a shadow of the Cluster class. The code is also available as a patch in OpenLayers Trac .
You can drop the code at the end of this answer directly into the javascript file and override the existing OpenLayers class OpenLayers.Strategy.Cluster . He adds a recluster method, which when called will force the strategy to recount its clustering. Because we are modifying the base class of Cluster , any derived class must inherit the recluster method recluster .
An example of using this might be:
var clustering=new OpenLayers.Strategy.Cluster() var vectorlayer = new OpenLayers.Layer.Vector('Vectorlayer', { strategies: [clustering] });
Code for replacement class:
OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { distance: 20, threshold: null, features: null, clusters: null, clustering: false, resolution: null, activate: function() { var activated = OpenLayers.Strategy.prototype.activate.call(this); if(activated) { this.layer.events.on({ "beforefeaturesadded": this.cacheFeatures, "moveend": this.cluster, scope: this }); } return activated; }, deactivate: function() { var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); if(deactivated) { this.clearCache(); this.layer.events.un({ "beforefeaturesadded": this.cacheFeatures, "moveend": this.cluster, scope: this }); } return deactivated; }, cacheFeatures: function(event) { var propagate = true; if(!this.clustering) { this.clearCache(); this.features = event.features; this.cluster(); propagate = false; } return propagate; }, clearCache: function() { this.features = null; }, cluster: function(event) { if((!event || event.zoomChanged || (event && event.recluster)) && this.features) { var resolution = this.layer.map.getResolution(); if(resolution != this.resolution || !this.clustersExist() || (event && event.recluster)) { this.resolution = resolution; var clusters = []; var feature, clustered, cluster; for(var i=0; i<this.features.length; ++i) { feature = this.features[i]; if(feature.geometry) { clustered = false; for(var j=clusters.length-1; j>=0; --j) { cluster = clusters[j]; if(this.shouldCluster(cluster, feature)) { this.addToCluster(cluster, feature); clustered = true; break; } } if(!clustered) { clusters.push(this.createCluster(this.features[i])); } } } this.layer.removeAllFeatures(); if(clusters.length > 0) { if(this.threshold > 1) { var clone = clusters.slice(); clusters = []; var candidate; for(var i=0, len=clone.length; i<len; ++i) { candidate = clone[i]; if(candidate.attributes.count < this.threshold) { Array.prototype.push.apply(clusters, candidate.cluster); } else { clusters.push(candidate); } } } this.clustering = true;
source share