From 07a4d363ec31de98a4e1aeccc010a8ae4e94d721 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Tue, 1 Dec 2026 01:44:54 +0100 Subject: [PATCH] =?UTF-8?q?Driving=20mode=20("Drive":=20big=20buttons=20?= =?UTF-8?q?=E2=80=94=20follow,=20zoom,=202D/3D,=20night,=20route=20overvie?= =?UTF-8?q?w=20=E2=80=94=20the=20sidebar=20hidden);=20palettes=20instead?= =?UTF-8?q?=20of=20the=20inversion=20(the=20UI's=20greys=20onto=20--ui-*,?= =?UTF-8?q?=20MapLibre's=20controls=20too,=20night=20=E2=86=92=20Night,=20?= =?UTF-8?q?new=20=E2=97=91=20Dusk);=20the=20navigated=20route=20magenta,?= =?UTF-8?q?=20the=20driven=20part=20dimmed;=20route=20progress=20only=20fo?= =?UTF-8?q?rward=20(locate=20near=20the=20last=20position=20first);=20rero?= =?UTF-8?q?uting=20on=20the=20server=20off=20its=20own=20GNSS=20(TripStore?= =?UTF-8?q?#follow),=20the=20browser's=20only=20without=20the=20shared=20t?= =?UTF-8?q?rip;=20the=20overview=20map=20hidden=20while=20following=20in?= =?UTF-8?q?=203D;=20the=20topbar's=20items=20apart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.adoc | 29 ++-- app.rb | 28 +-- docs/design.adoc | 13 +- lib/maptool/trip.rb | 61 +++++++ public/css/style.css | 378 ++++++++++++++++++++++------------------- public/js/dashboard.js | 39 ++++- public/js/driving.js | 74 ++++++++ public/js/gnss.js | 33 ++-- public/js/map.js | 21 ++- public/js/panels.js | 13 ++ public/js/route.js | 25 ++- test/test_trip.rb | 24 +++ views/importmap.erb | 1 + 13 files changed, 520 insertions(+), 219 deletions(-) create mode 100644 public/js/driving.js diff --git a/TODO.adoc b/TODO.adoc index e7555ff..10bfcac 100644 --- a/TODO.adoc +++ b/TODO.adoc @@ -92,9 +92,10 @@ plan from — the server does the heavy lifting. The UI is built for a mouse tod * [ ] 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] 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 -* [ ] 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 +* [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 +** [ ] Layer presets on the driving 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 -** [ ] The rest of the UI is still one invert+dim filter — CSS color tokens and a real dark set instead +** [x] The rest of the UI is still one invert+dim filter — CSS color tokens and a real dark set instead * [x] Tracker as a top-down vehicle (car / motorbike / bicycle from its icon) rotated by the GNSS course, kept while standing still; "Navigate" (tracker card or Overlays status) follows it heading-up, tilted 60°, vehicle in the lower third — panning by hand ends it == NPS parks & maps @@ -227,7 +228,10 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho the route panel routes from the position to the points not reached yet (via points passed by km along the route, `legs_km`), at most every 15 s and only moving *** [ ] Step advance like Ferrostar's DistanceEntryExit (30 m to the step's end, 5 m past it) - instead of "the first maneuver ahead by km"; arrival at 30 m + instead of "the first maneuver ahead by km"; arrival at 30 m. Done: progress only forward — + the position looked for near the last one first (`locate`, 0.1 km back to 3 km ahead), so a + route along the same road twice or crossing itself doesn't jump; the step still advances 5 m + past the maneuver. Arrival still to do ** [x] The navigation banner across the top (Dashboard widget, on by default): the next maneuver's arrow (Valhalla's maneuver type), distance and street, "then …" when the next one follows within 300 m, its lanes from 1 km, the street being driven; `/api/route` maneuvers @@ -244,7 +248,7 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho PBF), and only for the direction driven (`traffic_signals:direction`) ** [ ] The "Navigate" follow mode for the CAN GNSS position (today the MQTT tracker and the browser's GNSS control), the dashboard as part of the driving-mode UI -** [ ] `locate()` scans the whole route each fix — a window around the last hit on long routes +** [x] `locate()` scans the whole route each fix — a window around the last hit on long routes ** [ ] Shared trip — one itinerary per server for every screen (the cab's display, the tablet or display in the back, phones): the co-driver adds a stop, the driver's view reroutes on the fly without losing the map (no stop / reload / start like Android Auto between two phones) @@ -253,8 +257,10 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho unchanged), `PUT /api/trip` routes it on the server (not again when only names/nav changed). Logged in, the route panel edits it and polls it every 2 s — other screens' changes swapped in, the camera untouched, the old route shown until the new one is in -*** [ ] Rerouting on the server: it has the GNSS (CAN), so off-route detection and the new - route once for all screens, not per screen with a dashboard (today's, `dashboard.js`) +*** [x] Rerouting on the server: it has the GNSS (CAN), so off-route detection and the new + route once for all screens, not per screen with a dashboard. Done: `TripStore#follow` on + every fix (3 fixes > 30 m off while moving, at most every 15 s), the browser's own reroute + only without the shared trip *** [ ] An itinerary view: stops by day/night, notes, planned arrival times (Valhalla's leg times), "Add to the trip" from search, the library, park4night and other sources *** [ ] Brick ↔ the car: a trip planned at home on brick handed to the car's server (with @@ -288,8 +294,9 @@ Planning in the NPS look, driving in the cockpit look, joined by the Unigrid bla . [x] Colors: tokens on `:root` (`--band`, `--inst-*`: ok / caution / warning, magenta = what navigation follows, cyan = set by hand); the dashboard in them — a see-through black bezel, light values, inverted back in night mode -. [ ] The route line magenta while it's navigated (follow mode), blue while planning; the next - waypoint and maneuver magenta on the map too +. [x] The route line magenta while it's navigated (follow mode), blue while planning; the next + waypoint and maneuver magenta on the map too. Done for the line (the driven part dimmed, + while the dashboard is on the route); the waypoint / maneuver marks still to do . [ ] The rest of the hard-coded colors → tokens (route, warnings, panel states), one place to tune . [ ] Panel headers as the Unigrid band: black, white title in National Park (headings weight to vendor), the same band as the topbar @@ -300,9 +307,11 @@ Planning in the NPS look, driving in the cockpit look, joined by the Unigrid bla `--inst-warning` fault) . [x] Palettes after IHO S-52: the same tokens in Day / Dusk / Night (`data-palette` on ``), night dim with low blue and no white areas, the speed limit sign dimmed too -. [ ] Switch them: by the sun (the night mode's auto) and by hand (the topbar button cycles +. [x] Switch them: by the sun (the night mode's auto) and by hand (the topbar button cycles day / dusk / night / auto), replacing the inverting `html.night`; the planning UI's - hard-coded colors onto `--ui-*` first, or a dark palette leaves light panels + hard-coded colors onto `--ui-*` first, or a dark palette leaves light panels. Done: the + greys onto `--ui-*` by role, MapLibre's controls/popups too; night mode sets Night, the new + "◑" mode Dusk (the day map) . [ ] A Dusk map (between Park Tiles and `NightMap`), the map's palette following the UI's . [ ] Daylight: a full-opacity bezel preset for sun on the screen diff --git a/app.rb b/app.rb index 00b462f..e8f0aea 100644 --- a/app.rb +++ b/app.rb @@ -395,21 +395,29 @@ module Maptool # the fix COURSE_MIN_M back when the receiver sends none — following # heading-up from behind (followPosition, gnss.js) turns by it. def self.gnss_update(gnss, at: Time.now.to_f) - GNSS_LATEST_MUTEX.synchronize do + fix = GNSS_LATEST_MUTEX.synchronize do GNSS_LATEST.merge!(gnss) next unless gnss.key?(:lat) || gnss.key?(:lon) GNSS_LATEST[:received_at] = at - next if gnss.key?(:track) - - position = GNSS_LATEST.values_at(:lon, :lat) - from = GNSS_LATEST[:course_from] - if from.nil? || (GNSS_LATEST[:speed] || 0) < COURSE_MIN_SPEED - GNSS_LATEST[:course_from] = position - elsif GnssSim.meters(from, position) >= COURSE_MIN_M - GNSS_LATEST[:track] = GnssSim.bearing(from, position).round(1) - GNSS_LATEST[:course_from] = position + unless gnss.key?(:track) + position = GNSS_LATEST.values_at(:lon, :lat) + from = GNSS_LATEST[:course_from] + if from.nil? || (GNSS_LATEST[:speed] || 0) < COURSE_MIN_SPEED + GNSS_LATEST[:course_from] = position + elsif GnssSim.meters(from, position) >= COURSE_MIN_M + GNSS_LATEST[:track] = GnssSim.bearing(from, position).round(1) + GNSS_LATEST[:course_from] = position + end end + GNSS_LATEST.dup + end + return unless fix && fix[:lat] && fix[:lon] + + # off the shared trip's route: routed again from here (TripStore#follow) + + TRIP_STORE.follow([fix[:lon], fix[:lat]], speed: fix[:speed], hdop: fix[:hdop]) do |locations, vehicle, avoid| + Routing.route(VALHALLA_URL, locations, Routing.vehicle(DATA_DIR, vehicle), avoid.transform_keys(&:to_s)) end end diff --git a/docs/design.adoc b/docs/design.adoc index 509132a..5bf9709 100644 --- a/docs/design.adoc +++ b/docs/design.adoc @@ -86,10 +86,15 @@ Our night values are roughly a third of Day's luminance, warm greys, blue kept low; no white areas (the speed limit sign dims too). The map has its own night palette (`NightMap`, `map_themes.js`); a Dusk map is still to do. -Today the page's night mode inverts the whole UI (`html.night`, the -instruments inverted back). The palettes replace that: set the -`data-palette`, by the sun (already worked out for the night mode) or by -hand. +The night mode sets the palette (`map.js`): automatic by the sun or on → +Night (with the night map), "◑" → Dusk over the day map, off → Day. The +planning UI's greys are the `--ui-*` tokens (`--ui-bg`, `--ui-bg-2` for +hover and fills, `--ui-line`, `--ui-fg`, `--ui-muted`); MapLibre's own +controls and popups take them too. + +The driving mode (`driving.js`, "Drive" in the topbar) is the cockpit's +input side: big band-black buttons down the map's left — follow, zoom, +2D/3D, night, the route overview — and the planning sidebar hidden. == Typography diff --git a/lib/maptool/trip.rb b/lib/maptool/trip.rb index c645c5b..e1635bd 100644 --- a/lib/maptool/trip.rb +++ b/lib/maptool/trip.rb @@ -25,6 +25,67 @@ module Maptool @mutex.synchronize { @trip.dup } end + ON_ROUTE_M = 30 # as the dashboard's + OFF_ROUTE_FIXES = 3 + MAX_HDOP = 5 + MIN_SPEED = 1.5 # m/s: standing next to the route isn't a detour + REROUTE_EVERY_S = 15 + + # Every GNSS fix (App.gnss_update): off the trip's route for + # OFF_ROUTE_FIXES fixes while driving, routes again from here to the + # points not reached yet — on the server, so it happens with no screen + # open; the screens pick the new version up by polling. The block routes + # (as #update's). In a thread of its own: CAN's reader doesn't wait. + def follow(position, speed:, hdop: nil, now: Time.now.to_f, &router) + trip = get + route = trip[:route] + return unless route && trip[:points].size >= 2 + + at, off = self.class.locate(route[:geometry][:coordinates], position) + if off <= ON_ROUTE_M + @off_fixes = 0 + @last_at = at + return + end + return if (hdop || 0) > MAX_HDOP + + @off_fixes = (@off_fixes || 0) + 1 + return if @off_fixes < OFF_ROUTE_FIXES || speed.to_f < MIN_SPEED || (@reroute_at && now - @reroute_at < REROUTE_EVERY_S) || @rerouting + + @reroute_at = now + @rerouting = true + leg = 0 + passed = (route[:properties][:legs_km] || [])[0...-1].map { |km| leg += km }.count { |km| km <= (@last_at || 0) } + points = [{ lngLat: position, name: "My position", nav: false }] + trip[:points].drop(1 + passed) + Thread.new do + update(points: points, vehicle: trip[:vehicle], avoid: trip[:avoid], editing: trip[:editing], &router) + rescue StandardError => e + warn "trip reroute: #{e.message}" + ensure + @rerouting = false + @off_fixes = 0 + end + end + + # Nearest point on the line ([[lon, lat], ...]): [km along it, meters off it]. + def self.locate(coords, (lon, lat)) + cos = Math.cos(lat * Math::PI / 180) + along = 0.0 + best = [0.0, Float::INFINITY] + coords.each_cons(2) do |(ax, ay), (bx, by)| + ax *= cos + bx *= cos + px = lon * cos + len2 = (bx - ax)**2 + (by - ay)**2 + t = len2.zero? ? 0.0 : (((px - ax) * (bx - ax) + (lat - ay) * (by - ay)) / len2).clamp(0.0, 1.0) + off = Math.hypot(px - (ax + t * (bx - ax)), lat - (ay + t * (by - ay))) * 111_320 + length = Math.sqrt(len2) * 111.32 + best = [along + t * length, off] if off < best[1] + along += length + end + best + end + # points: [{ lngLat: [lon, lat], name:, nav: }]. Routes through them with # the block (locations, vehicle id, avoid → the /api/route Feature, may # raise Routing errors) unless only names/nav changed — the old route diff --git a/public/css/style.css b/public/css/style.css index 96a9959..5a1932d 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -8,6 +8,7 @@ :root { /* planning UI (NPS) */ --ui-bg: #ffffff; + --ui-bg-2: #f0f0f0; /* hover, subtle fills */ --ui-fg: #1a1a1a; --ui-muted: #6b6b66; --ui-line: #d9d6cc; @@ -38,6 +39,7 @@ :root[data-palette="dusk"] { --ui-bg: #1f201d; + --ui-bg-2: #2a2b27; /* hover, subtle fills */ --ui-fg: #dedbd0; --ui-muted: #9b988d; --ui-line: #3a3a35; @@ -64,6 +66,7 @@ generate more light than the chart display itself"). */ :root[data-palette="night"] { --ui-bg: #0c0c0b; + --ui-bg-2: #161614; /* hover, subtle fills */ --ui-fg: #8f8b80; --ui-muted: #5f5c55; --ui-line: #24231f; @@ -86,24 +89,21 @@ --sign-fg: #0c0c0b; } -/* The page's night mode (html.night) inverts the whole UI and inverts the - dashboard back — so only the instruments and signs take the night values - there; the UI's own colors stay Day's for the inversion to darken. Goes - once the palettes replace the inversion. */ -html.night { - --inst-bezel: 0 0 0; - --inst-halo: #000000; - --inst-text: #a29d90; - --inst-muted: #5f5c55; - --inst-ok: #2a8a33; - --inst-caution: #a87400; - --inst-warning: #ad2a20; - --inst-active: #94339f; - --inst-selected: #137a8c; - --sign-bg: #6b675e; - --sign-ring: #8a231b; - --sign-fg: #0c0c0b; -} +/* The palette follows the night mode (map.js sets data-palette); the + MapLibre controls and popups (its own CSS is white) take it too. */ +body { background: var(--ui-bg); color: var(--ui-fg); } +.maplibregl-ctrl-group, .maplibregl-popup-content, .maplibregl-ctrl-attrib { background: var(--ui-bg); color: var(--ui-fg); } +.maplibregl-ctrl-group button + button { border-top-color: var(--ui-line); } +.maplibregl-ctrl-group button { color: var(--ui-fg); } +.maplibregl-ctrl-scale { background-color: rgb(from var(--ui-bg) r g b / 0.75); color: var(--ui-fg); border-color: var(--ui-fg); } +.maplibregl-ctrl-attrib.maplibregl-compact, .maplibregl-ctrl-attrib-button { background-color: var(--ui-bg); } +.maplibregl-ctrl-attrib a { color: var(--ui-fg); } +.maplibregl-ctrl-group button:not(:disabled):hover { background-color: var(--ui-bg-2); } +.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--ui-bg); } +.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--ui-bg); } +.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--ui-bg); } +.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--ui-bg); } +:root[data-palette] .maplibregl-ctrl-icon { filter: invert(0.75); } html, body { height: 100%; @@ -133,6 +133,7 @@ html, body { flex: 0 0 auto; display: flex; align-items: center; + gap: 16px; /* the status dot, Drive, the night mode, the login: apart, to hit by touch */ height: 44px; padding: 0 16px; background: var(--band); @@ -357,7 +358,7 @@ html, body { } .sun-chart__fields dt { - color: #999; + color: var(--ui-muted); } .sun-chart__fields dd { @@ -438,8 +439,8 @@ html, body { align-items: center; gap: 4px; padding: 8px 0; - background: #fff; - border-right: 1px solid #ddd; + background: var(--ui-bg); + border-right: 1px solid var(--ui-line); /* No overflow-y:auto here: setting only one axis to a clipping value forces the browser to compute the other axis as "auto" too (CSS Overflow spec), which would clip the flyouts — they intentionally @@ -475,7 +476,7 @@ html, body { border: none; border-radius: 6px; background: none; - color: #444; + color: var(--ui-fg); cursor: pointer; } @@ -485,7 +486,7 @@ html, body { } .sidebar-icon:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .sidebar-icon.active { @@ -499,8 +500,8 @@ html, body { left: 44px; z-index: 20; min-width: max-content; - background: #fff; - border: 1px solid #ddd; + background: var(--ui-bg); + border: 1px solid var(--ui-line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 6px; @@ -526,7 +527,7 @@ html, body { } .sidebar-flyout__option:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .sidebar-flyout__option.active { @@ -566,7 +567,7 @@ html, body { .radar-control__forecast { margin-top: 6px; padding-top: 6px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); } .radar-control__forecast-hours { @@ -575,7 +576,7 @@ html, body { overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; - border-bottom: 1px solid #eee; + border-bottom: 1px solid var(--ui-line); } .radar-control__forecast-hour { @@ -588,7 +589,7 @@ html, body { } .radar-control__forecast-hour span:first-child { - color: #888; + color: var(--ui-muted); font-size: 11px; } @@ -602,7 +603,7 @@ html, body { .radar-control__forecast-day span:first-child { width: 2.2em; - color: #888; + color: var(--ui-muted); } .radar-control__forecast-day span:nth-child(3) { @@ -612,7 +613,7 @@ html, body { .radar-control__forecast-stale { margin: 4px 0 0; - color: #888; + color: var(--ui-muted); font-size: 11px; } @@ -633,7 +634,7 @@ html, body { .shadow-control__hint { margin: 6px 0 0; - color: #888; + color: var(--ui-muted); font-size: 11px; } @@ -646,7 +647,7 @@ html, body { height: 100%; display: flex; flex-direction: column; - background: #fff; + background: var(--ui-bg); box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15); font-size: 13px; z-index: 10; @@ -697,13 +698,13 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr border: none; border-radius: 4px; background: none; - color: #898781; + color: var(--ui-muted); cursor: pointer; display: inline-flex; } .side-panel-pin:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .side-panel-pin.active { @@ -715,7 +716,7 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr align-items: center; justify-content: space-between; padding: 10px 12px; - border-bottom: 1px solid #eee; + border-bottom: 1px solid var(--ui-line); } .basemap-panel__close { @@ -760,7 +761,7 @@ button.basemap-panel__link[hidden] { display: none; } } .basemap-panel__option:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .basemap-panel__option.active { @@ -792,8 +793,8 @@ button.basemap-panel__link[hidden] { display: none; } bottom: 0; width: 300px; max-width: 90vw; - background: #fff; - border-left: 1px solid #ddd; + background: var(--ui-bg); + border-left: 1px solid var(--ui-line); box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15); z-index: 10; } @@ -833,7 +834,7 @@ button.basemap-panel__link[hidden] { display: none; } max-width: none; max-height: 50vh; border-left: none; - border-top: 1px solid #ddd; + border-top: 1px solid var(--ui-line); border-radius: 8px 8px 0 0; box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15); } @@ -881,7 +882,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__region-list { max-height: 50vh; overflow-y: auto; - border: 1px solid #eee; + border: 1px solid var(--ui-line); border-radius: 4px; } @@ -898,7 +899,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__continent > summary { font-weight: 600; background: #f7f7f7; - border-bottom: 1px solid #eee; + border-bottom: 1px solid var(--ui-line); } .offline-data-panel__count { @@ -908,7 +909,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__subregions { margin-left: 26px; - border-left: 2px solid #eee; + border-left: 2px solid var(--ui-line); } /* Second-level, so smaller than the 44 px rows (and more specific than @@ -916,7 +917,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__region-list .offline-data-panel__subregions > summary { min-height: 32px; padding: 8px 8px; - color: #666; + color: var(--ui-muted); font-size: 12px; } @@ -944,7 +945,7 @@ button.basemap-panel__link[hidden] { display: none; } } .offline-data-panel__region-list label:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .offline-data-panel__cache-info { @@ -952,7 +953,7 @@ button.basemap-panel__link[hidden] { display: none; } align-items: center; gap: 4px; padding-right: 8px; - color: #888; + color: var(--ui-muted); font-size: 11px; white-space: nowrap; } @@ -989,15 +990,15 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__region-status { padding: 6px 8px; - color: #888; + color: var(--ui-muted); } .offline-data-panel__apply { margin-top: 8px; width: 100%; - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); padding: 6px 8px; font: inherit; font-size: 12px; @@ -1005,7 +1006,7 @@ button.basemap-panel__link[hidden] { display: none; } } .offline-data-panel__apply:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .offline-data-panel__apply:disabled { @@ -1016,7 +1017,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__row { margin-top: 14px; padding-top: 10px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); } .offline-data-panel__row-head { @@ -1027,9 +1028,9 @@ button.basemap-panel__link[hidden] { display: none; } } .offline-data-panel__delete { - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); padding: 2px 8px; font: inherit; font-size: 11px; @@ -1048,7 +1049,7 @@ button.basemap-panel__link[hidden] { display: none; } .offline-data-panel__status { margin: 6px 0 0; - color: #666; + color: var(--ui-muted); font-size: 12px; } @@ -1073,7 +1074,7 @@ button.basemap-panel__link[hidden] { display: none; } height: 100%; display: flex; flex-direction: column; - background: #fff; + background: var(--ui-bg); box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15); font-size: 13px; z-index: 10; @@ -1088,7 +1089,7 @@ button.basemap-panel__link[hidden] { display: none; } align-items: center; justify-content: space-between; padding: 10px 12px; - border-bottom: 1px solid #eee; + border-bottom: 1px solid var(--ui-line); } .gpx-panel__actions { @@ -1106,7 +1107,7 @@ button.basemap-panel__link[hidden] { display: none; } border: none; border-radius: 6px; background: none; - color: #444; + color: var(--ui-fg); cursor: pointer; } @@ -1124,7 +1125,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-panel__action:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .gpx-panel__close { @@ -1138,7 +1139,7 @@ button.basemap-panel__link[hidden] { display: none; } .gpx-upload__status { margin: 0 12px 10px; - color: #666; + color: var(--ui-muted); } .gpx-tree { @@ -1184,7 +1185,7 @@ button.basemap-panel__link[hidden] { display: none; } justify-content: center; width: 24px; height: 28px; - color: #888; + color: var(--ui-muted); font-size: 13px; transition: transform 0.15s; } @@ -1285,7 +1286,7 @@ button.basemap-panel__link[hidden] { display: none; } .gpx-tree__kind-icon { flex-shrink: 0; display: flex; - color: #999; + color: var(--ui-muted); } .gpx-tree__kind-icon svg { @@ -1304,7 +1305,7 @@ button.basemap-panel__link[hidden] { display: none; } display: flex; border: none; background: none; - color: #999; + color: var(--ui-muted); padding: 0 4px; cursor: pointer; } @@ -1315,7 +1316,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-tree__download:hover { - color: #333; + color: var(--ui-fg); } .gpx-tree__download-menu { @@ -1324,8 +1325,8 @@ button.basemap-panel__link[hidden] { display: none; } right: 0; z-index: 20; min-width: max-content; - background: #fff; - border: 1px solid #ddd; + background: var(--ui-bg); + border: 1px solid var(--ui-line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 4px; @@ -1353,14 +1354,14 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-tree__download-menu-item:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .gpx-tree__delete { flex-shrink: 0; border: none; background: none; - color: #999; + color: var(--ui-muted); font-size: 14px; line-height: 1; padding: 0 4px; @@ -1372,7 +1373,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-tree__empty { - color: #888; + color: var(--ui-muted); font-style: italic; } @@ -1407,12 +1408,12 @@ button.basemap-panel__link[hidden] { display: none; } font: inherit; text-align: left; cursor: pointer; - color: #1a1a1a; + color: var(--ui-fg); overflow: hidden; } .gpx-legend__item:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .gpx-legend__item--hidden { @@ -1430,7 +1431,7 @@ button.basemap-panel__link[hidden] { display: none; } width: 14px; height: 14px; flex-shrink: 0; - color: #1a1a1a; + color: var(--ui-fg); } .gpx-legend__icon svg { @@ -1472,7 +1473,7 @@ button.basemap-panel__link[hidden] { display: none; } .debug-popup__feature + .debug-popup__feature { margin-top: 8px; padding-top: 8px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); } .debug-popup__feature table { @@ -1482,7 +1483,7 @@ button.basemap-panel__link[hidden] { display: none; } .debug-popup__feature th { text-align: left; - color: #888; + color: var(--ui-muted); font-weight: normal; padding: 1px 6px 1px 0; vertical-align: top; @@ -1521,8 +1522,8 @@ button.basemap-panel__link[hidden] { display: none; } margin-left: 8px; z-index: 20; min-width: max-content; - background: #fff; - border: 1px solid #ddd; + background: var(--ui-bg); + border: 1px solid var(--ui-line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 6px 8px; @@ -1594,7 +1595,7 @@ button.basemap-panel__link[hidden] { display: none; } } .measure-panel__mode:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .measure-panel__mode.active { @@ -1604,7 +1605,7 @@ button.basemap-panel__link[hidden] { display: none; } .measure-panel__result { min-width: 4em; - color: #333; + color: var(--ui-fg); font-variant-numeric: tabular-nums; } @@ -1616,13 +1617,13 @@ button.basemap-panel__link[hidden] { display: none; } background: none; font-size: 16px; line-height: 1; - color: #888; + color: var(--ui-muted); cursor: pointer; padding: 0 2px; } .measure-panel__clear:hover { - color: #333; + color: var(--ui-fg); } .search-ctrl { @@ -1647,8 +1648,8 @@ button.basemap-panel__link[hidden] { display: none; } margin-left: 8px; z-index: 20; width: 240px; - background: #fff; - border: 1px solid #ddd; + background: var(--ui-bg); + border: 1px solid var(--ui-line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 6px 8px; @@ -1668,7 +1669,7 @@ button.basemap-panel__link[hidden] { display: none; } .search-panel__input { width: 100%; box-sizing: border-box; - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; padding: 5px 7px; font: inherit; @@ -1690,12 +1691,12 @@ button.basemap-panel__link[hidden] { display: none; } } .search-panel__result:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .search-panel__status { padding: 6px 4px; - color: #888; + color: var(--ui-muted); } .search-panel__sources { @@ -1704,7 +1705,7 @@ button.basemap-panel__link[hidden] { display: none; } gap: 2px 10px; margin-top: 6px; font-size: 12px; - color: #555; + color: var(--ui-fg); } /* Pulsing ring left on the map where a point search result landed. */ @@ -1732,7 +1733,7 @@ button.basemap-panel__link[hidden] { display: none; } .search-panel__where { display: block; font-size: 11px; - color: #888; + color: var(--ui-muted); overflow-wrap: anywhere; } @@ -1758,8 +1759,8 @@ button.basemap-panel__link[hidden] { display: none; } margin-left: 8px; z-index: 20; width: 200px; - background: #fff; - border: 1px solid #ddd; + background: var(--ui-bg); + border: 1px solid var(--ui-line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 8px; @@ -1783,7 +1784,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 4px 8px; border: none; border-radius: 4px; - background: #f0f0f0; + background: var(--ui-bg-2); font: inherit; font-size: 12px; cursor: pointer; @@ -1796,7 +1797,7 @@ button.basemap-panel__link[hidden] { display: none; } .notes-panel__hint { margin: 0 0 6px; - color: #888; + color: var(--ui-muted); } .notes-panel__finish { @@ -1834,7 +1835,7 @@ button.basemap-panel__link[hidden] { display: none; } font: inherit; font-size: 12px; padding: 4px 6px; - border: 1px solid #ddd; + border: 1px solid var(--ui-line); border-radius: 4px; } @@ -1877,7 +1878,7 @@ button.basemap-panel__link[hidden] { display: none; } border: 1px solid transparent; border-radius: 4px; background: none; - color: #555; + color: var(--ui-fg); cursor: pointer; } @@ -1887,7 +1888,7 @@ button.basemap-panel__link[hidden] { display: none; } } .notes-panel__icon-option:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .notes-panel__icon-option.active { @@ -1910,7 +1911,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 0; border: 2px solid #fff; border-radius: 50%; - background: var(--swatch, repeating-linear-gradient(45deg, #fff 0 3px, #ccc 3px 6px)); + background: var(--swatch, repeating-linear-gradient(45deg, var(--ui-bg) 0 3px, #ccc 3px 6px)); box-shadow: 0 0 0 1px #bbb; cursor: pointer; } @@ -1929,15 +1930,15 @@ button.basemap-panel__link[hidden] { display: none; } .notes-panel__format button { min-width: 32px; height: 28px; - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); font: inherit; cursor: pointer; } .notes-panel__format button:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } /* Moving a note: the marker takes the accent color, the hint + Save/Cancel @@ -1991,7 +1992,7 @@ button.basemap-panel__link[hidden] { display: none; } font: inherit; font-size: 12px; padding: 4px 6px; - border: 1px solid #ddd; + border: 1px solid var(--ui-line); border-radius: 4px; } @@ -2012,7 +2013,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 4px 10px; border: none; border-radius: 4px; - background: #f0f0f0; + background: var(--ui-bg-2); font: inherit; font-size: 12px; cursor: pointer; @@ -2035,7 +2036,7 @@ button.basemap-panel__link[hidden] { display: none; } justify-content: center; font-size: 12px; font-weight: 600; - color: #333; + color: var(--ui-fg); user-select: none; } @@ -2099,7 +2100,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-popup__time { - color: #888; + color: var(--ui-muted); font-size: 12px; } @@ -2109,7 +2110,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-popup__category { - color: #888; + color: var(--ui-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; @@ -2137,7 +2138,7 @@ button.basemap-panel__link[hidden] { display: none; } .gpx-popup__meta { margin-top: 8px; padding-top: 6px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); font-size: 12px; line-height: 1.5; } @@ -2147,7 +2148,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gpx-popup__meta-label { - color: #888; + color: var(--ui-muted); margin-right: 4px; } @@ -2168,7 +2169,7 @@ button.basemap-panel__link[hidden] { display: none; } display: flex; width: 13px; height: 13px; - color: #555; + color: var(--ui-fg); flex-shrink: 0; } @@ -2188,14 +2189,14 @@ button.basemap-panel__link[hidden] { display: none; } gap: 6px; margin-top: 8px; padding-top: 6px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); } .gpx-popup__note-actions button, .gpx-popup__edit-actions button { border: none; border-radius: 4px; - background: #f0f0f0; + background: var(--ui-bg-2); padding: 3px 8px; font: inherit; font-size: 12px; @@ -2214,7 +2215,7 @@ button.basemap-panel__link[hidden] { display: none; } font: inherit; font-size: 13px; padding: 4px 6px; - border: 1px solid #ddd; + border: 1px solid var(--ui-line); border-radius: 4px; margin-bottom: 6px; } @@ -2228,7 +2229,7 @@ button.basemap-panel__link[hidden] { display: none; } } .gnss-control__status { - color: #888; + color: var(--ui-muted); white-space: nowrap; } @@ -2259,7 +2260,7 @@ button.basemap-panel__link[hidden] { display: none; } } .overlays-panel__item label:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .overlays-panel__icon { @@ -2267,7 +2268,7 @@ button.basemap-panel__link[hidden] { display: none; } width: 16px; height: 16px; flex-shrink: 0; - color: #555; + color: var(--ui-fg); } .overlays-panel__icon svg { @@ -2280,7 +2281,7 @@ button.basemap-panel__link[hidden] { display: none; } margin: 10px 4px 2px; font-size: 11px; font-weight: 600; - color: #888; + color: var(--ui-muted); text-transform: uppercase; letter-spacing: 0.05em; } @@ -2313,7 +2314,7 @@ button.basemap-panel__link[hidden] { display: none; } .overlays-panel__details { margin: 0 4px 6px 26px; padding-top: 6px; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); font-size: 12px; } @@ -2329,7 +2330,7 @@ button.basemap-panel__link[hidden] { display: none; } .hiking-trail-kinds { margin-bottom: 8px; padding-bottom: 8px; - border-bottom: 1px solid #eee; + border-bottom: 1px solid var(--ui-line); } .hiking-trail-countries__item label { @@ -2348,7 +2349,7 @@ button.basemap-panel__link[hidden] { display: none; } } .livetrack-panel__item { - border-bottom: 1px solid #f0f0f0; + border-bottom: 1px solid var(--ui-line); } .livetrack-panel__row { @@ -2366,7 +2367,7 @@ button.basemap-panel__link[hidden] { display: none; } } .livetrack-panel__row:hover { - background: #f0f0f0; + background: var(--ui-bg-2); } .livetrack-panel__row.active { @@ -2400,7 +2401,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 2px 6px; border-radius: 3px; background: #e5e5e5; - color: #666; + color: var(--ui-muted); font-size: 10px; font-weight: 600; text-transform: uppercase; @@ -2414,7 +2415,7 @@ button.basemap-panel__link[hidden] { display: none; } .livetrack-panel__time { flex-shrink: 0; - color: #888; + color: var(--ui-muted); font-size: 12px; } @@ -2426,7 +2427,7 @@ button.basemap-panel__link[hidden] { display: none; } max-height: 45vh; display: flex; flex-direction: column; - background: #fcfcfb; + background: var(--ui-bg); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15); z-index: 10; } @@ -2464,7 +2465,7 @@ button.basemap-panel__link[hidden] { display: none; } line-height: 1; padding: 0 4px; cursor: pointer; - color: #898781; + color: var(--ui-muted); } .profile-panel__charts { @@ -2483,7 +2484,7 @@ button.basemap-panel__link[hidden] { display: none; } .profile-chart__label { font-size: 11px; - color: #898781; + color: var(--ui-muted); margin-bottom: 2px; } @@ -2515,7 +2516,7 @@ button.basemap-panel__link[hidden] { display: none; } .profile-chart__axis-value { position: absolute; left: 4px; - color: #898781; + color: var(--ui-muted); font-size: 10px; line-height: 1; background: rgba(252, 252, 251, 0.75); @@ -2539,7 +2540,7 @@ button.basemap-panel__link[hidden] { display: none; } gap: 4px 8px; margin-bottom: 4px; font-size: 11px; - color: #898781; + color: var(--ui-muted); } .profile-panel__controls-spacer { @@ -2568,7 +2569,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 0 3px; border: 1px solid #e1e0d9; border-radius: 3px; - background: #fcfcfb; + background: var(--ui-bg); color: #52514e; font-size: 10px; line-height: 13px; @@ -2582,7 +2583,7 @@ button.basemap-panel__link[hidden] { display: none; } .profile-panel__xaxis-toggle-btn { border: 1px solid #e1e0d9; - background: #fcfcfb; + background: var(--ui-bg); color: #52514e; font-size: 11px; padding: 2px 8px; @@ -2614,14 +2615,14 @@ button.basemap-panel__link[hidden] { display: none; } .profile-stats th { text-align: left; font-weight: 600; - color: #666; + color: var(--ui-muted); } .profile-chart__trails { display: block; width: 100%; height: 10px; - background: #eee; + background: var(--ui-bg-2); } .profile-panel__xaxis { @@ -2635,7 +2636,7 @@ button.basemap-panel__link[hidden] { display: none; } top: 0; transform: translateX(-50%); font-size: 10px; - color: #898781; + color: var(--ui-muted); white-space: nowrap; } @@ -2681,7 +2682,7 @@ button.basemap-panel__link[hidden] { display: none; } .plugins-panel__hint { margin: 0 0 6px; - color: #888; + color: var(--ui-muted); font-size: 11px; } @@ -2733,7 +2734,7 @@ button.basemap-panel__link[hidden] { display: none; } .plugins-panel__status { flex-basis: 100%; - color: #888; + color: var(--ui-muted); font-size: 11px; } @@ -2746,7 +2747,7 @@ button.basemap-panel__link[hidden] { display: none; } } .plugins-panel__empty { - color: #888; + color: var(--ui-muted); white-space: normal; max-width: 200px; } @@ -2760,11 +2761,11 @@ button.basemap-panel__link[hidden] { display: none; } .route-panel__hint, .route-panel__summary { margin: 0 0 8px; - color: #666; + color: var(--ui-muted); } .route-panel__summary { - color: #222; + color: var(--ui-fg); font-weight: 600; } @@ -2784,7 +2785,7 @@ button.basemap-panel__link[hidden] { display: none; } .route-panel__remove { border: none; background: none; - color: #999; + color: var(--ui-muted); font-size: 14px; cursor: pointer; } @@ -2812,9 +2813,9 @@ button.basemap-panel__link[hidden] { display: none; } } .route-panel__buttons button { - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); padding: 4px 8px; font: inherit; font-size: 12px; @@ -2884,7 +2885,7 @@ button.basemap-panel__link[hidden] { display: none; } display: grid; grid-template-columns: 1fr 1fr; gap: 6px; - border: 1px solid #eee; + border: 1px solid var(--ui-line); border-radius: 4px; } @@ -2931,7 +2932,7 @@ button.basemap-panel__link[hidden] { display: none; } .route-panel__vehicle-hint { margin: 0; font-size: 0.85em; - color: #666; + color: var(--ui-muted); } .route-marker { @@ -2975,9 +2976,9 @@ button.basemap-panel__link[hidden] { display: none; } .search-panel__route, .gpx-popup__route { - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); font: inherit; font-size: 12px; cursor: pointer; @@ -3014,9 +3015,9 @@ button.basemap-panel__link[hidden] { display: none; } .route-panel__profile, .route-panel__reach button, .route-panel__reach select { - border: 1px solid #ccc; + border: 1px solid var(--ui-line); border-radius: 4px; - background: #fff; + background: var(--ui-bg); padding: 3px 6px; font: inherit; font-size: 12px; @@ -3042,14 +3043,14 @@ button.basemap-panel__link[hidden] { display: none; } .route-panel__reach-status { margin: 0 0 8px; - color: #666; + color: var(--ui-muted); } /* Vehicle & ITS-G5 overlay (live.js): its status line and popup table. */ .live-panel__status { margin: 4px 0 0 26px; font-size: 12px; - color: #666; + color: var(--ui-muted); } .live-panel__show { @@ -3064,7 +3065,7 @@ button.basemap-panel__link[hidden] { display: none; } .live-popup th { padding-right: 8px; - color: #666; + color: var(--ui-muted); font-weight: normal; text-align: left; } @@ -3104,7 +3105,7 @@ button.basemap-panel__link[hidden] { display: none; } .nps-panel__results small, .nps-panel__none { - color: #888; + color: var(--ui-muted); } .nps-panel__shown { @@ -3142,7 +3143,7 @@ button.basemap-panel__link[hidden] { display: none; } .nps-popup li { padding: 4px 0; - border-top: 1px solid #eee; + border-top: 1px solid var(--ui-line); } .nps-popup__title { @@ -3166,7 +3167,7 @@ button.basemap-panel__link[hidden] { display: none; } padding: 2px 8px; border: 1px solid var(--accent); border-radius: 4px; - background: #fff; + background: var(--ui-bg); color: var(--accent); font: inherit; cursor: pointer; @@ -3225,7 +3226,7 @@ button.basemap-panel__link[hidden] { display: none; } min-width: 170px; padding: 8px 10px; border-radius: 8px; - background: #fff; + background: var(--ui-bg); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25); font-size: 12px; cursor: pointer; @@ -3257,7 +3258,7 @@ button.basemap-panel__link[hidden] { display: none; } .live-tracker-card th { padding-right: 10px; - color: #666; + color: var(--ui-muted); font-weight: normal; text-align: left; } @@ -3282,25 +3283,6 @@ button.basemap-panel__link[hidden] { display: none; } background: #c0392b; } -/* Night mode (map.js): the map gets its own night palette (NightMap in - map_themes.js), so its canvas and markers are inverted back here; the - rest of the UI is still the whole page inverted and dimmed, with the - already-black topbar and photos inverted back. - ponytail: the UI part is one filter, not a dark copy of this stylesheet; - colors come out approximate — CSS color tokens + a dark set later. */ -html.night { - filter: invert(1) hue-rotate(180deg) brightness(0.8); - background: #fff; -} - -html.night .topbar, -html.night .dash-card, -html.night img, -html.night #map canvas, -html.night .maplibregl-marker { - filter: invert(1) hue-rotate(180deg); -} - .topbar__night { min-width: 40px; height: 40px; @@ -3358,8 +3340,8 @@ html.night .maplibregl-marker { margin: 10px -12px 0; padding: 8px 16px 6px; background: #f3f3f1; - border-top: 1px solid #e2e2e2; - border-bottom: 1px solid #e2e2e2; + border-top: 1px solid var(--ui-line); + border-bottom: 1px solid var(--ui-line); } .overlays-panel__group:first-child { @@ -3395,7 +3377,7 @@ html.night .maplibregl-marker { display: inline-flex; align-items: center; justify-content: center; - color: #444; + color: var(--ui-fg); } .gpx-panel__action[hidden] { @@ -3526,3 +3508,55 @@ html.night .maplibregl-marker { box-shadow: 0 2px 8px rgb(0 0 0 / 0.35); cursor: pointer; } + +/* Driving mode (driving.js): big buttons down the map's left side, the + planning sidebar and its panels out of the way. */ +.topbar__drive { + height: 40px; + padding: 0 12px; + border: 1px solid #555; + border-radius: 6px; + background: none; + color: #ddd; + font-size: 15px; + font-weight: 600; + cursor: pointer; +} +.topbar__drive.active { background: var(--accent); border-color: var(--accent); color: #fff; } +html.driving #sidebar, +html.driving .basemap-panel, +html.driving .gpx-panel, +html.driving .trail-panel, +html.driving .profile-panel, +html.driving #map .maplibregl-ctrl-top-left { display: none; } +.drive-bar { + position: absolute; + left: 12px; + top: 50%; + transform: translateY(-50%); + z-index: 4; + display: flex; + flex-direction: column; + gap: 10px; + max-height: calc(100% - 24px); /* a low screen: the buttons shrink, to 44 px */ +} +.drive-bar[hidden] { display: none; } +.drive-bar button { + width: 76px; + flex: 0 1 64px; + min-height: 44px; + border: none; + border-radius: 12px; + background: var(--band); + color: var(--band-fg); + font-size: 22px; + font-weight: 700; + 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:disabled { opacity: 0.4; } +html.follow-3d .maplibregl-ctrl-overview-map { display: none; } +.drive-bar .drive-bar__night { font-size: 30px; } diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 0b51fa9..d174201 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -1,5 +1,5 @@ import { isLoggedIn } from "/js/auth.js"; -import { onRouteChanged, requestReroute, requestGnssFollow } from "/js/panels.js"; +import { onRouteChanged, requestReroute, requestGnssFollow, notifyRouteProgress } from "/js/panels.js"; import { elevationAt } from "/js/dem.js"; // The car's dashboard over the map, off the CAN signals (GET /api/can, @@ -102,13 +102,27 @@ function prepareRoute(route) { return { coords, km, limits: route.properties.speed_limits, signals: route.properties.signals || [], maneuvers, viaKm }; } -// Nearest point on the route: [km along it, meters off it]. -// ponytail: scans every segment each fix — a window around the last hit if long routes get slow. -function locate(route, position) { +// Nearest point on the route: [km along it, meters off it]. Near the last +// one first (fromKm: LOCATE_BACK_KM behind to LOCATE_AHEAD_KM ahead), so a +// route that comes back along the same road or crosses itself doesn't jump +// to the other pass — progress goes forward, as Ferrostar's does; the whole +// route only when that window has nothing close (a reroute, a restart). +const LOCATE_BACK_KM = 0.1; +const LOCATE_AHEAD_KM = 3; +function locate(route, position, fromKm = null) { + if (fromKm != null) { + const near = locateIn(route, position, fromKm - LOCATE_BACK_KM, fromKm + LOCATE_AHEAD_KM); + if (near[1] <= ON_ROUTE_M) return near; + } + return locateIn(route, position, -Infinity, Infinity); +} + +function locateIn(route, position, fromKm, toKm) { let best = [0, Infinity]; const { coords, km } = route; const cos = Math.cos(position[1] * RAD); for (let i = 1; i < coords.length; i++) { + if (km[i] < fromKm || km[i - 1] > toKm) continue; const [ax, ay] = [coords[i - 1][0] * cos, coords[i - 1][1]]; const [bx, by] = [coords[i][0] * cos, coords[i][1]]; const [px, py] = [position[0] * cos, position[1]]; @@ -161,6 +175,7 @@ export class DashboardControl { this._route = prepareRoute(route); this._lastAt = 0; this._offFixes = 0; + this._sentKm = undefined; // the new route drawn by the next fix })); this._trace = []; // [lon, lat] fixes TRACE_STEP_M apart, for /api/road this._road = null; // its last answer @@ -195,6 +210,13 @@ export class DashboardControl { this._values.roll = deg(left - right); } + // To the route panel (the driven part dimmed), when it moved ≥ 10 m. + _progress(km) { + if (km === this._sentKm || (km != null && this._sentKm != null && Math.abs(km - this._sentKm) < 0.01)) return; + this._sentKm = km; + notifyRouteProgress(km); + } + // The limit and what's ahead: from the route while on it, else the road. _navigate() { const { lat, lon, speed } = this._values; @@ -202,7 +224,7 @@ export class DashboardControl { const position = [lon, lat]; if (!this._trace.length || meters(this._trace.at(-1), position) >= TRACE_STEP_M) this._trace = [...this._trace.slice(-7), position]; - const [at, off] = this._route ? locate(this._route, position) : [0, Infinity]; + const [at, off] = this._route ? locate(this._route, position, this._lastAt || null) : [0, Infinity]; const fresh = position.join() !== this._lastFix; // polled faster than the fixes come this._lastFix = position.join(); if (fresh && this._route && off > ON_ROUTE_M && (this._values.hdop ?? 0) <= MAX_HDOP) this._offFixes++; @@ -216,7 +238,10 @@ export class DashboardControl { const maneuver = maneuvers[index]; const then = maneuvers[index + 1]; const onStreet = maneuvers[index - 1]?.street; // the one being driven: the last maneuver's - if (off <= ON_ROUTE_M) this._lastAt = at; + if (off <= ON_ROUTE_M) { + this._lastAt = at; + this._progress(at); + } this._nav = { limit: current?.[1] ?? null, next: next && { limit: next[1], m: (next[0] - at) * 1000 }, @@ -227,6 +252,7 @@ export class DashboardControl { }; return; } + this._progress(null); this._nav = { limit: this._road?.speed_limit ?? null, offRoute: !!this._route, street: this._road?.name }; if (this._route && (speed ?? 0) >= MOVING_MS && Date.now() - this._rerouteAt >= REROUTE_EVERY_MS) { this._rerouteAt = Date.now(); @@ -352,6 +378,7 @@ export class DashboardControl { } _disable() { + this._progress(null); clearTimeout(this._timer); this._timer = null; this._card?.remove(); diff --git a/public/js/driving.js b/public/js/driving.js new file mode 100644 index 0000000..781922b --- /dev/null +++ b/public/js/driving.js @@ -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"); +} diff --git a/public/js/gnss.js b/public/js/gnss.js index 578b054..c14e422 100644 --- a/public/js/gnss.js +++ b/public/js/gnss.js @@ -38,27 +38,40 @@ function freeLookState(map) { button.hidden = true; map.getContainer().appendChild(button); state = { until: 0, button, followedAt: 0 }; - button.addEventListener("click", () => { - state.until = 0; - button.hidden = true; - clearTimeout(state.timer); - }); + button.addEventListener("click", () => resumeFollow(map)); const touched = (e) => { // our own easeTo, or nothing being followed (GNSS off) - if (!e.originalEvent || Date.now() - state.followedAt > FOLLOWING_MS) return; - state.until = Date.now() + FREE_LOOK_MS; - button.hidden = false; - clearTimeout(state.timer); - state.timer = setTimeout(() => (button.hidden = true), FREE_LOOK_MS); + if (e.originalEvent && Date.now() - state.followedAt <= FOLLOWING_MS) pauseFollow(map); }; for (const type of ["dragstart", "zoomstart", "rotatestart", "pitchstart", "move"]) map.on(type, touched); freeLook.set(map, state); return state; } +// Also for a view the app moves to itself (the driving bar's route overview). +export function pauseFollow(map) { + const state = freeLookState(map); + state.until = Date.now() + FREE_LOOK_MS; + state.button.hidden = false; + clearTimeout(state.timer); + state.timer = setTimeout(() => (state.button.hidden = true), FREE_LOOK_MS); +} + +export function resumeFollow(map) { + const state = freeLookState(map); + state.until = 0; + state.button.hidden = true; + clearTimeout(state.timer); +} + export function followPosition(map, lngLat, heading, speed, duration) { const free = freeLookState(map); free.followedAt = Date.now(); + // following in 3D like a navigation: the overview map out of the way + // (style.css), back once the follow stops or the view goes 2D + document.documentElement.classList.toggle("follow-3d", map.getPitch() > 0); + clearTimeout(free.followTimer); + free.followTimer = setTimeout(() => document.documentElement.classList.remove("follow-3d"), FOLLOWING_MS); if (Date.now() < free.until) return; free.button.hidden = true; const pitched = map.getPitch() > 0; diff --git a/public/js/map.js b/public/js/map.js index 909548d..27b05c4 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -29,6 +29,7 @@ import { offerSharedFiles } from "/js/share_import.js"; import HomeButton from "/vendor/npmap-home-button/home-button.esm.js"; import OverviewMap from "/vendor/npmap-overview/overview.esm.js"; import * as maplibregl from "/vendor/maplibre-gl/maplibre-gl.mjs"; +import { setupDriving } from "/js/driving.js"; const CENTER = [17.1077, 48.1486]; const ZOOM = 13; @@ -467,10 +468,18 @@ updateSun(); map.on("moveend", updateSun); setInterval(updateSun, 60000); -// Night mode (html.night, style.css) so the screen doesn't glare in the -// car: "auto" follows the sun at the map center, or forced on/off — the -// topbar button cycles the three, remembered per device. -const NIGHT_MODES = { auto: ["◐", "Night mode: automatic (after sunset)"], on: ["☾", "Night mode: on"], off: ["☀", "Night mode: off"] }; +// Night mode so the screen doesn't glare in the car: "auto" follows the sun +// at the map center, or by hand — the topbar button cycles them, +// remembered per device. +// The UI's palette (style.css, after S-52: Day, Dusk, Night) and the map's +// night style: automatic by the sun, or by hand — Dusk the dark UI over the +// day map, "for optional use by day as well" (docs/design.adoc). +const NIGHT_MODES = { + auto: ["◐", "Night mode: automatic (after sunset)"], + on: ["☾", "Night mode: on"], + dusk: ["◑", "Dusk: the dark UI over the day map"], + off: ["☀", "Night mode: off"], +}; const nightButton = document.querySelector(".topbar__night"); const nightMap = new NightMap(map); // The base style's texture patterns (grass, scrub, military hatch) and the @@ -506,6 +515,9 @@ const updateNight = () => { const { lng, lat } = sunAt; const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0); document.documentElement.classList.toggle("night", dark); + const palette = dark ? "night" : nightMode === "dusk" ? "dusk" : null; + if (palette) document.documentElement.dataset.palette = palette; + else delete document.documentElement.dataset.palette; nightMap.set(dark); [nightButton.textContent, nightButton.title] = NIGHT_MODES[nightMode] || NIGHT_MODES.auto; }; @@ -520,6 +532,7 @@ nightButton.addEventListener("click", () => { updateNight(); map.on("moveend", updateNight); setInterval(updateNight, 60000); +setupDriving(map, nightButton); const sidebar = document.getElementById("sidebar"); diff --git a/public/js/panels.js b/public/js/panels.js index b562d2d..c2075c8 100644 --- a/public/js/panels.js +++ b/public/js/panels.js @@ -123,6 +123,19 @@ export function notifyRouteChanged(route) { document.dispatchEvent(new CustomEvent(ROUTE_CHANGED_EVENT, { detail: route })); } +// How far along the route the position is, while the dashboard follows it +// (km, or null once it's off it / not navigating): the route panel draws +// the driven part dimmed and the rest as the active route. +const ROUTE_PROGRESS_EVENT = "route-progress"; + +export function notifyRouteProgress(km) { + document.dispatchEvent(new CustomEvent(ROUTE_PROGRESS_EVENT, { detail: km })); +} + +export function onRouteProgress(callback) { + document.addEventListener(ROUTE_PROGRESS_EVENT, (event) => callback(event.detail)); +} + // Off the route while navigating: the route panel routes again from `from` // ([lon, lat]) to the points not yet reached (`passed` via points skipped). const REROUTE_EVENT = "route-reroute"; diff --git a/public/js/route.js b/public/js/route.js index 17060c1..206275b 100644 --- a/public/js/route.js +++ b/public/js/route.js @@ -1,6 +1,6 @@ import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs"; import { ROUTE_ICON, POSITION_ICON, SAVED_POINT_ICON, REVERSE_ICON, CLEAR_ICON, SAVE_ICON } from "/js/icons.js"; -import { notifySidePanelOpen, onlyOneSidePanelOpen, notifyGpxStoreChanged, onRoutePoint, onRouteEdit, notifyRouteChanged, onReroute } from "/js/panels.js"; +import { notifySidePanelOpen, onlyOneSidePanelOpen, notifyGpxStoreChanged, onRoutePoint, onRouteEdit, notifyRouteChanged, onReroute, onRouteProgress } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { wirePreview } from "/js/preview.js"; import { elevationAt } from "/js/dem.js"; @@ -52,12 +52,14 @@ export class RoutePanelControl { // Rerouting (the dashboard, off the route): the start and the via points // already passed give way to the current position. onReroute(({ from, passed }) => { - if (this._points.length < 2) return; + // the shared trip is rerouted by the server, off its own GNSS (TripStore#follow) + if (this._shared || this._points.length < 2) return; this._points.splice(0, 1 + passed).forEach((p) => p.marker.remove()); this._addPoint(from, "My position", { quiet: true }); this._points.unshift(this._points.pop()); this._changed(); }); + onRouteProgress((km) => this._showProgress(km)); onRoutePoint(({ lngLat, name }) => { this._setOpen(true); this._addPoint(lngLat, name); @@ -455,7 +457,7 @@ export class RoutePanelControl { source.setData(data); return; } - this._map.addSource(SOURCE, { type: "geojson", data }); + this._map.addSource(SOURCE, { type: "geojson", data, lineMetrics: true }); // line-progress for _showProgress this._map.addLayer({ id: `${SOURCE}-casing`, type: "line", @@ -480,6 +482,23 @@ export class RoutePanelControl { }); } + // Navigated (km along the route, docs/design.adoc): the driven part + // dimmed, the rest magenta (--route-active); null: the planned blue. + _showProgress(km) { + if (!this._map.getLayer(`${SOURCE}-line`)) return; + const total = this._route?.properties.distance_km; + if (km == null || !total) { + this._map.setPaintProperty(`${SOURCE}-line`, "line-gradient", undefined); + return; + } + const css = getComputedStyle(document.documentElement); + const active = css.getPropertyValue("--route-active").trim() || "#a21caf"; + const driven = css.getPropertyValue("--ui-muted").trim() || "#6b6b66"; + const fraction = Math.min(1, Math.max(0, km / total)); + this._map.setPaintProperty(`${SOURCE}-line`, "line-gradient", + fraction > 0 ? ["step", ["line-progress"], driven, fraction, active] : ["step", ["line-progress"], active, 1, active]); + } + // A route item in the library ("Routes" folder), keeping its points and // vehicle so it can be routed again later; an edited one is updated in // place. diff --git a/test/test_trip.rb b/test/test_trip.rb index 21572ba..d78c7c1 100644 --- a/test/test_trip.rb +++ b/test/test_trip.rb @@ -1,5 +1,6 @@ require_relative "test_helper" require "tmpdir" +require "timeout" require_relative "../lib/maptool/trip" class TripTest < Minitest::Test @@ -25,6 +26,29 @@ class TripTest < Minitest::Test end end + # Off the route while driving for 3 fixes: routed again from the position + # to the points not reached yet (the first via passed: dropped). + def test_following_reroutes_from_the_position_off_the_route + Dir.mktmpdir do |dir| + store = Maptool::TripStore.new(File.join(dir, "trip.json")) + line = { geometry: { coordinates: [[17.0, 48.0], [17.1, 48.0], [17.2, 48.0]] }, properties: { legs_km: [7.44, 7.44] } } + points = [{ lngLat: [17.0, 48.0] }, { lngLat: [17.1, 48.0] }, { lngLat: [17.2, 48.0] }] + calls = [] + router = ->(locations, _vehicle, _avoid) { calls << locations; line } + store.update(points: points, vehicle: nil, avoid: {}, editing: nil, &router) + calls.clear + + store.follow([17.15, 48.0], speed: 20, now: 0, &router) # on it, past the via + 3.times { |i| store.follow([17.15, 48.01], speed: 20, now: i + 1, &router) } # ~1.1 km off + Timeout.timeout(5) { sleep 0.05 until store.get[:version] == 2 } + assert_equal [[[17.15, 48.01], [17.2, 48.0]]], calls + assert_equal "My position", store.get[:points][0][:name] + + store.follow([17.15, 48.02], speed: 20, now: 5, &router) # within REROUTE_EVERY_S: nothing + assert_equal 1, calls.size + end + end + def test_a_routing_error_is_kept_with_the_points_and_tried_again_next_time Dir.mktmpdir do |dir| store = Maptool::TripStore.new(File.join(dir, "trip.json")) diff --git a/views/importmap.erb b/views/importmap.erb index 3e09e26..9d8e7ea 100644 --- a/views/importmap.erb +++ b/views/importmap.erb @@ -19,6 +19,7 @@ "/js/hiking_trails.js": "/js/hiking_trails.js?v=<%= ASSET_VERSION %>", "/js/live.js": "/js/live.js?v=<%= ASSET_VERSION %>", "/js/dashboard.js": "/js/dashboard.js?v=<%= ASSET_VERSION %>", + "/js/driving.js": "/js/driving.js?v=<%= ASSET_VERSION %>", "/js/update.js": "/js/update.js?v=<%= ASSET_VERSION %>", "/js/icons.js": "/js/icons.js?v=<%= ASSET_VERSION %>", "/js/livetrack.js": "/js/livetrack.js?v=<%= ASSET_VERSION %>",