From 9d60d9c6b02c2c1d2e04f3945613d022a13c7b02 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 12 Sep 2017 15:00:32 -0400 Subject: [PATCH] Track inflight jsonp requests and avoid reissuing them --- modules/renderer/background_source.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index cb2f454d0..0451131e4 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -160,6 +160,7 @@ rendererBackgroundSource.Bing = function(data, dispatch) { url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&key=' + key + '&jsonp={callback}', cache = {}, + inflight = {}, providers = []; jsonpRequest(url, function(json) { @@ -199,6 +200,8 @@ rendererBackgroundSource.Bing = function(data, dispatch) { url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial/' + centerPoint + '?zl=' + zoom + '&key=' + key + '&jsonp={callback}'; + if (inflight[tileId]) return; + if (!cache[tileId]) { cache[tileId] = {}; } @@ -206,7 +209,10 @@ rendererBackgroundSource.Bing = function(data, dispatch) { return callback(null, cache[tileId].metadata); } + inflight[tileId] = true; jsonpRequest(url, function(result) { + delete inflight[tileId]; + var err = (!result && 'Unknown Error') || result.errorDetails; if (err) { return callback(err); @@ -242,7 +248,8 @@ rendererBackgroundSource.Esri = function(data) { } var esri = rendererBackgroundSource(data), - cache = {}; + cache = {}, + inflight = {}; esri.getMetadata = function(center, tileCoord, callback) { var tileId = tileCoord.slice(0, 3).join('/'), @@ -252,6 +259,8 @@ rendererBackgroundSource.Esri = function(data) { vintage = {}, metadata = {}; + if (inflight[tileId]) return; + switch (true) { case zoom >= 19: metadataLayer = 3; @@ -294,7 +303,10 @@ rendererBackgroundSource.Esri = function(data) { callback(null, metadata); } else { + inflight[tileId] = true; jsonpRequest(url, function(result) { + delete inflight[tileId]; + var err; if (!result) { err = 'Unknown Error';