Driving bar after the research: four 76 px buttons (zoom ±, 2D/3D, route overview), one Follow button bottom left shown only while the map isn't following, night and exit off the bar; research on day/night and on driving buttons (Garmin aviation/marine/zūmo, ships' ECDIS/S-Mode, Android Auto) in docs/design.adoc, its follow-ups in TODO
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 02:02:55 +01:00
1 parent 9b797fd48c
commit 0eb9d05cdc
5 files changed
+211 -36

No files matched your search

+28 -5
View File
@@ -3544,9 +3544,10 @@ html.driving #map .maplibregl-ctrl-top-left { display: none; }
max-height: calc(100% - 24px); /* a low screen: the buttons shrink, to 44 px */
}
.drive-bar[hidden] { display: none; }
.drive-bar button {
.drive-bar button,
.drive-bar__recenter {
width: 76px;
flex: 0 1 64px;
flex: 0 1 76px;
min-height: 44px;
border: none;
border-radius: 12px;
@@ -3557,11 +3558,33 @@ html.driving #map .maplibregl-ctrl-top-left { display: none; }
box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
cursor: pointer;
}
.drive-bar .drive-bar__follow,
.drive-bar .drive-bar__overview { font-size: 16px; }
.drive-bar button:active { background: var(--accent); }
.drive-bar button:active,
.drive-bar__recenter:active { background: var(--accent); }
/* the one follow / back-to-the-position button, bottom left, only while
the map isn't following (driving.js); gnss.js's own one not meanwhile */
.drive-bar__recenter {
position: absolute;
left: 12px;
bottom: 36px;
z-index: 4;
width: auto;
height: 76px;
padding: 0 22px;
border: none;
border-radius: 12px;
background: var(--band);
color: var(--band-fg);
font-size: 18px;
font-weight: 700;
box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
cursor: pointer;
}
.drive-bar__recenter[hidden],
html.driving .follow-resume { display: none; }
.drive-bar button:disabled { opacity: 0.4; }
html.follow-3d .maplibregl-ctrl-overview-map { display: none; }
.drive-bar .drive-bar__night { font-size: 30px; }
/* npmap's home button draws its house in #333: the UI's text color instead */
.feather-home { fill: var(--ui-fg); }
:root[data-palette] .drive-bar button,
:root[data-palette] .drive-bar__recenter { box-shadow: 0 0 0 1px var(--ui-line), 0 2px 8px rgb(0 0 0 / 0.35); }
+36 -31
View File
@@ -1,12 +1,16 @@
import { LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { requestGnssFollow, onRouteChanged } from "/js/panels.js";
import { pauseFollow, resumeFollow } from "/js/gnss.js";
import { pauseFollow, resumeFollow, isFollowing } 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).
// Driving mode: the few things needed on the road as big buttons, the
// planning sidebar and panels out of the way. After the research in
// docs/design.adoc ("Buttons while driving"): four buttons on the map
// (Android Auto's action strip: at most four, 76 px), the recenter button
// only while the map isn't following (as Google Maps), night automatic and
// leaving by the topbar's Drive. Per device (localStorage).
const KEY = "drivingMode";
const PITCH_3D = 60; // as map.js's 3D toggle
const CHECK_MS = 1000; // how often the recenter button looks whether the map follows
export function setupDriving(map, nightButton) {
let route = onRouteChanged((r) => (route = r));
@@ -17,47 +21,48 @@ export function setupDriving(map, nightButton) {
toggle.textContent = "Drive";
nightButton.before(toggle);
const button = (name, label, title, action) => {
const el = document.createElement("button");
el.type = "button";
el.className = `drive-bar__${name}`;
el.textContent = label;
el.title = title;
el.setAttribute("aria-label", title);
el.addEventListener("click", action);
return el;
};
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)", () => {
bar.append(
button("zoomIn", "+", "Zoom in", () => map.zoomIn()),
button("zoomOut", "−", "Zoom out", () => map.zoomOut()),
button("pitch", "3D", "2D / 3D", () => map.easeTo({ pitch: map.getPitch() > 0 ? 0 : PITCH_3D, ...(map.getPitch() > 0 && { bearing: 0 }), duration: 300 })),
button("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);
}),
);
// the one "follow / back to the position", bottom left, only when needed
const recenter = button("recenter", "Follow", "Follow the position, heading up in 3D", () => {
requestGnssFollow();
resumeFollow(map);
if (map.getPitch() === 0) map.easeTo({ pitch: PITCH_3D, duration: 300 });
recenter.hidden = true;
});
recenter.hidden = true;
map.getContainer().append(bar, recenter);
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;
recenter.hidden = bar.hidden || isFollowing(map);
};
map.on("pitchend", render);
nightButton.addEventListener("click", render);
onRouteChanged(render);
setInterval(render, CHECK_MS);
function set(on) {
document.documentElement.classList.toggle("driving", on);
+7
View File
@@ -57,6 +57,13 @@ export function pauseFollow(map) {
state.timer = setTimeout(() => (state.button.hidden = true), FREE_LOOK_MS);
}
// Is the map following a position right now (a follow step lately, not
// paused by hand)? For the driving bar's recenter button.
export function isFollowing(map) {
const state = freeLookState(map);
return Date.now() - state.followedAt <= FOLLOWING_MS && Date.now() >= state.until;
}
export function resumeFollow(map) {
const state = freeLookState(map);
state.until = 0;