Adding a threshold property to the cluster strategy. If a threshold set, clusters will only be created if the number of features in a group meets or exceeds the threshold number. r=elemoine,crschmidt (closes #1815)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9119 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -22,6 +22,17 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
distance: 20,
|
||||
|
||||
/**
|
||||
* APIProperty: threshold
|
||||
* {Integer} Optional threshold below which original features will be
|
||||
* added to the layer instead of clusters. For example, a threshold
|
||||
* of 3 would mean that any time there are 2 or fewer features in
|
||||
* a cluster, those features will be added directly to the layer instead
|
||||
* of a cluster representing those features. Default is null (which is
|
||||
* equivalent to 1 - meaning that clusters may contain just one feature).
|
||||
*/
|
||||
threshold: null,
|
||||
|
||||
/**
|
||||
* Property: features
|
||||
* {Array(<OpenLayers.Feature.Vector>)} Cached features.
|
||||
@@ -122,15 +133,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
|
||||
/**
|
||||
* Method: clearCache
|
||||
* Clear out the cached features. This destroys features, assuming
|
||||
* nothing else has a reference.
|
||||
* Clear out the cached features.
|
||||
*/
|
||||
clearCache: function() {
|
||||
if(this.features) {
|
||||
for(var i=0; i<this.features.length; ++i) {
|
||||
this.features[i].destroy();
|
||||
}
|
||||
}
|
||||
this.features = null;
|
||||
},
|
||||
|
||||
@@ -168,6 +173,19 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
}
|
||||
this.layer.destroyFeatures();
|
||||
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;
|
||||
// A legitimate feature addition could occur during this
|
||||
// addFeatures call. For clustering to behave well, features
|
||||
|
||||
Reference in New Issue
Block a user