fix: fall back to direct tile URLs on proxy errors

This commit is contained in:
Richard Zink committed 2026-10-13 11:14:45 +02:00
1 parent 5ce027fd5d
commit c02a198f3f
1 file changed
+19 -9
+19 -9
View File
@@ -1834,13 +1834,24 @@ 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) {
@@ -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);