standalone without our server: basemap and DEM load from the CORS-enabled upstreams, same-origin proxy only when a probe proves it exists; drop dead kumi.systems mirror

This commit is contained in:
Richard Zink committed 2026-10-11 16:02:10 +02:00
1 parent 3395ac8f8e
commit 499c00d8b1
3 files changed
+62 -19

No files matched your search

+43 -7
View File
@@ -826,12 +826,20 @@ function init(canvas) {
// Tile source per CONFIG.ground.style:
// 'streets' - ESRI World_Street_Map (place names), /esri/streets/
// 'satellite' - ESRI World_Imagery (no labels), /esri/imagery/
// Both are z11 {z}/{y}/{x}.jpg via the nginx CORS proxy. The IndexedDB
// id carries a style prefix so both styles can coexist in the cache.
// Both are z11 {z}/{y}/{x}.jpg (y before x). ESRI answers cross-origin
// GETs with Access-Control-Allow-Origin: *, so the standalone build needs
// no server at all; the same-origin nginx paths are used instead when this
// page has them (proxy cache, friendlier to the upstream). The IndexedDB id
// carries a style prefix so both styles can coexist in the cache.
var GROUND_STYLE_CFG = (window.CONFIG && window.CONFIG.ground &&
window.CONFIG.ground.style) || 'streets';
var GROUND_STYLE = GROUND_STYLE_CFG === 'satellite' ? 'satellite' : 'streets';
var GROUND_TILE_URL = GROUND_STYLE === 'satellite' ? '/esri/imagery/' : '/esri/streets/';
var GROUND_TILE_DIRECT = (GROUND_STYLE === 'satellite')
? 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/'
: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/';
var GROUND_TILE_PROXY = (GROUND_STYLE === 'satellite') ? '/esri/imagery/' : '/esri/streets/';
// direct by default: works from any origin, including a plain file:// open
var GROUND_TILE_URL = GROUND_TILE_DIRECT;
var GROUND_TILE_ID_PREFIX = GROUND_STYLE === 'satellite' ? 'sat/' : '';
// Debug tile overlays (border + N/S + x/y labels) - off unless
// CONFIG.tiles.debug is true.
@@ -1172,9 +1180,31 @@ window.BackgroundCache = {
}
};
// ---- tile source selection ---------------------------------------------
// Start from the public upstreams so the page works anywhere, then switch a
// source over to the same-origin proxy if a probe shows it is really served
// by our nginx (an image content-type is required, so a SPA fallback that
// answers 200 + HTML for every path cannot hijack the switch).
var _tileProxyChecked = false;
function tileProbeProxy() {
if (_tileProxyChecked) return;
_tileProxyChecked = true;
if (location.protocol === 'file:') return;
function probe(path, apply) {
fetch(path, { method: 'HEAD' }).then(function (r) {
var type = (r.headers.get('Content-Type') || '').toLowerCase();
if (r.ok && type.indexOf('image/') === 0) {
apply();
console.log('[clouds3d] tiles: using dev proxy ' + path);
}
}, function () {});
}
probe(ELEV_TILE_PROXY + '11/0/0.png', function () { ELEV_TILE_URL = ELEV_TILE_PROXY; });
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 via local
// proxy. (y before x, jpg not png)
// 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) {
if (!r.ok) throw new Error('tile http ' + r.status);
@@ -1471,7 +1501,14 @@ function recenterGroundMosaic(centerTileX, centerTileY, dLng, dPerp) {
var ELEV_Z = 10;
var ELEV_TILES_PER = 1 << (11 - ELEV_Z); // z11 tiles covered per DEM tile
var ELEV_UNIT_PX = 256 / ELEV_TILES_PER; // canvas px per z11 tile
var ELEV_TILE_URL = '/terrarium/';
// elevation-tiles-prod (AWS) answers cross-origin GETs with CORS, so the
// DEM also loads without our server; /terrarium/ is preferred when present.
var ELEV_TILE_DIRECT = 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/';
var ELEV_TILE_PROXY = '/terrarium/';
var ELEV_TILE_URL = ELEV_TILE_DIRECT;
// (the probe needs both URL pairs assigned, so it runs here, not at the
// ground-source block)
tileProbeProxy();
var elevCanvas = null;
var elevCtx = null;
var elevTexture = null;
@@ -2098,7 +2135,6 @@ var CAR_QUERIES = carCells('geo/mw11', CAR_MOTORWAY_RX, 46.8, 9.4, 50.1, 13.4, 1
// the proxy is actually there (see opProbeProxy), otherwise they are dropped.
var OP_PUBLIC = [
'https://overpass-api.de/api/interpreter',
'https://overpass.kumi.systems/api/interpreter',
'https://maps.mail.ru/osm/tools/overpass/api/interpreter'
];
var OP_PROXY = ['/overpass/api/interpreter', '/overpass/mail/interpreter'];