fix: fall back to direct tile URLs on proxy errors
This commit is contained in:
1 parent
5ce027fd5d
commit
c02a198f3f
1 file changed
+19
-9
Vendored
+19
-9
@@ -1834,13 +1834,24 @@ function tileProbeProxy() {
|
||||
probe(GROUND_TILE_PROXY + GROUND_TILE_Z + '/0/0.jpg',
|
||||
function () { GROUND_TILE_URL = GROUND_TILE_PROXY; });
|
||||
}
|
||||
function fetchTileBlob(tileX, tileY) {
|
||||
// ESRI World_Street_Map format: {z}/{y}/{x}.jpg (y before x, jpg not png)
|
||||
return fetch(GROUND_TILE_URL + GROUND_TILE_Z + '/' + tileY + '/' + tileX + '.jpg')
|
||||
.then(function (r) {
|
||||
function fetchBlobWithFallback(primaryUrl, fallbackUrl) {
|
||||
function get(url) {
|
||||
return fetch(url).then(function (r) {
|
||||
if (!r.ok) throw new Error('tile http ' + r.status);
|
||||
return r.blob();
|
||||
});
|
||||
}
|
||||
return get(primaryUrl).catch(function (e) {
|
||||
if (fallbackUrl && primaryUrl !== fallbackUrl) return get(fallbackUrl);
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
function fetchTileBlob(tileX, tileY) {
|
||||
// ESRI World_Street_Map format: {z}/{y}/{x}.jpg (y before x, jpg not png)
|
||||
return fetchBlobWithFallback(
|
||||
GROUND_TILE_URL + GROUND_TILE_Z + '/' + tileY + '/' + tileX + '.jpg',
|
||||
GROUND_TILE_DIRECT + GROUND_TILE_Z + '/' + tileY + '/' + tileX + '.jpg'
|
||||
);
|
||||
}
|
||||
|
||||
function decodeToBitmap(blob) {
|
||||
@@ -2181,11 +2192,10 @@ function loadElevTile(zx, zy, halfX, halfY) {
|
||||
});
|
||||
});
|
||||
function fetchFresh(db) {
|
||||
return fetch(ELEV_TILE_URL + ELEV_Z + '/' + zx + '/' + zy + '.png')
|
||||
.then(function (r) {
|
||||
if (!r.ok) throw new Error('elev http ' + r.status);
|
||||
return r.blob();
|
||||
})
|
||||
return fetchBlobWithFallback(
|
||||
ELEV_TILE_URL + ELEV_Z + '/' + zx + '/' + zy + '.png',
|
||||
ELEV_TILE_DIRECT + ELEV_Z + '/' + zx + '/' + zy + '.png'
|
||||
)
|
||||
.then(function (blob) {
|
||||
if (db) tileDbPut(db, { id: id, blob: blob, savedAt: Date.now() });
|
||||
return decodeToBitmap(blob);
|
||||
|
||||
Reference in new issue
Block a user