Offline-Karten Runde 2: adaptives Modell (Budget, Funkloch-Gedaechtnis, Korridor, Coverage)

Design Rene 2026-06-06:
- Budget-Download: z14-Ringe um den Standort bis 5 MB gespeicherte Bytes
  (Stadt klein, Land gross — passend zur Funknetzdichte); client-seitig,
  Server-Region-Extract entfaellt
- Funkloch-Gedaechtnis: Tile-Miss bei aktivem GPS-Recording -> Zone gemerkt
  (lokal, nie hochgeladen); Auto-Download offener Zonen sobald online
- Routen-Korridor: 'Offline'-Button im Routen-Detail, Kacheln +-1km um den
  Track + Marker (Cap 50 MB) — fuer mehrtaegige Unternehmungen
- Coverage-Layer: gespeicherte Bereiche als blauer Layer; Offline-Button
  oeffnet Verwaltungs-Modal (Stats, speichern, anzeigen, loeschen)
- Flag-Logik zentral in boot.js BY.offlineTiles() (war 3x dupliziert)
Bump v1226
This commit is contained in:
rene 2026-06-06 12:00:43 +02:00
parent 45534aa8ee
commit 42a04ec405
12 changed files with 466 additions and 91 deletions

View file

@ -21,15 +21,9 @@ window.OfflineIndicator = (() => {
}
// GL-Offline-Tiles-Modus (byt://-Vektorkacheln in IndexedDB) statt OSM-Raster.
// Default-Logik MUSS map-gl-style.js _offlineEnabled() entsprechen (Staging-AN seit 2026-06-06);
// dupliziert weil map-gl-style.js lazy mit der GL-Karte lädt, dieses Modul aber sofort.
// Zentrale Flag-Logik in boot.js BY.offlineTiles().
function _offlineTilesMode() {
try {
const flag = localStorage.getItem('by_offline_tiles');
if (flag === '1') return true;
if (flag === '0') return false;
return location.hostname === 'staging.banyaro.app';
} catch (e) { return false; }
try { return !!(window.BY && BY.offlineTiles()); } 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()
@ -213,7 +207,7 @@ window.OfflineIndicator = (() => {
await Promise.all(tasks);
}
// GL-Offline: Vektor-Region (~5 km) um den aktuellen Standort in IndexedDB laden.
// GL-Offline: Gebiet (~5 MB budget-getrieben) um den aktuellen Standort in IndexedDB laden.
async function _downloadOfflineRegion() {
let pos = null;
try { pos = await API.getLocation(); } catch (e) {}
@ -226,10 +220,53 @@ window.OfflineIndicator = (() => {
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);
if (window.MapOffline) await MapOffline.downloadAround(pos.lat, pos.lon, { budgetMB: 5 });
} catch (e) { console.warn('Offline-Region-Download fehlgeschlagen:', e); }
}
// Gibt es offene (ungefüllte) Funkloch-Zonen? — direkt aus IndexedDB, OHNE den
// GL-Stack zu laden (gleiches Schema/Version wie map-offline.js, s. Warnung oben).
function _openDeadZonesStored() {
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('meta')) { db.close(); return res(false); }
const rq = db.transaction('meta', 'readonly').objectStore('meta').get('deadzones');
rq.onsuccess = () => { res((rq.result || []).some(z => !z.filled)); db.close(); };
rq.onerror = () => { res(false); db.close(); };
};
r.onerror = () => res(false);
} catch (e) { res(false); }
});
}
// Funkloch-Zonen automatisch füllen, sobald Netz da ist — das Gerät lernt selbst,
// wo Offline-Karten nötig sind (dort wo Netz ist, braucht es keine).
let _autoFillTimer = null;
function _scheduleAutoFill(delayMs) {
if (!_offlineTilesMode()) return;
clearTimeout(_autoFillTimer);
_autoFillTimer = setTimeout(async () => {
if (!navigator.onLine) return;
try {
if (!(await _openDeadZonesStored())) return; // nichts zu tun → GL-Stack nicht laden
await UI.loadMapLibreUI();
const n = await window.MapOffline?.autoFillDeadZones?.();
if (n) {
UI.toast?.info(`${n} Funkloch-${n === 1 ? 'Gebiet' : 'Gebiete'} automatisch offline gespeichert.`);
refresh();
}
} catch (e) {}
}, delayMs);
}
// ----------------------------------------------------------
// Tile-URL-Berechnung (OSM, Subdomain 'a')
// ----------------------------------------------------------
@ -398,6 +435,9 @@ window.OfflineIndicator = (() => {
if (e?.data?.type === 'CACHE_TILES_PROGRESS') refresh();
});
}
// Funkloch-Zonen nachladen: verzögert beim Start + sobald die Verbindung zurückkommt.
_scheduleAutoFill(30_000);
window.addEventListener('online', () => _scheduleAutoFill(8_000));
_checkStorageQuota(); // beim Init prüfen
setInterval(() => { _prefetchData(); refresh(); _checkStorageQuota(); }, 60_000);
}