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,14 +1834,25 @@ function tileProbeProxy() {
|
|||||||
probe(GROUND_TILE_PROXY + GROUND_TILE_Z + '/0/0.jpg',
|
probe(GROUND_TILE_PROXY + GROUND_TILE_Z + '/0/0.jpg',
|
||||||
function () { GROUND_TILE_URL = GROUND_TILE_PROXY; });
|
function () { GROUND_TILE_URL = GROUND_TILE_PROXY; });
|
||||||
}
|
}
|
||||||
function fetchTileBlob(tileX, tileY) {
|
function fetchBlobWithFallback(primaryUrl, fallbackUrl) {
|
||||||
// ESRI World_Street_Map format: {z}/{y}/{x}.jpg (y before x, jpg not png)
|
function get(url) {
|
||||||
return fetch(GROUND_TILE_URL + GROUND_TILE_Z + '/' + tileY + '/' + tileX + '.jpg')
|
return fetch(url).then(function (r) {
|
||||||
.then(function (r) {
|
|
||||||
if (!r.ok) throw new Error('tile http ' + r.status);
|
if (!r.ok) throw new Error('tile http ' + r.status);
|
||||||
return r.blob();
|
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) {
|
function decodeToBitmap(blob) {
|
||||||
if (window.createImageBitmap) return createImageBitmap(blob);
|
if (window.createImageBitmap) return createImageBitmap(blob);
|
||||||
@@ -2181,11 +2192,10 @@ function loadElevTile(zx, zy, halfX, halfY) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
function fetchFresh(db) {
|
function fetchFresh(db) {
|
||||||
return fetch(ELEV_TILE_URL + ELEV_Z + '/' + zx + '/' + zy + '.png')
|
return fetchBlobWithFallback(
|
||||||
.then(function (r) {
|
ELEV_TILE_URL + ELEV_Z + '/' + zx + '/' + zy + '.png',
|
||||||
if (!r.ok) throw new Error('elev http ' + r.status);
|
ELEV_TILE_DIRECT + ELEV_Z + '/' + zx + '/' + zy + '.png'
|
||||||
return r.blob();
|
)
|
||||||
})
|
|
||||||
.then(function (blob) {
|
.then(function (blob) {
|
||||||
if (db) tileDbPut(db, { id: id, blob: blob, savedAt: Date.now() });
|
if (db) tileDbPut(db, { id: id, blob: blob, savedAt: Date.now() });
|
||||||
return decodeToBitmap(blob);
|
return decodeToBitmap(blob);
|
||||||
|
|||||||
Reference in new issue
Block a user