From 5337ddfa0500aa1d0cd9e3fd2db0002091ec8762 Mon Sep 17 00:00:00 2001 From: rene Date: Fri, 5 Jun 2026 19:53:55 +0200 Subject: [PATCH] Offline-Karten: Welten-FAB Segment 5 + Download-Trigger (flag-gated) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit offline-indicator.js: im GL-Offline-Modus (by_offline_tiles) prüft Segment 5 'Karten-Kacheln' jetzt eine gespeicherte Vektor-Region in IndexedDB (statt des OSM-Raster-Counts, den die GL-Karte nicht nutzt → war falsch-grün). 'Fehlende nachladen' (Segment 5) stößt im GL-Modus MapOffline.downloadAround(GPS, 5km) an. - _offlineRegionStored legt dasselbe IDB-Schema/Version an wie map-offline.js (sonst bricht ein versionsloses open() die Store-Erstellung) - UI.loadMapLibreUI exportiert (für den FAB-Download) Headless verifiziert: Flag an, keine Fehler; Segment 5 vor Download grau (0), nach Download grün (97 Tiles). --- VERSION | 2 +- backend/static/index.html | 24 ++++++------ backend/static/js/app.js | 2 +- backend/static/js/offline-indicator.js | 52 +++++++++++++++++++++++++- backend/static/js/ui.js | 1 + backend/static/landing.html | 2 +- backend/static/sw.js | 2 +- 7 files changed, 67 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 02be51a..847dd18 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1211 \ No newline at end of file +1213 \ No newline at end of file diff --git a/backend/static/index.html b/backend/static/index.html index 5987a83..77b269b 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -86,14 +86,14 @@ Ban Yaro - + - - - - - + + + + + @@ -617,11 +617,11 @@ - - - - - + + + + + @@ -631,7 +631,7 @@ - + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 55a367c..00af0f7 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '1211'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '1213'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator) window.APP_VERSION = APP_VERSION; diff --git a/backend/static/js/offline-indicator.js b/backend/static/js/offline-indicator.js index 234fca0..55e93b1 100644 --- a/backend/static/js/offline-indicator.js +++ b/backend/static/js/offline-indicator.js @@ -20,6 +20,34 @@ window.OfflineIndicator = (() => { return found ? await caches.open(found) : null; } + // GL-Offline-Tiles-Modus (byt://-Vektorkacheln in IndexedDB) statt OSM-Raster. + function _offlineTilesMode() { + try { return localStorage.getItem('by_offline_tiles') === '1'; } catch (e) { return false; } + } + // Ist eine Offline-Region (Vektorkacheln) in IndexedDB gespeichert? (ohne MapOffline zu laden) + // WICHTIG: dasselbe Schema/Version wie map-offline.js anlegen — sonst legt ein versionsloses open() + // die DB leer an und MapOffline kann seine Stores nicht mehr erstellen. + function _offlineRegionStored() { + return new Promise(res => { + try { + const r = indexedDB.open('by-offline-tiles', 1); + r.onupgradeneeded = () => { + const d = r.result; + if (!d.objectStoreNames.contains('tiles')) d.createObjectStore('tiles'); + if (!d.objectStoreNames.contains('meta')) d.createObjectStore('meta'); + }; + r.onsuccess = () => { + const db = r.result; + if (!db.objectStoreNames.contains('tiles')) { db.close(); return res(false); } + const cnt = db.transaction('tiles', 'readonly').objectStore('tiles').count(); + cnt.onsuccess = () => { res(cnt.result > 0); db.close(); }; + cnt.onerror = () => { res(false); db.close(); }; + }; + r.onerror = () => res(false); + } catch (e) { res(false); } + }); + } + const CHECKS = [ { step: 1, title: 'App-Grundgerüst', detail: 'CSS, Layout und Hauptmodule — die Basis', @@ -69,8 +97,10 @@ window.OfflineIndicator = (() => { } }, { step: 5, title: 'Karten-Kacheln', - detail: `Mindestens ${TILE_MIN} OSM-Tiles im Umkreis`, + detail: 'Karten für deine Gegend offline verfügbar', probe: async () => { + // GL-Modus: gespeicherte Vektor-Region in IndexedDB (das alte OSM-Raster nutzt die GL-Karte nicht). + if (_offlineTilesMode()) return _offlineRegionStored(); const c = await caches.open(CACHE_TILES).catch(() => null); if (!c) return false; return (await c.keys()).length >= TILE_MIN; @@ -169,12 +199,30 @@ window.OfflineIndicator = (() => { tasks.push(fetch('/api/routes').catch(() => {})); tasks.push(fetch('/api/notes').catch(() => {})); } else if (m.step === 5) { - await _prefetchTiles(); + if (_offlineTilesMode()) await _downloadOfflineRegion(); + else await _prefetchTiles(); } } await Promise.all(tasks); } + // GL-Offline: Vektor-Region (~5 km) um den aktuellen Standort in IndexedDB laden. + async function _downloadOfflineRegion() { + let pos = null; + try { pos = await API.getLocation(); } catch (e) {} + if (!pos) { + try { + const raw = localStorage.getItem(LS_LAST_POS); + if (raw) { const p = JSON.parse(raw); pos = { lat: p.lat, lon: p.lon }; } + } catch (e) {} + } + if (!pos) { UI.toast.warning('Standort nötig, um die Gegend offline zu speichern.'); return; } + try { + await UI.loadMapLibreUI(); + if (window.MapOffline) await MapOffline.downloadAround(pos.lat, pos.lon, 5); + } catch (e) { console.warn('Offline-Region-Download fehlgeschlagen:', e); } + } + // ---------------------------------------------------------- // Tile-URL-Berechnung (OSM, Subdomain 'a') // ---------------------------------------------------------- diff --git a/backend/static/js/ui.js b/backend/static/js/ui.js index 23a71d5..b3d66a8 100644 --- a/backend/static/js/ui.js +++ b/backend/static/js/ui.js @@ -1800,6 +1800,7 @@ const UI = (() => { escape, escHtml, help, pageInfo, saveToAlbum, loadLeaflet, + loadMapLibreUI, leafletMarker, locationPicker, map, diff --git a/backend/static/landing.html b/backend/static/landing.html index 2cbc2a4..5f3d168 100644 --- a/backend/static/landing.html +++ b/backend/static/landing.html @@ -4,7 +4,7 @@ - + Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz diff --git a/backend/static/sw.js b/backend/static/sw.js index b9fa861..8a9b471 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -4,7 +4,7 @@ ============================================================ */ // ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab -const VER = '1211'; +const VER = '1213'; const CACHE_VERSION = `by-v${VER}`; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten