diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index bc13c15649..1aae581187 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -299,7 +299,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { * the refresh event. */ refresh: function(obj) { - if(this.inRange && this.visibility) { + if(this.calculateInRange() && this.visibility) { this.events.triggerEvent("refresh", obj); } }, diff --git a/lib/OpenLayers/Strategy/Fixed.js b/lib/OpenLayers/Strategy/Fixed.js index 3885d4bf69..b3553a64fd 100644 --- a/lib/OpenLayers/Strategy/Fixed.js +++ b/lib/OpenLayers/Strategy/Fixed.js @@ -53,6 +53,10 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, { */ activate: function() { if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) { + this.layer.events.on({ + "refresh": this.load, + scope: this + }); if(this.layer.visibility == true || this.preload) { this.load(); } else { @@ -66,16 +70,38 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, { return false; }, + /** + * Method: deactivate + * Deactivate the strategy. Undo what is done in . + * + * Returns: + * {Boolean} The strategy was successfully deactivated. + */ + deactivate: function() { + var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this); + if(deactivated) { + this.layer.events.un({ + "refresh": this.load, + "visibilitychanged": this.load, + scope: this + }); + } + return deactivated; + }, + /** * Method: load * Tells protocol to load data and unhooks the visibilitychanged event + * + * Parameters: + * options - {Object} options to pass to protocol read. */ - load: function() { + load: function(options) { this.layer.events.triggerEvent("loadstart"); - this.layer.protocol.read({ + this.layer.protocol.read(OpenLayers.Util.applyDefaults({ callback: this.merge, scope: this - }); + }, options)); this.layer.events.un({ "visibilitychanged": this.load, scope: this @@ -87,6 +113,7 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, { * Add all features to the layer. */ merge: function(resp) { + this.layer.destroyFeatures(); var features = resp.features; if (features && features.length > 0) { var remote = this.layer.projection; diff --git a/tests/Strategy/Fixed.html b/tests/Strategy/Fixed.html index bf03d9e336..120786f640 100644 --- a/tests/Strategy/Fixed.html +++ b/tests/Strategy/Fixed.html @@ -62,7 +62,7 @@ function test_events(t) { - t.plan(2); + t.plan(3); var log = { loadstart: 0, @@ -93,6 +93,13 @@ t.eq(log.loadstart, 1, "loadstart triggered"); t.eq(log.loadend, 1, "loadend triggered"); + var log = {}; + layer.protocol.read = function(obj) { + log.obj = obj; + } + layer.refresh({whee: 'chicken'}); + + t.eq(log.obj && log.obj.whee, "chicken", "properties passed to read on refresh correctly."); map.destroy(); @@ -101,7 +108,7 @@ function test_merge(t) { - t.plan(5); + t.plan(6); var strategy = new OpenLayers.Strategy.Fixed(); @@ -124,6 +131,14 @@ } } }); + + // give the layer some existing features (one) + layer.addFeatures([ + new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(0, 0) + ) + ]); + map.addLayer(layer); map.zoomToMaxExtent(); @@ -140,6 +155,9 @@ // call merge with a mocked up response strategy.merge({features: features}); + // confirm that the original features were destroyed + t.eq(layer.features.length, 2, "old features destroyed"); + // confirm that loadend was called t.eq(log.loadend, 1, "merge triggers loadend");