add an option to OpenLayers.Strategy.BBOX to allow not aborting previous requests

This commit is contained in:
Bart van den Eijnden
2012-02-21 07:53:43 +01:00
parent 79b539c1f9
commit 815cafd900
2 changed files with 18 additions and 7 deletions
+7 -4
View File
@@ -124,9 +124,12 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
* Callback function called on "moveend" or "refresh" layer events. * Callback function called on "moveend" or "refresh" layer events.
* *
* Parameters: * Parameters:
* options - {Object} An object with a property named "force", this * options - {Object} Optional object whose properties will determine
* property references a boolean value indicating if new data * the behaviour of this Strategy
* must be incondtionally read. *
* 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) { update: function(options) {
var mapBounds = this.getMapBounds(); var mapBounds = this.getMapBounds();
@@ -218,7 +221,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
* returned by the layer protocol. * returned by the layer protocol.
*/ */
triggerRead: function(options) { triggerRead: function(options) {
if (this.response) { if (this.response && options.noAbort !== true) {
this.layer.protocol.abort(this.response); this.layer.protocol.abort(this.response);
this.layer.events.triggerEvent("loadend"); this.layer.events.triggerEvent("loadend");
} }
+10 -2
View File
@@ -33,7 +33,7 @@
} }
function test_update(t) { function test_update(t) {
t.plan(5); t.plan(7);
// Create a dummy layer that can act as the map base layer. // Create a dummy layer that can act as the map base layer.
// This will be unnecessary if #1921 is addressed (allowing // This will be unnecessary if #1921 is addressed (allowing
@@ -43,9 +43,10 @@
var strategy = new OpenLayers.Strategy.BBOX({ var strategy = new OpenLayers.Strategy.BBOX({
ratio: 1 // makes for easier comparison to map bounds ratio: 1 // makes for easier comparison to map bounds
}); });
var log = [];
var layer = new OpenLayers.Layer.Vector(null, { var layer = new OpenLayers.Layer.Vector(null, {
isBaseLayer: true, isBaseLayer: true,
protocol: new OpenLayers.Protocol(), protocol: new OpenLayers.Protocol({abort: function(response) { log.push(response); }}),
strategies: [strategy] strategies: [strategy]
}); });
@@ -61,6 +62,13 @@
* should be removed when the issue(s) described in #1835 are addressed. * should be removed when the issue(s) described in #1835 are addressed.
*/ */
strategy.update({force: true}); 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 // test that the strategy bounds were set
t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent"); t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent");