From 815cafd9008f5f7d0a26ac59562b9b67fa70f3d8 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 21 Feb 2012 07:53:43 +0100 Subject: [PATCH 1/2] add an option to OpenLayers.Strategy.BBOX to allow not aborting previous requests --- lib/OpenLayers/Strategy/BBOX.js | 11 +++++++---- tests/Strategy/BBOX.html | 14 +++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index b6307876fb..2f7ff50631 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -124,9 +124,12 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { * Callback function called on "moveend" or "refresh" layer events. * * Parameters: - * options - {Object} An object with a property named "force", this - * property references a boolean value indicating if new data - * must be incondtionally read. + * options - {Object} Optional object whose properties will determine + * the behaviour of this Strategy + * + * Valid options include: + * force - {Boolean} if true, new data must be unconditionally read. + * noAbort - {Boolean} if true, do not abort previous requests. */ update: function(options) { var mapBounds = this.getMapBounds(); @@ -218,7 +221,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { * returned by the layer protocol. */ triggerRead: function(options) { - if (this.response) { + if (this.response && options.noAbort !== true) { this.layer.protocol.abort(this.response); this.layer.events.triggerEvent("loadend"); } diff --git a/tests/Strategy/BBOX.html b/tests/Strategy/BBOX.html index c0ff4ff401..aa66c65321 100644 --- a/tests/Strategy/BBOX.html +++ b/tests/Strategy/BBOX.html @@ -33,7 +33,7 @@ } function test_update(t) { - t.plan(5); + t.plan(7); // Create a dummy layer that can act as the map base layer. // This will be unnecessary if #1921 is addressed (allowing @@ -43,9 +43,10 @@ var strategy = new OpenLayers.Strategy.BBOX({ ratio: 1 // makes for easier comparison to map bounds }); + var log = []; var layer = new OpenLayers.Layer.Vector(null, { isBaseLayer: true, - protocol: new OpenLayers.Protocol(), + protocol: new OpenLayers.Protocol({abort: function(response) { log.push(response); }}), strategies: [strategy] }); @@ -61,7 +62,14 @@ * should be removed when the issue(s) described in #1835 are addressed. */ strategy.update({force: true}); - + strategy.response = {}; + strategy.update({force: true}); + t.eq(log.length, 1, "Response aborted"); + log = []; + strategy.update({force: true}); + strategy.update({force: true, noAbort: true}); + t.eq(log.length, 0, "Response not aborted when noAbort is true"); + // test that the strategy bounds were set t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent"); From 990a33662eeeedb9b98c83e2ac55e7c6a604fa3f Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 21 Feb 2012 12:09:19 +0100 Subject: [PATCH 2/2] incorporate @ahocevar's review --- lib/OpenLayers/Strategy/BBOX.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index 2f7ff50631..6d59e4c2ab 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -221,7 +221,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { * returned by the layer protocol. */ triggerRead: function(options) { - if (this.response && options.noAbort !== true) { + if (this.response && !(options && options.noAbort === true)) { this.layer.protocol.abort(this.response); this.layer.events.triggerEvent("loadend"); }