Offline-Karten: Welten-FAB Segment 5 + Download-Trigger (flag-gated)
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).
This commit is contained in:
parent
8f13f4d38d
commit
5337ddfa05
7 changed files with 67 additions and 18 deletions
|
|
@ -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')
|
||||
// ----------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue