diff --git a/lib/OpenLayers/Strategy/Cluster.js b/lib/OpenLayers/Strategy/Cluster.js index 9fac5c698f..7eae765860 100644 --- a/lib/OpenLayers/Strategy/Cluster.js +++ b/lib/OpenLayers/Strategy/Cluster.js @@ -70,9 +70,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { if(activated) { this.layer.events.on({ "beforefeaturesadded": this.cacheFeatures, + "moveend": this.cluster, scope: this }); - this.layer.map.events.on({"zoomend": this.cluster, scope: this}); } return activated; }, @@ -91,9 +91,9 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { this.clearCache(); this.layer.events.un({ "beforefeaturesadded": this.cacheFeatures, + "moveend": this.cluster, scope: this }); - this.layer.map.events.un({"zoomend": this.cluster, scope: this}); } return deactivated; }, @@ -137,9 +137,13 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, { /** * Method: cluster * Cluster features based on some threshold distance. + * + * Parameters: + * event - {Object} The event received when cluster is called as a + * result of a moveend event. */ - cluster: function() { - if(this.features) { + cluster: function(event) { + if((!event || event.zoomChanged) && this.features) { var resolution = this.layer.map.getResolution(); if(resolution != this.resolution || !this.clustersExist()) { this.resolution = resolution; diff --git a/tests/Strategy/Cluster.html b/tests/Strategy/Cluster.html index aee66ee8e9..e7d4d901b5 100644 --- a/tests/Strategy/Cluster.html +++ b/tests/Strategy/Cluster.html @@ -59,8 +59,8 @@ // add one additional feature, with no geometry - just to confirm it doesn't break things features.push(new OpenLayers.Feature.Vector()); - map.setCenter(new OpenLayers.LonLat(0, 0), 0); layer.addFeatures(features); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); // resolution 4 // threshold: 4 * 20 = 80 units