auto-sync: 2026-05-17 11:00:01
This commit is contained in:
26
tasks/enduro-trails/prototype/static/app.js
vendored
26
tasks/enduro-trails/prototype/static/app.js
vendored
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user