From 885fa5b785fabae0acfadaeda9ad584183c9a55a Mon Sep 17 00:00:00 2001 From: Stream Date: Sun, 17 May 2026 11:00:01 +0300 Subject: [PATCH] auto-sync: 2026-05-17 11:00:01 --- tasks/enduro-trails/prototype/static/app.js | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tasks/enduro-trails/prototype/static/app.js b/tasks/enduro-trails/prototype/static/app.js index af7cf90..cde51d7 100644 --- a/tasks/enduro-trails/prototype/static/app.js +++ b/tasks/enduro-trails/prototype/static/app.js @@ -88,6 +88,7 @@ function switchMapStyle() { if (!map) return; const dark = isDarkTheme(); const basePath = window.location.pathname.replace(/\/[^/]*$/, '') || ''; + const tileBase = window.location.origin + basePath; const styleUrl = dark ? basePath + '/style-dark.json' : basePath + '/style.json'; // Save current position before style change @@ -96,19 +97,22 @@ function switchMapStyle() { const bearing = map.getBearing(); const pitch = map.getPitch(); - fetch(styleUrl, { method: 'HEAD' }).then(r => { - if (r.ok) { - map.setStyle(styleUrl); - // Restore position and overlays after style loads - map.once('idle', () => { - map.jumpTo({ center, zoom, bearing, pitch }); - rebuildMapOverlays(); - }); - } else { - console.log('Map style not available:', styleUrl); + fetch(styleUrl).then(r => { + if (r.ok) return r.json(); + throw new Error('Style not available'); + }).then(style => { + // Fix tile URLs to absolute (same as initMap) + if (style.sources && style.sources['trails-tiles'] && style.sources['trails-tiles'].tiles) { + style.sources['trails-tiles'].tiles = [`${tileBase}/api/tiles/{z}/{x}/{y}.mvt`]; } + map.setStyle(style); + // Restore position and overlays after style loads + map.once('idle', () => { + map.jumpTo({ center, zoom, bearing, pitch }); + rebuildMapOverlays(); + }); }).catch(() => { - // Network error, don't switch + // Network error or style not available, don't switch }); }