Drive: the limit as a round sign at the speed field's end (the next one under it), the speed red past it; the Limit cell gone, Speed over 4 cells, and no surface in its place (the terrain panel's head has it). Terrain view in the Menu: opens and closes by itself / opens and stays / by hand; simulated, the tilt doesn't open it (the DEM's slope on a hillside road is the hill's). Desktop: the sun times in the status bar (the chart opens over it), the night button out of the top bar — On the map's Theme row and drive mode still cycle it
CI / check (push) Successful in 25s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 14:21:07 +01:00
1 parent f981b80599
commit f15fbef746
6 files changed
+72 -36

No files matched your search

+22 -15
View File
@@ -43,13 +43,11 @@ const NOT_YET = new Set();
// TILT_DEG for TILT_S; back to the road view after PAVED_BACK_M on paved road.
// Closed by hand while still off-road: not again until back on the road.
const UNPAVED = new Set(["compacted", "dirt", "gravel", "path", "impassable"]);
// Valhalla's surfaces, shown in place of the limit while the terrain view is open
const SURFACES = { paved_smooth: "Paved", paved: "Paved", paved_rough: "Rough", compacted: "Compacted", dirt: "Dirt", gravel: "Gravel", path: "Track", impassable: "Impassable" };
const TILT_DEG = 10;
const TILT_S = 10;
const PAVED_BACK_M = 2000;
const TERRAIN_AUTO_KEY = "maptool.terrainAuto";
const FIELDS = { speed: "Speed", limit: "Limit", surface: "Surface", altitude: "Altitude", time: "Time", sun: "Sun", nextStop: "Next stop",
const FIELDS = { speed: "Speed", limit: "Limit", altitude: "Altitude", time: "Time", sun: "Sun", nextStop: "Next stop",
toNextStop: "To next stop", etaNextStop: "ETA next stop", toEnd: "To the end" };
const CARDINALS = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
@@ -107,11 +105,15 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
<button type="button" class="drive-menu__row" data-action="overview">The whole route <small>the follow pauses</small></button>
<button type="button" class="drive-menu__row" data-action="terrain-auto"></button>
<button type="button" class="drive-menu__row" data-action="leave">Leave driving mode</button>`;
const terrainAuto = () => { try { return localStorage.getItem(TERRAIN_AUTO_KEY) !== "hand"; } catch { return true; } };
// auto: opens off-road and closes back on the road; stay: opens and stays (the inclinometer all along); hand: neither
const TERRAIN_MODES = { auto: "opens and closes by itself", stay: "opens by itself, stays", hand: "by hand" };
const terrainMode = () => { try { const m = localStorage.getItem(TERRAIN_AUTO_KEY); return m in TERRAIN_MODES ? m : "auto"; } catch { return "auto"; } };
const terrainAuto = () => terrainMode() !== "hand";
const autoButton = menuPanel.querySelector('[data-action="terrain-auto"]');
const renderAuto = () => { autoButton.innerHTML = `Terrain view: ${terrainAuto() ? "automatic" : "by hand"} <small>tap to switch</small>`; };
const renderAuto = () => { autoButton.innerHTML = `Terrain view: ${TERRAIN_MODES[terrainMode()]} <small>tap to switch</small>`; };
autoButton.addEventListener("click", () => {
try { localStorage.setItem(TERRAIN_AUTO_KEY, terrainAuto() ? "hand" : "auto"); } catch { /* private window: not kept */ }
const modes = Object.keys(TERRAIN_MODES);
try { localStorage.setItem(TERRAIN_AUTO_KEY, modes[(modes.indexOf(terrainMode()) + 1) % modes.length]); } catch { /* private window: not kept */ }
renderAuto();
});
renderAuto();
@@ -231,7 +233,9 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
const now = Date.now();
const dt = (now - lastState) / 1000;
lastState = now;
const tilted = Math.max(Math.abs(v.roll ?? 0), Math.abs(v.pitch ?? 0)) >= TILT_DEG;
// simulated, the tilt is the DEM's slope round the car — on a road cut into a hillside that's the
// hill's, not the car's, so it doesn't count (the surface still does); the dials still show it
const tilted = !state.simulated && Math.max(Math.abs(v.roll ?? 0), Math.abs(v.pitch ?? 0)) >= TILT_DEG;
tiltSince = tilted ? tiltSince ?? now : null;
offRoad = UNPAVED.has(state.surface) || (tiltSince != null && now - tiltSince >= TILT_S * 1000);
if (offRoad) pavedM = 0;
@@ -243,7 +247,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
if (offRoad && !suppressed && !openPanel) {
open(terrain.el);
autoOpened = true;
} else if (autoOpened && openPanel === terrain.el && pavedM >= PAVED_BACK_M) open(null);
} else if (terrainMode() === "auto" && autoOpened && openPanel === terrain.el && pavedM >= PAVED_BACK_M) open(null);
};
function open(panel) {
if (openPanel === terrain.el && panel !== terrain.el) {
@@ -418,14 +422,17 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
const limit = nav?.limit;
const now = new Date();
switch (name) {
case "speed":
return [kmh == null ? "—" : Math.round(kmh), "km/h", typeof limit === "number" && kmh > limit + OVER_KMH ? "drive-cell--warn" : ""];
case "speed": {
// the limit as a sign at the field's end, the next one under it; the speed red past the limit
const next = nav?.next ? `${typeof nav.next.limit === "number" ? nav.next.limit : "∞"} in ${distance(nav.next.m)}` : "";
const sign = typeof limit === "number" || limit === "unlimited"
? `<span class="drive-speed__limit" aria-label="Limit ${limit}"><b>${limit === "unlimited" ? "∞" : limit}</b>${next ? `<small>${escapeHtml(next)}</small>` : ""}</span>` : "";
return [kmh == null ? "—" : Math.round(kmh), "km/h", typeof limit === "number" && kmh > limit + OVER_KMH ? "drive-cell--warn" : "", sign];
}
case "limit": {
const next = nav?.next ? `· ${typeof nav.next.limit === "number" ? nav.next.limit : "∞"} in ${distance(nav.next.m)}` : "";
return [typeof limit === "number" ? limit : limit === "unlimited" ? "∞" : "—", next, "drive-cell--limit"];
}
case "surface":
return [SURFACES[dash?.surface] || "—", dash?.surface ? "" : "unknown", UNPAVED.has(dash?.surface) ? "drive-terrain--caution" : ""];
case "altitude":
return [v.alt == null ? "—" : Math.round(v.alt), "m"];
case "time":
@@ -494,9 +501,9 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
const a = ahead();
for (const { cell, el } of cells) {
if (cell.widget === "field") {
const name = cell.value === "limit" && openPanel === terrain.el ? "surface" : cell.value; // off-road the surface matters, not the limit
const [value, unit, cls = ""] = fieldValue(name, a);
el.innerHTML = `<span class="drive-cell__label">${FIELDS[name] || name}</span><span class="drive-cell__value ${cls}">${escapeHtml(value)} <small>${escapeHtml(unit)}</small></span>`;
const name = cell.value;
const [value, unit, cls = "", extra = ""] = fieldValue(name, a);
el.innerHTML = `${extra}<span class="drive-cell__label">${FIELDS[name] || name}</span><span class="drive-cell__value ${cls}">${escapeHtml(value)} <small>${escapeHtml(unit)}</small></span>`;
} else if (cell.widget === "maneuver") renderManeuver(el);
else if (cell.widget === "status") {
el.innerHTML = `<b class="drive-status__brand">MAPTOOL</b><span class="drive-cell__muted"><span class="${navigator.onLine ? "drive-status--ok" : ""}">●</span> ${navigator.onLine ? "online" : "offline"}${log?.active ? ` · <span class="drive-status--rec">● rec</span>` : ""}</span>`;
+1 -1
View File
@@ -370,7 +370,7 @@ coordsLabel.addEventListener("click", async () => {
// barely moves between two nearby spots, not worth recomputing constantly)
// plus a periodic tick so the "Xh Ym to sunset" countdown keeps counting
// down even while the map sits still.
const sunLabel = document.querySelector(".topbar__sun");
const sunLabel = document.querySelector(".statusbar__sun");
const sunChart = document.querySelector(".sun-chart");
const updateSun = () => {
const { lng, lat } = map.getCenter();