Track inflight jsonp requests and avoid reissuing them

This commit is contained in:
Bryan Housel
2017-09-12 15:00:32 -04:00
parent 6addbba340
commit 9d60d9c6b0
+13 -1
View File
@@ -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';