Offline: Giftkoeder + vermisste Hunde offline sichtbar, Korridor auf Detailkarte
Geraetetest-Befunde Runde 2: - Giftkoeder verschwanden offline: /api/places kam aus dem SW-Cache (feste URL) und verhinderte den allFailed-Fallback, waehrend /api/poison?lat=... (Bbox-URL) scheiterte -> jetzt faellt jede Quelle EINZELN auf den letzten guten Stand zurueck (localStorage) + Merge aus dem Offline-Region-Snapshot - Region-Download speichert jetzt auch /api/poison + /api/lost der Gegend (p/_poison, p/_lost, anonym; MapOffline.alerts(kind,bbox) als Reader) — Sicherheitsdaten muessen auch am vorab gespeicherten Urlaubsort da sein - lost.js Offline-Pfad merged den Region-Snapshot in Cache- und Leer-Fall - Routen-Korridor war 'unsichtbar' (lag im schon gespeicherten Gebiet): nach dem Speichern werden die gespeicherten Bereiche blau auf der Detailkarte eingeblendet; Logik per Node-Stub-Test verifiziert Bump v1227
This commit is contained in:
parent
42a04ec405
commit
a600ca1dec
9 changed files with 125 additions and 49 deletions
|
|
@ -126,6 +126,22 @@ window.MapOffline = (function () {
|
|||
var POI_TYPES = ['waste_basket', 'dog_park', 'drinking_water', 'tierarzt', 'hundesalon', 'shop',
|
||||
'restaurant', 'bank', 'giftkoeder', 'kotbeutel', 'gefahr', 'parkplatz',
|
||||
'treffpunkt', 'sonstiges', 'hotel'];
|
||||
|
||||
// Frische Liste mit Bestand mergen (per id) — eine zweite Region (Urlaubsort) darf die erste
|
||||
// nicht löschen. Liefert die Anzahl frischer Einträge.
|
||||
function _mergeStore(key, fresh) {
|
||||
if (!fresh || !fresh.length) return Promise.resolve(0);
|
||||
return _get(key).then(function (old) {
|
||||
var merged = fresh;
|
||||
if (old && old.length) {
|
||||
var seen = {};
|
||||
fresh.forEach(function (p) { seen[p.id] = true; });
|
||||
merged = fresh.concat(old.filter(function (p) { return !seen[p.id]; }));
|
||||
}
|
||||
return _put(key, merged).then(function () { return fresh.length; });
|
||||
});
|
||||
}
|
||||
|
||||
function _cachePois(bbox) {
|
||||
var total = 0;
|
||||
var jobs = POI_TYPES.map(function (type) {
|
||||
|
|
@ -133,25 +149,41 @@ window.MapOffline = (function () {
|
|||
south: bbox.south, west: bbox.west, north: bbox.north, east: bbox.east });
|
||||
return fetch('/api/osm/pois?' + params)
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (fresh) {
|
||||
if (!fresh || !fresh.length) return;
|
||||
total += fresh.length;
|
||||
// Mit Bestand mergen (per id) — eine zweite Region (Urlaubsort) darf die erste nicht löschen.
|
||||
return _get('p/' + type).then(function (old) {
|
||||
var merged = fresh;
|
||||
if (old && old.length) {
|
||||
var seen = {};
|
||||
fresh.forEach(function (p) { seen[p.id] = true; });
|
||||
merged = fresh.concat(old.filter(function (p) { return !seen[p.id]; }));
|
||||
}
|
||||
return _put('p/' + type, merged);
|
||||
});
|
||||
})
|
||||
.then(function (fresh) { return _mergeStore('p/' + type, fresh); })
|
||||
.then(function (n) { total += n; })
|
||||
.catch(function () {});
|
||||
});
|
||||
|
||||
// Sicherheitsdaten MÜSSEN offline da sein (René 2026-06-07): Giftköder-Alarme
|
||||
// (/api/poison, Radius in m) + vermisste Hunde (/api/lost, Radius in km) — beide anonym.
|
||||
var midLat = (bbox.south + bbox.north) / 2, midLon = (bbox.west + bbox.east) / 2;
|
||||
var radiusKm = Math.max(
|
||||
(bbox.north - bbox.south) * 111 / 2,
|
||||
(bbox.east - bbox.west) * 111 * Math.cos(midLat * Math.PI / 180) / 2, 1);
|
||||
jobs.push(fetch('/api/poison?lat=' + midLat + '&lon=' + midLon + '&radius=' + Math.round(radiusKm * 1000))
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (fresh) { return _mergeStore('p/_poison', fresh); })
|
||||
.then(function (n) { total += n; })
|
||||
.catch(function () {}));
|
||||
jobs.push(fetch('/api/lost?lat=' + midLat + '&lon=' + midLon + '&radius_km=' + Math.ceil(radiusKm))
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (fresh) { return _mergeStore('p/_lost', fresh); })
|
||||
.then(function (n) { total += n; })
|
||||
.catch(function () {}));
|
||||
|
||||
return Promise.all(jobs).then(function () { return total; });
|
||||
}
|
||||
|
||||
// Gespeicherte Sicherheits-Alarme ('poison' | 'lost') im Bbox-Ausschnitt — Offline-Fallback.
|
||||
function alerts(kind, bbox) {
|
||||
return _get('p/_' + kind).then(function (list) {
|
||||
if (!list || !list.length) return [];
|
||||
return list.filter(function (p) {
|
||||
return p.lat >= bbox.south && p.lat <= bbox.north && p.lon >= bbox.west && p.lon <= bbox.east;
|
||||
});
|
||||
}).catch(function () { return []; });
|
||||
}
|
||||
|
||||
// Gespeicherte POIs eines Typs im Bbox-Ausschnitt — Offline-Fallback für die Karten-Marker.
|
||||
function pois(type, bbox) {
|
||||
return _get('p/' + type).then(function (list) {
|
||||
|
|
@ -414,7 +446,7 @@ window.MapOffline = (function () {
|
|||
|
||||
return {
|
||||
registerProtocol: registerProtocol, downloadAround: downloadAround, downloadCorridor: downloadCorridor,
|
||||
tile: tile, glyph: glyph, pois: pois, coverage: coverage,
|
||||
tile: tile, glyph: glyph, pois: pois, alerts: alerts, coverage: coverage,
|
||||
setGps: setGps, markDeadZone: markDeadZone, autoFillDeadZones: autoFillDeadZones,
|
||||
stats: stats, hasRegion: hasRegion, clear: clear, MAXZOOM: MAXZOOM,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue