From ad975bcf62bccd991ead4e8df73c996335d4ad48 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Thu, 3 Dec 2026 17:44:27 +0100 Subject: [PATCH] What's here on a right click / long press / Alt+click (the Design canvas' Desktop): the position on top (a click copies it, with the DMS and the ground's height), Route here / Add to the trip / Save a point, the features' raw properties folded under it; C copies the position under the mouse. Voice prompts while navigating (speechSynthesis, Valhalla's verbal alert and pre-transition instructions, ~25 s and ~7 s ahead), on/off in drive mode's Menu, off by default. TODO: the touch items closed (the Pad7 is fine as it is) --- TODO.adoc | 22 +++++++----- lib/maptool/routing.rb | 3 +- public/css/style.css | 15 ++++++++ public/js/dashboard.js | 24 +++++++++++++ public/js/driving.js | 12 ++++++- public/js/map.js | 82 ++++++++++++++++++++++++++++++------------ public/js/notes.js | 8 +++++ test/test_routing.rb | 4 +-- 8 files changed, 134 insertions(+), 36 deletions(-) diff --git a/TODO.adoc b/TODO.adoc index 6b4ed97..9b2dcce 100644 --- a/TODO.adoc +++ b/TODO.adoc @@ -89,12 +89,12 @@ independence from connectivity. The app is already reachable from the internet behind login, so a tablet is enough to plan from — the server does the heavy lifting. The UI is built for a mouse today. -* [ ] Touch targets ≥ 44 px (tree rows, panel buttons, icon grids) +* [x] Touch targets ≥ 44 px (tree rows, panel buttons, icon grids) — on the Pad7 everything is big enough (2026-12-03), nothing more to do ** [x] Route markers: an invisible 48px grab area around the dot (a finger missed the 26px dot and panned the map) ** [x] Tracks & Points open/close arrows: a 24×28 px hit area, 36×40 on touch screens ** [x] Notes can be moved (Move in the popup: drag the marker or tap the new spot), and new/edited points get an icon, a color and B/I buttons -* [ ] Nothing reachable only by hover — tooltips and flyouts must open on tap too -* [ ] A touch substitute for the Alt+click debug inspector (e.g. long-press) +* [x] Nothing reachable only by hover — tooltips and flyouts must open on tap too +* [x] A touch substitute for the Alt+click debug inspector (e.g. long-press) — the long press is a contextmenu: what's here * [x] Side panels as an overlay in portrait instead of a pinned column — under 640 px the pin is ignored and the panel floats over the map at full width (a pinned 300 px panel left the phone a sliver of map); a real bottom sheet still open * [x] Driving mode (field test in the car, 2026-11): tiny icons and lists can't be hit while driving — a separate big-button UI for the few things needed on the road (navigate/follow, night mode, zoom, layer presets) rather than enlarging every planning panel. Done: "Drive" in the topbar (`driving.js`), per device — Follow, zoom, 2D/3D, night, route overview, exit down the left side; the sidebar and panels hidden ** [x] Layer presets on the driving bar (Layers: Road / Off-road / Overnight, + Keep) @@ -163,9 +163,11 @@ plan from — the server does the heavy lifting. The UI is built for a mouse tod text fields. Who: the navigator (co-driver) runs the whole UI and the trip's points on the 16" display; the driver only looks at a finished map on Android Auto, touching the 16" only now and then — so it's simple for a moving car, not driver-distraction rules -* [ ] Desktop (the Design canvas' Desktop, 2026-12-03): copy the position under the cursor +* [x] Desktop (the Design canvas' Desktop, 2026-12-03): copy the position under the cursor to the clipboard (a key or the right-click menu) — today only the map's center copies, - from the status bar, so the way around it is to put the center on the point first + from the status bar, so the way around it is to put the center on the point first. Done: right + click / long press / Alt+click = what's here (the position, a click copies it; Route here, Add to + the trip, Save a point; the features' raw properties folded), C copies the position under the mouse * [x] Desktop: the scale back over the map, not in the status bar * [x] Night mode — topbar button cycles auto (sun below the horizon at the map center) / on / off. The map has its own night palette (`NightMap` in `public/js/map_themes.js`, switched live with setPaintProperty): dark blue-gray ground, roads a step lighter, muted ochre motorways, light-gray labels on dark halos; raster overlays dimmed, our own track/point colors kept ** [x] The rest of the UI is still one invert+dim filter — CSS color tokens and a real dark set instead @@ -329,8 +331,10 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho gain `type`, `street`, `exit` ** [x] The driving view decluttered: tilted to 3D (≥ 30°), route numbers and minor roads' / paths' names hidden; road labels 1.5× further apart, past z15 the same ground distance -** [ ] Turn-by-turn voice (`speechSynthesis`), the route ahead highlighted / the driven part - greyed +** [x] Turn-by-turn voice (`speechSynthesis`), the route ahead highlighted / the driven part + greyed. Voice: Valhalla's `verbal_transition_alert_instruction` ("In 400 meters, …", 25 s / ≥ 400 m + ahead) and `verbal_pre_transition_instruction` (7 s / ≥ 60 m ahead), English; on/off in drive + mode's Menu, off by default ** [x] Lanes as SVG arrows, one per direction bit, the lanes to take (Valhalla's `active`) blue with that direction bold *** [ ] Lane guidance before motorway exits (lanes several maneuvers ahead), bigger on the @@ -379,8 +383,8 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho *** [ ] Replay a library track (GPX/FIT with times) instead, at its own speed ** [x] Free look while following: moving the map by hand pauses the follow, "Back to the position" or 15 s untouched resumes it -* [ ] While following a planned route: the route ahead highlighted, distance to the next - maneuver from Valhalla's directions +* [x] While following a planned route: the route ahead highlighted, distance to the next + maneuver from Valhalla's directions (the banner; the driven part dashed) === Design: the park brochure and the cockpit diff --git a/lib/maptool/routing.rb b/lib/maptool/routing.rb index bb8942e..8787ec1 100644 --- a/lib/maptool/routing.rb +++ b/lib/maptool/routing.rb @@ -265,7 +265,8 @@ module Maptool def self.maneuver(m) { text: m["instruction"], km: m["length"], type: m["type"], street: (m["begin_street_names"] || m["street_names"])&.first, - exit: m["roundabout_exit_count"], lanes: m["lanes"] }.compact + exit: m["roundabout_exit_count"], lanes: m["lanes"], + alert: m["verbal_transition_alert_instruction"], say: m["verbal_pre_transition_instruction"] }.compact end private_class_method :maneuver diff --git a/public/css/style.css b/public/css/style.css index 6304181..fc76e7b 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1504,6 +1504,21 @@ button.basemap-panel__link[hidden] { display: none; } word-break: break-word; } +/* what's here (map.js): the position, what to do with it, the features folded */ +.here-popup .maplibregl-popup-content { padding: 0; max-height: 420px; } +.here button { font: inherit; color: inherit; cursor: pointer; } +.here__position { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 28px 10px 12px; border: none; border-bottom: 1px solid var(--ui-line); background: none; text-align: left; } +.here__position > span { flex: 1; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; } +.here__position b { font-size: 15px; } +.here__position small, .here__position em { color: var(--ui-muted); font-style: normal; font-size: 12px; } +.here__actions { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--ui-line); } +.here__actions button { flex: 1; height: 30px; padding: 0 6px; border: 1px solid var(--ui-line); border-radius: 6px; background: none; font-weight: 600; font-size: 12px; white-space: nowrap; } +.here__actions button:hover { background: var(--ui-hover, rgba(0, 0, 0, 0.06)); } +.here__features { padding: 8px 12px 0; } +.here__features summary { font-weight: 600; cursor: pointer; } +.here__features .debug-popup__feature:first-of-type { margin-top: 6px; } +.here__hint { padding: 6px 12px 8px; font-size: 11px; color: var(--ui-muted); } + .maplibregl-ctrl-overview-map { border-radius: 4px; overflow: hidden; diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 6a02b61..64ab4eb 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -39,6 +39,12 @@ const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close const DEFAULT_WIDGETS = { inclinometer: true, speed: true, altitude: true, navigation: true, banner: true }; const THEN_M = 300; // the maneuver after the next one shown with it when it follows this closely +// Voice prompts (speechSynthesis, Valhalla's verbal instructions), on/off in +// drive mode's Menu: "In 400 m, turn right…" from SOON_S ahead, the +// instruction itself NOW_S before the maneuver (at least the metres given). +export const VOICE_KEY = "maptool.voice"; +const SOON_S = 25, SOON_M = 400; +const NOW_S = 7, NOW_M = 60; const DEFAULT_OPACITY = 0.45; // the card's background, the map shows through const load = () => { @@ -187,7 +193,9 @@ export class DashboardControl { this._lastAt = 0; this._offFixes = 0; this._sentKm = undefined; // the new route drawn by the next fix + this._said = new Set(); })); + this._said = new Set(); // voice prompts given: "maneuver index:soon|now" this._trace = []; // [lon, lat] fixes TRACE_STEP_M apart, for /api/road this._road = null; // its last answer this._roadAt = 0; @@ -228,6 +236,21 @@ export class DashboardControl { notifyRouteProgress(km); } + _speak(index, maneuver, m, speed) { + let voiceOn = false; + try { voiceOn = localStorage.getItem(VOICE_KEY) === "on"; } catch { /* private window */ } + if (!voiceOn || !window.speechSynthesis) return; + const now = Math.max(NOW_M, speed * NOW_S); + let stage = null, text = null; + if (m <= now) [stage, text] = ["now", maneuver.say]; + else if (m <= Math.max(SOON_M, speed * SOON_S) && m > 2 * now && maneuver.alert) { + [stage, text] = ["soon", `In ${distance(m).replace(" m", " meters").replace(" km", " kilometers")}, ${maneuver.alert[0].toLowerCase()}${maneuver.alert.slice(1)}`]; + } + if (!text || this._said.has(`${index}:${stage}`)) return; + this._said.add(`${index}:soon`).add(`${index}:${stage}`); + speechSynthesis.speak(new SpeechSynthesisUtterance(text)); + } + // The limit and what's ahead: from the route while on it, else the road. _navigate() { const { lat, lon, speed } = this._values; @@ -261,6 +284,7 @@ export class DashboardControl { then: maneuver && then && then.at - maneuver.at <= THEN_M / 1000 ? then : null, street: onStreet, }; + if (maneuver && off <= ON_ROUTE_M) this._speak(index, maneuver, (maneuver.at - at) * 1000, speed ?? 0); return; } this._progress(null); diff --git a/public/js/driving.js b/public/js/driving.js index 83c8a59..1926708 100644 --- a/public/js/driving.js +++ b/public/js/driving.js @@ -3,7 +3,7 @@ import { requestGnssFollow, onRouteChanged } from "/js/panels.js"; import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js"; import { formatDuration } from "/js/route.js"; import { isLoggedIn } from "/js/auth.js"; -import { watchDashboard, maneuverSvg, distance } from "/js/dashboard.js"; +import { watchDashboard, maneuverSvg, distance, VOICE_KEY } from "/js/dashboard.js"; import { formatSunInfo } from "/js/sun.js"; import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js"; @@ -104,6 +104,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) { + `; // 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" }; @@ -117,6 +118,15 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) { renderAuto(); }); renderAuto(); + const voiceButton = menuPanel.querySelector('[data-action="voice"]'); + const voiceOn = () => { try { return localStorage.getItem(VOICE_KEY) === "on"; } catch { return false; } }; + const renderVoice = () => { voiceButton.innerHTML = `Voice prompts: ${voiceOn() ? "on" : "off"} tap to switch`; }; + voiceButton.addEventListener("click", () => { + try { localStorage.setItem(VOICE_KEY, voiceOn() ? "off" : "on"); } catch { /* private window: not kept */ } + if (voiceOn()) window.speechSynthesis?.speak(new SpeechSynthesisUtterance("Voice prompts on")); + renderVoice(); + }); + renderVoice(); menuPanel.querySelector('[data-action="overview"]').addEventListener("click", overview); menuPanel.querySelector('[data-action="leave"]').addEventListener("click", () => set(false)); const crosshair = document.createElement("div"); diff --git a/public/js/map.js b/public/js/map.js index f62b505..7dbed48 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -20,7 +20,7 @@ import { RoutePanelControl } from "/js/route.js"; import { WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON, LOCK_ICON, UNLOCK_ICON } from "/js/icons.js"; import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js"; import { getPosition } from "/vendor/suncalc/suncalc.js"; -import { setupSidePanelModes } from "/js/panels.js"; +import { addRoutePoint, setupSidePanelModes } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { DebugControl } from "/js/debug.js"; import { setupUpdate } from "/js/update.js"; @@ -285,7 +285,8 @@ map.addControl(new MeasureControl(), "top-right"); // button that can only ever end in a 401 for a logged-out viewer, same // "hide the write-only affordance" story as GpxPanelControl's own // upload/new-folder buttons. -if (isLoggedIn()) map.addControl(new NotesControl(), "top-right"); +let notesControl = null; // what's here's "Save a point" (below) +if (isLoggedIn()) map.addControl((notesControl = new NotesControl()), "top-right"); map.addControl(new HomeButton({ bounds: SLOVAKIA_BOUNDS }), "top-right"); // ...as the artboard's three cards: zoom; the view (compass, north lock, 3D, // my position); the tools (measure, note, home). Each control keeps its own @@ -581,36 +582,71 @@ Promise.allSettled(ready).then(() => { else map.once("idle", restore); }); -// Alt+click, right click or a long press (touch browsers fire -// contextmenu for it) anywhere shows every rendered feature at that point — base map -// (OSM tags via OpenFreeMap/protomaps), GPX/FIT layers, radar, all of it — -// with its raw properties, inspired by NPMap4's infoboxControl (a generic -// "show me everything here" debug view, kept separate from the curated -// popups those same features already have via their own layer-specific -// click handlers, e.g. gpx.js's waypoint popups — both can fire on the same -// click, which is fine, this is a power-user/debugging affordance, not -// something replacing the normal popups). No dedicated UI for this -// deliberately — a keyboard-modified click needs no button, state, or -// cursor change of its own. -const inspect = (event) => { +// Right click, a long press (touch browsers fire contextmenu for it) or +// Alt+click: what's here (the Design canvas' Desktop). The position on top, +// a click copies it; Route here / Add to the trip / Save a point; every +// rendered feature's raw properties folded under it (the debug view it +// was). C copies the position under the mouse with no popup. +const copyPosition = async ({ lng, lat }) => { + try { + await navigator.clipboard.writeText(`${lat.toFixed(6)}, ${lng.toFixed(6)}`); + return true; + } catch { + return false; // clipboard API unavailable (an insecure context) + } +}; +const whatsHere = (event) => { + const { lngLat } = event; const features = map.queryRenderedFeatures(event.point); - if (features.length === 0) return; - - const html = features + const rows = features .map((feature) => { - const rows = Object.entries(feature.properties) + const cells = Object.entries(feature.properties) .map(([key, value]) => `${escapeHtml(key)}${escapeHtml(String(value))}`) .join(""); - return `
${escapeHtml(feature.layer.id)}${rows || ""}
(no properties)
`; + return `
${escapeHtml(feature.layer.id)}${cells || ""}
(no properties)
`; }) .join(""); - - new Popup({ maxWidth: "320px", className: "debug-popup" }).setLngLat(event.lngLat).setHTML(html).addTo(map); + const el = document.createElement("div"); + el.className = "here"; + el.innerHTML = ` + +
+ + + ${notesControl ? `` : ""} +
+
${features.length} feature${features.length === 1 ? "" : "s"} here${rows}
+
C copies the position under the cursor
`; + const popup = new Popup({ maxWidth: "320px", className: "debug-popup here-popup" }).setLngLat(lngLat).setDOMContent(el).addTo(map); + elevationAt(lngLat.lng, lngLat.lat, terrainOffline) + .then((metres) => metres != null && (el.querySelector(".here__alt").textContent = ` · ${Math.round(metres)} m`)) + .catch(() => {}); + el.querySelector(".here__position").addEventListener("click", async () => { + if (await copyPosition(lngLat)) el.querySelector(".here__position em").textContent = "Copied ✓"; + }); + const at = [lngLat.lng, lngLat.lat]; + const actions = { route: () => addRoutePoint(at, null), trip: () => routePanel.addStop(at), note: () => notesControl.placeAt(lngLat) }; + el.querySelector(".here__actions").addEventListener("click", (e) => { + const action = actions[e.target.dataset?.do]; + if (!action) return; + popup.remove(); + action(); + }); }; -map.on("click", (event) => event.originalEvent.altKey && inspect(event)); +map.on("click", (event) => event.originalEvent.altKey && whatsHere(event)); map.on("contextmenu", (event) => { event.originalEvent.preventDefault(); - inspect(event); + whatsHere(event); +}); +let mouseAt = null; +map.on("mousemove", ({ lngLat }) => (mouseAt = lngLat)); +map.getCanvasContainer().addEventListener("mouseleave", () => (mouseAt = null)); +document.addEventListener("keydown", async (e) => { + if (e.key !== "c" || !mouseAt || e.ctrlKey || e.altKey || e.metaKey || e.target.closest("input, textarea, select, [contenteditable]")) return; + if (await copyPosition(mouseAt)) cursorLabel.textContent = "Copied ✓"; }); // Feature properties can come straight from an uploaded GPX/FIT file (an diff --git a/public/js/notes.js b/public/js/notes.js index 77833dd..9f671dd 100644 --- a/public/js/notes.js +++ b/public/js/notes.js @@ -342,6 +342,14 @@ export class NotesControl { return this._container; } + // "Save a point" from what's here (map.js): the note's form at that spot. + placeAt(lngLat) { + if (!this._active) this._setActive(true); + this._form.close(); + this._removeMarker(); + this._onClick({ lngLat }); + } + _removeMarker() { this._marker?.remove(); this._marker = null; diff --git a/test/test_routing.rb b/test/test_routing.rb index beea75a..5edffef 100644 --- a/test/test_routing.rb +++ b/test/test_routing.rb @@ -126,12 +126,12 @@ class RoutingTest < Minitest::Test def test_route_picks_the_costing_by_weight_and_returns_a_line shape = "wdg|xA{ubdQc@w@" reply = JSON.generate(trip: { summary: { length: 1.5, time: 90 }, - legs: [{ shape: shape, summary: { length: 1.5, time: 90 }, maneuvers: [{ instruction: "Drive north.", length: 1.5, type: 2, street_names: ["Main"] }] }] }) + legs: [{ shape: shape, summary: { length: 1.5, time: 90 }, maneuvers: [{ instruction: "Drive north.", length: 1.5, type: 2, street_names: ["Main"], verbal_pre_transition_instruction: "Drive north on Main." }] }] }) # The per-country lookup failing (400) leaves the route as it is. request = serve_once("HTTP/1.1 200 OK\r\nContent-Length: #{reply.bytesize}\r\n\r\n#{reply}", "HTTP/1.1 400 Bad Request\r\nContent-Length: 2\r\n\r\n{}") do |url| route = Maptool::Routing.route(url, [[9.52, 47.14], [9.53, 47.15]], Maptool::Routing::DEFAULT_VEHICLES[1]) assert_equal [2, "auto", "Drive north."], [route[:geometry][:coordinates].size, route[:properties][:costing], route[:properties][:maneuvers][0][:text]] - assert_equal({ text: "Drive north.", km: 1.5, type: 2, street: "Main" }, route[:properties][:maneuvers][0]) + assert_equal({ text: "Drive north.", km: 1.5, type: 2, street: "Main", say: "Drive north on Main." }, route[:properties][:maneuvers][0]) assert_equal [[1.5], [90]], route[:properties].values_at(:legs_km, :legs_s) # each leg's km and time, for the stops end assert_includes request, %("costing_options":{"auto":{"height":3.0,"width":2.3}})