Cluster strategy should register for moveend on the layer instead of zoomend on the map. p=elemoine,me r=me (closes #1834)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8460 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-12-06 20:54:51 +00:00
parent f9c814a34a
commit 304b2cf3ea
2 changed files with 9 additions and 5 deletions
+8 -4
View File
@@ -70,9 +70,9 @@ 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,
"moveend": this.cluster,
scope: this scope: this
}); });
this.layer.map.events.on({"zoomend": this.cluster, scope: this});
} }
return activated; return activated;
}, },
@@ -91,9 +91,9 @@ 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,
"moveend": this.cluster,
scope: this scope: this
}); });
this.layer.map.events.un({"zoomend": this.cluster, scope: this});
} }
return deactivated; return deactivated;
}, },
@@ -137,9 +137,13 @@ OpenLayers.Strategy.Cluster = OpenLayers.Class(OpenLayers.Strategy, {
/** /**
* Method: cluster * Method: cluster
* Cluster features based on some threshold distance. * 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() { cluster: function(event) {
if(this.features) { if((!event || event.zoomChanged) && this.features) {
var resolution = this.layer.map.getResolution(); var resolution = this.layer.map.getResolution();
if(resolution != this.resolution || !this.clustersExist()) { if(resolution != this.resolution || !this.clustersExist()) {
this.resolution = resolution; this.resolution = resolution;
+1 -1
View File
@@ -59,8 +59,8 @@
// add one additional feature, with no geometry - just to confirm it doesn't break things // add one additional feature, with no geometry - just to confirm it doesn't break things
features.push(new OpenLayers.Feature.Vector()); features.push(new OpenLayers.Feature.Vector());
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
layer.addFeatures(features); layer.addFeatures(features);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
// resolution 4 // resolution 4
// threshold: 4 * 20 = 80 units // threshold: 4 * 20 = 80 units