Driving mode ("Drive": big buttons — follow, zoom, 2D/3D, night, route overview — the sidebar hidden); palettes instead of the inversion (the UI's greys onto --ui-*, MapLibre's controls too, night → Night, new ◑ Dusk); the navigated route magenta, the driven part dimmed; route progress only forward (locate near the last position first); rerouting on the server off its own GNSS (TripStore#follow), the browser's only without the shared trip; the overview map hidden while following in 3D; the topbar's items apart
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 01:44:54 +01:00
1 parent 12b4ac6725
commit 07a4d363ec
13 files changed
+520 -219

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
import { LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { requestGnssFollow, onRouteChanged } from "/js/panels.js";
import { pauseFollow, resumeFollow } from "/js/gnss.js";
// Driving mode: the few things needed on the road as big buttons down the
// side of the map, the planning sidebar and panels out of the way (TODO:
// tiny icons can't be hit while driving). Per device (localStorage).
const KEY = "drivingMode";
const PITCH_3D = 60; // as map.js's 3D toggle
export function setupDriving(map, nightButton) {
let route = onRouteChanged((r) => (route = r));
const toggle = document.createElement("button");
toggle.type = "button";
toggle.className = "topbar__drive";
toggle.title = "Driving mode: big buttons, no planning panels";
toggle.textContent = "Drive";
nightButton.before(toggle);
const bar = document.createElement("div");
bar.className = "drive-bar";
bar.hidden = true;
const buttons = {
follow: ["Follow", "Follow the position, heading up in 3D", () => {
requestGnssFollow();
resumeFollow(map);
if (map.getPitch() === 0) map.easeTo({ pitch: PITCH_3D, duration: 300 });
}],
zoomIn: ["+", "Zoom in", () => map.zoomIn()],
zoomOut: ["−", "Zoom out", () => map.zoomOut()],
pitch: ["2D", "2D / 3D", () => map.easeTo({ pitch: map.getPitch() > 0 ? 0 : PITCH_3D, ...(map.getPitch() > 0 && { bearing: 0 }), duration: 300 })],
night: ["", "Night mode", () => nightButton.click()],
overview: ["Route", "The whole route (the follow pauses)", () => {
const coords = route?.geometry?.coordinates;
if (!coords?.length) return;
pauseFollow(map);
map.fitBounds(coords.reduce((b, c) => b.extend(c), new LngLatBounds(coords[0], coords[0])), { padding: 80, pitch: 0, bearing: 0 });
}],
exit: ["✕", "Leave driving mode", () => set(false)],
};
for (const [name, [label, title, action]] of Object.entries(buttons)) {
const button = document.createElement("button");
button.type = "button";
button.className = `drive-bar__${name}`;
button.textContent = label;
button.title = title;
button.setAttribute("aria-label", title);
button.addEventListener("click", action);
bar.appendChild(button);
}
map.getContainer().appendChild(bar);
const render = () => {
bar.querySelector(".drive-bar__pitch").textContent = map.getPitch() > 0 ? "2D" : "3D";
bar.querySelector(".drive-bar__night").textContent = nightButton.textContent;
bar.querySelector(".drive-bar__overview").disabled = !route;
};
map.on("pitchend", render);
nightButton.addEventListener("click", render);
onRouteChanged(render);
function set(on) {
document.documentElement.classList.toggle("driving", on);
bar.hidden = !on;
toggle.classList.toggle("active", on);
try { localStorage.setItem(KEY, on ? "on" : "off"); } catch { /* private window: not kept */ }
render();
map.resize(); // the sidebar came or went
}
toggle.addEventListener("click", () => set(bar.hidden));
let saved = null;
try { saved = localStorage.getItem(KEY); } catch { /* nothing kept */ }
set(saved === "on");
}