Feature: Gassirunden-Chip auf Welcome öffnet direkt ORS-Vorschlag im Routen-Tab — SW by-v479, APP_VER 456
This commit is contained in:
parent
369eae5e5a
commit
ca8bb495b0
4 changed files with 61 additions and 76 deletions
|
|
@ -363,55 +363,45 @@ window.Page_welcome = (() => {
|
|||
</div>`;
|
||||
}
|
||||
|
||||
// Versucht async eine Bank in 2 km Umkreis zu finden und ersetzt Chip 2
|
||||
async function _tryBenchChip(dashData) {
|
||||
// Berechnet async eine Tages-Gassirunde via ORS und ersetzt Chip 2
|
||||
async function _tryRouteChip(dashData) {
|
||||
if (dashData?.next_appointment) return; // Termin hat Vorrang
|
||||
let loc;
|
||||
try { loc = await API.getLocation({ timeout: 5000, maximumAge: 300000 }); }
|
||||
catch { return; }
|
||||
|
||||
const d = 0.018; // ~2 km in Grad
|
||||
let pois;
|
||||
// Täglich stabile, aber rotierende Distanz + Variante
|
||||
const dayIdx = Math.floor(Date.now() / 86400000);
|
||||
const km = [2, 4, 6][dayIdx % 3];
|
||||
const seed = dayIdx % 5;
|
||||
|
||||
let result;
|
||||
try {
|
||||
pois = await API.osm.pois('bank', loc.lat - d, loc.lon - d, loc.lat + d, loc.lon + d);
|
||||
result = await API.post('/routes/suggest', { lat: loc.lat, lon: loc.lon, distance_km: km, seed });
|
||||
} catch { return; }
|
||||
|
||||
if (!pois || pois.length === 0) return;
|
||||
|
||||
// täglich stabile Auswahl, aber täglich andere Bank
|
||||
const dayIdx = Math.floor(Date.now() / 86400000);
|
||||
const bench = pois[dayIdx % pois.length];
|
||||
const distM = Math.round(_haversine(loc.lat, loc.lon, bench.lat, bench.lon));
|
||||
const distTxt = distM < 1000 ? `${distM} m` : `${(distM / 1000).toFixed(1)} km`;
|
||||
const name = bench.name || 'Bank';
|
||||
if (!result?.gps_track?.length) return;
|
||||
|
||||
const chipsRow = _container.querySelector('#wc-chips-row');
|
||||
if (!chipsRow) return;
|
||||
|
||||
// Chip ggf. schon da (Termin-Chip) oder neu einfügen (nach Chip 1)
|
||||
let chip2 = _container.querySelector('#wc-chip-mid');
|
||||
if (!chip2) {
|
||||
chip2 = document.createElement('div');
|
||||
chip2.className = 'wc-chip';
|
||||
chip2.id = 'wc-chip-mid';
|
||||
// nach erstem Chip einfügen
|
||||
chip2.className = 'wc-chip';
|
||||
chip2.id = 'wc-chip-mid';
|
||||
const first = chipsRow.querySelector('.wc-chip');
|
||||
first ? first.after(chip2) : chipsRow.prepend(chip2);
|
||||
}
|
||||
chip2.dataset.nav = 'map';
|
||||
const durStr = result.dauer_min < 60
|
||||
? `${result.dauer_min} min`
|
||||
: `${Math.floor(result.dauer_min / 60)}h ${result.dauer_min % 60}min`;
|
||||
chip2.innerHTML = `
|
||||
<svg class="ph-icon wc-chip-icon" aria-hidden="true"><use href="/icons/phosphor.svg#path"></use></svg>
|
||||
<span class="wc-chip-label">Gassirunde</span>
|
||||
<span class="wc-chip-val">${UI.escape(name)} · ${distTxt}</span>`;
|
||||
chip2.addEventListener('click', () => App.navigate('map'));
|
||||
}
|
||||
|
||||
function _haversine(lat1, lon1, lat2, lon2) {
|
||||
const R = 6371000;
|
||||
const f1 = lat1 * Math.PI / 180, f2 = lat2 * Math.PI / 180;
|
||||
const df = (lat2 - lat1) * Math.PI / 180, dl = (lon2 - lon1) * Math.PI / 180;
|
||||
const a = Math.sin(df/2)**2 + Math.cos(f1)*Math.cos(f2)*Math.sin(dl/2)**2;
|
||||
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||
<span class="wc-chip-val">${result.distanz_km} km · ${durStr}</span>`;
|
||||
chip2.addEventListener('click', () => {
|
||||
App.navigate('routes', true, { _suggestResult: result, _suggestKm: km, _suggestSeed: seed });
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
|
|
@ -473,7 +463,7 @@ window.Page_welcome = (() => {
|
|||
API.dogs.welcomeDashboard(dog.id).then(dash => {
|
||||
_updateHeroFromDash(dash, dog);
|
||||
_updateChipsFromDash(dash);
|
||||
_tryBenchChip(dash); // nach Chips-Update: ggf. mit naher Bank ersetzen
|
||||
_tryRouteChip(dash); // nach Chips-Update: ggf. Gassirunden-Vorschlag einfügen
|
||||
}).catch(() => { /* Skeleton bleibt sichtbar */ });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue