+ Demonstrates the use of the cluster strategy threshold property.
+
+
+
+
The Cluster strategy lets you display points representing clusters
+ of features within some pixel distance. You can control the behavior
+ of the cluster strategy by setting its distance and threshold properties.
+ The distance determines the search radius (in pixels) for features to
+ cluster. The threshold determines the minimum number of features to
+ be considered a cluster.
+
+
+
Cluster details: hover over a feature to see details.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/OpenLayers/Strategy/Cluster.js b/lib/OpenLayers/Strategy/Cluster.js
index 7eae765860..d4d5000f43 100644
--- a/lib/OpenLayers/Strategy/Cluster.js
+++ b/lib/OpenLayers/Strategy/Cluster.js
@@ -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()} 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 0) {
+ if(this.threshold > 1) {
+ var clone = clusters.slice();
+ clusters = [];
+ var candidate;
+ for(var i=0, len=clone.length; i