aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2019-04-02 16:11:04 +0100
committerStruan Donald <struan@exo.org.uk>2019-05-28 11:34:19 +0100
commit1d236f3fd5496355ce61adb68e0bf0efdd0ff366 (patch)
tree0357e8e2fcb77c1eaa0b33d3b5e65133148365e8
parentc525f570acef784e09824d1444feffd7949b9ace (diff)
[Alloy] abort existing tile fetches on new request
Rather than trying to work out if the response is part of the current set, track existing responses and abort them if a new request is started.
-rw-r--r--web/cobrands/fixmystreet-uk-councils/alloy.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/web/cobrands/fixmystreet-uk-councils/alloy.js b/web/cobrands/fixmystreet-uk-councils/alloy.js
index 1ade3a1fa..c9fb11ab0 100644
--- a/web/cobrands/fixmystreet-uk-councils/alloy.js
+++ b/web/cobrands/fixmystreet-uk-councils/alloy.js
@@ -1,6 +1,17 @@
(function(){
OpenLayers.Protocol.Alloy = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
+ currentRequests: [],
+
+ abort: function() {
+ if (this.currentRequests.length) {
+ for (var j = 0; j < this.currentRequests.length; j++) {
+ this.currentRequests[j].priv.abort();
+ }
+ this.currentRequests = [];
+ }
+ },
+
read: function(options) {
OpenLayers.Protocol.prototype.read.apply(this, arguments);
options = options || {};
@@ -9,12 +20,10 @@ OpenLayers.Protocol.Alloy = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
options = OpenLayers.Util.applyDefaults(options, this.options);
var all_tiles = this.getTileRange_(options.scope.bounds, options.scope.layer.maxExtent, options.scope.layer.map);
var rresp;
- var start = new Date();
var max = all_tiles.length;
- options.scope.newRequest(start, max);
+ options.scope.newRequest(max);
for (var i = 0; i < max; i++) {
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
- resp.start = start;
var url = this.getURL(all_tiles[i], options);
resp.priv = OpenLayers.Request.GET({
url: url, //options.url,
@@ -22,6 +31,7 @@ OpenLayers.Protocol.Alloy = OpenLayers.Class(OpenLayers.Protocol.HTTP, {
params: options.params,
headers: options.headers
});
+ this.currentRequests.push(resp);
rresp = resp;
}
return rresp;
@@ -70,18 +80,12 @@ OpenLayers.Strategy.Alloy = OpenLayers.Class(OpenLayers.Strategy.FixMyStreet, {
initialize: function(name, options) {
OpenLayers.Strategy.FixMyStreet.prototype.initialize.apply(this, arguments);
},
- newRequest: function(start, max) {
+ newRequest: function(max) {
this.max = max;
- this.requestStart = start;
this.count = 0;
this.layer.destroyFeatures();
},
merge: function(resp) {
- // because we are issuing async requests it's possible that if someone moves the
- // map we've triggered a new set of requests, in which case ignore the old ones.
- if (resp.start < this.requestStart) {
- return;
- }
this.count++;
// This if/else clause lifted from OpenLayers.Strategy.BBOX
if (resp.success()) {