From 9148c9a4118ecdf41d3c6b81abd79b979886d9c1 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Mon, 23 Nov 2026 15:03:58 +0100 Subject: [PATCH] Night mode (auto after sunset / on / off, one invert+dim filter for now), tracker drawn as a top-down vehicle rotated by its GNSS course with a heading-up tilted Navigate mode, side panels float over the map on phone width instead of squeezing it --- TODO.adoc | 5 ++- public/css/style.css | 68 ++++++++++++++++++++++++++++ public/js/live.js | 104 ++++++++++++++++++++++++++++++++++++------- public/js/map.js | 28 ++++++++++++ views/index.erb | 1 + 5 files changed, 189 insertions(+), 17 deletions(-) diff --git a/TODO.adoc b/TODO.adoc index 0bf9407..5974cb7 100644 --- a/TODO.adoc +++ b/TODO.adoc @@ -90,7 +90,10 @@ plan from — the server does the heavy lifting. The UI is built for a mouse tod ** [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) -* [ ] Side panels as an overlay/bottom sheet in portrait instead of a pinned column +* [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] Night mode — topbar button cycles auto (sun below the horizon at the map center) / on / off; for now one invert+dim filter over the whole page, a real dark map palette later if the inverted colors don't hold up +* [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 diff --git a/public/css/style.css b/public/css/style.css index 782babc..fe76658 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -552,6 +552,30 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr left: calc(52px + min(300px, 90vw)); } +/* Phone portrait: a pinned 300px panel left the map a sliver, so there it + always floats over the map instead (closed by its × button). */ +@media (max-width: 640px) { + body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) #map { + margin-left: 0; + } + + body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .profile-panel { + left: 52px; + } + + /* body: outranks .gpx-panel's own rule further down */ + body .basemap-panel, + body .gpx-panel { + width: auto; + right: 0; + max-width: none; + } + + .side-panel-pin { + display: none; + } +} + .side-panel-pin { margin-left: auto; margin-right: 4px; @@ -3092,3 +3116,47 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr font-weight: normal; text-align: left; } + +/* Big enough to hit while driving. */ +.live-tracker-card__nav { + display: block; + width: 100%; + min-height: 44px; + margin-top: 6px; + border: none; + border-radius: 6px; + background: var(--accent); + color: #fff; + font: inherit; + font-size: 15px; + font-weight: 600; + cursor: pointer; +} + +.live-tracker-card__nav.active { + background: #c0392b; +} + +/* Night mode (map.js): the whole page inverted and dimmed, map included, + the already-black topbar and photos inverted back. + ponytail: one filter instead of a dark map style + dark copy of this + stylesheet; colors come out approximate (hue kept, lightness flipped) — + a real dark Park Tiles palette in map_themes.js if that's not enough. */ +html.night { + filter: invert(1) hue-rotate(180deg) brightness(0.75); + background: #fff; +} + +html.night .topbar, +html.night img { + filter: invert(1) hue-rotate(180deg); +} + +.topbar__night { + border: none; + background: none; + color: #bbb; + font-size: 16px; + padding: 4px 6px; + cursor: pointer; +} diff --git a/public/js/live.js b/public/js/live.js index 685c448..d0dc343 100644 --- a/public/js/live.js +++ b/public/js/live.js @@ -104,7 +104,25 @@ const poller = { const TRACKER_SOURCE = "live-tracker"; const TRAIL_SOURCE = "live-tracker-trail"; -const TRACKER_LAYERS = ["live-tracker-trail", "live-tracker-badge", "live-tracker-icon", "live-tracker-label"]; +const TRACKER_LAYERS = ["live-tracker-trail", "live-tracker-badge", "live-tracker-icon", "live-tracker-vehicle", "live-tracker-label"]; +// Below this speed the GNSS course is noise: the vehicle keeps its last one. +const MOVING_KMH = 3; +const NAV_PITCH = 60; +const NAV_ZOOM = 16; + +// Top-down shapes pointing north, rotated on the map by the course (like +// OpenTrafficMap's vehicles): picked from the tracker's icon. +const VEHICLE_SHAPES = { + car: ``, + moto: ``, + bike: ``, +}; + +function vehicleShape(icon) { + if (/moto/.test(icon)) return "moto"; + if (/bicycle|cycl|vtt|bike/.test(icon)) return "bike"; + return "car"; +} export class TrackerControl { constructor(map) { @@ -150,6 +168,7 @@ export class TrackerControl { this._status.addEventListener("click", (event) => { if (event.target.closest(".live-panel__show")) this._showTracker(); + if (event.target.closest(".live-panel__follow")) this._setFollow(true); }); if (!isLoggedIn()) { this._toggle.disabled = true; @@ -202,6 +221,7 @@ export class TrackerControl { } _disable() { + this._setFollow(false); this._enabled = false; poller.unsubscribe(this._onData); this._status.hidden = true; @@ -210,6 +230,28 @@ export class TrackerControl { removeLayers(this._map, TRACKER_LAYERS, [TRACKER_SOURCE, TRAIL_SOURCE]); } + // Navigation mode: the map follows the tracker heading-up, tilted, with + // the vehicle in the lower third so more road ahead shows. + _setFollow(on) { + if (!this._follow === !on) return; + this._follow = on; + this._renderCard(); + const t = this._data?.tracker; + if (on && t) this._navigate(t); + if (!on) this._map.easeTo({ padding: { top: 0, bottom: 0, left: 0, right: 0 }, duration: 300 }); + } + + _navigate(t) { + this._map.easeTo({ + center: [t.longitude, t.latitude], + bearing: this._course ?? this._map.getBearing(), + pitch: NAV_PITCH, + zoom: Math.max(this._map.getZoom(), NAV_ZOOM), + padding: { top: this._map.getContainer().clientHeight * 0.4, bottom: 0, left: 0, right: 0 }, + duration: Math.min(POLL_INTERVAL_MS, 1000), + }); + } + _showTracker() { const t = this._data?.tracker; if (t) this._map.flyTo({ center: [t.longitude, t.latitude], zoom: Math.max(this._map.getZoom(), 14) }); @@ -227,18 +269,36 @@ export class TrackerControl { layout: { "line-cap": "round", "line-join": "round" }, paint: { "line-color": ["get", "color"], "line-width": 3, "line-opacity": 0.75 }, }); + // Badge + glyph until a course is known, then the rotated vehicle. + const still = ["!", ["has", "course"]]; this._map.addLayer({ id: "live-tracker-badge", type: "symbol", source: TRACKER_SOURCE, + filter: still, layout: { "icon-image": ["get", "badge"], "icon-size": 0.7, "icon-allow-overlap": true }, }); this._map.addLayer({ id: "live-tracker-icon", type: "symbol", source: TRACKER_SOURCE, + filter: still, layout: { "icon-image": ["get", "glyph"], "icon-size": 0.4, "icon-allow-overlap": true }, }); + this._map.addLayer({ + id: "live-tracker-vehicle", + type: "symbol", + source: TRACKER_SOURCE, + filter: ["has", "course"], + layout: { + "icon-image": ["get", "vehicle"], + "icon-size": 0.9, + "icon-rotate": ["get", "course"], + "icon-rotation-alignment": "map", + "icon-pitch-alignment": "map", + "icon-allow-overlap": true, + }, + }); this._map.addLayer({ id: "live-tracker-label", type: "symbol", @@ -248,9 +308,13 @@ export class TrackerControl { }); if (!this._interactive) { this._interactive = true; - this._map.on("click", "live-tracker-badge", (event) => this._popup(event.lngLat)); - this._map.on("mouseenter", "live-tracker-badge", () => (this._map.getCanvas().style.cursor = "pointer")); - this._map.on("mouseleave", "live-tracker-badge", () => (this._map.getCanvas().style.cursor = "")); + for (const layer of ["live-tracker-badge", "live-tracker-vehicle"]) { + this._map.on("click", layer, (event) => this._popup(event.lngLat)); + this._map.on("mouseenter", layer, () => (this._map.getCanvas().style.cursor = "pointer")); + this._map.on("mouseleave", layer, () => (this._map.getCanvas().style.cursor = "")); + } + // Panning by hand ends navigation mode (zoom/pinch keeps it). + this._map.on("dragstart", () => this._setFollow(false)); } } @@ -268,7 +332,13 @@ export class TrackerControl { const image = await svgToImageData(svg.replace(/currentColor/g, "#fff"), ICON_IMAGE_SIZE); if (!this._map.hasImage(glyph)) this._map.addImage(glyph, image); } - return { badge, glyph }; + const shape = vehicleShape(icon); + const vehicle = `live-vehicle-${shape}-${color}`; + if (!this._map.hasImage(vehicle)) { + const image = await svgToImageData(VEHICLE_SHAPES[shape].replace(/currentColor/g, color), ICON_IMAGE_SIZE); + if (!this._map.hasImage(vehicle)) this._map.addImage(vehicle, image); + } + return { badge, glyph, vehicle }; } async _render(data) { @@ -286,22 +356,20 @@ export class TrackerControl { } const t = data.tracker; this._status.innerHTML = t - ? `${escapeHtml(settings.name)} ${ago(t.age)} · ` + ? `${escapeHtml(settings.name)} ${ago(t.age)} · · ` : `No ${escapeHtml(settings.name)} position yet`; + if (t?.course != null && (t.speed ?? MOVING_KMH) >= MOVING_KMH) this._course = t.course; this._renderCard(); if (!t) return; - const { badge, glyph } = await this._ensureImages(settings.color, settings.icon); + const { badge, glyph, vehicle } = await this._ensureImages(settings.color, settings.icon); + const properties = { badge, glyph, vehicle, label: `${settings.name} · ${ago(t.age)}` }; + if (this._course != null) properties.course = this._course; this._map.getSource(TRACKER_SOURCE)?.setData({ type: "FeatureCollection", - features: [ - { - type: "Feature", - geometry: { type: "Point", coordinates: [t.longitude, t.latitude] }, - properties: { badge, glyph, label: `${settings.name} · ${ago(t.age)}` }, - }, - ], + features: [{ type: "Feature", geometry: { type: "Point", coordinates: [t.longitude, t.latitude] }, properties }], }); + if (this._follow) this._navigate(t); const trail = [...(t.trail || []), [t.longitude, t.latitude]]; this._map.getSource(TRAIL_SOURCE)?.setData({ type: "FeatureCollection", @@ -337,7 +405,10 @@ export class TrackerControl { if (!this._card) { this._card = document.createElement("div"); this._card.className = "live-tracker-card"; - this._card.addEventListener("click", () => this._showTracker()); + this._card.addEventListener("click", (event) => { + if (event.target.closest(".live-tracker-card__nav")) this._setFollow(!this._follow); + else this._showTracker(); + }); this._map.getContainer().appendChild(this._card); } this._card.style.opacity = this._cardOpacity.value; @@ -352,7 +423,8 @@ export class TrackerControl { ["Updated", ago(t.age)], ].filter(Boolean); this._card.innerHTML = `
${POI_ICONS[s.icon] || NPS_SYMBOLS.automobiles}${escapeHtml(s.name)}
- ${rows.map(([k, v]) => ``).join("")}
${k}${escapeHtml(v)}
`; + ${rows.map(([k, v]) => ``).join("")}
${k}${escapeHtml(v)}
+ `; } _popup(lngLat) { diff --git a/public/js/map.js b/public/js/map.js index c6295ac..32ec965 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -19,6 +19,7 @@ import { OfflineDataControl } from "/js/offline_data.js"; import { RoutePanelControl } from "/js/route.js"; import { LAYERS_ICON, 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 { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { DebugControl } from "/js/debug.js"; @@ -465,6 +466,33 @@ 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"] }; +const nightButton = document.querySelector(".topbar__night"); +let nightMode = "auto"; +try { + nightMode = localStorage.getItem("nightMode") || "auto"; +} catch {} +const updateNight = () => { + const { lng, lat } = map.getCenter(); + const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0); + document.documentElement.classList.toggle("night", dark); + [nightButton.textContent, nightButton.title] = NIGHT_MODES[nightMode] || NIGHT_MODES.auto; +}; +nightButton.addEventListener("click", () => { + const modes = Object.keys(NIGHT_MODES); + nightMode = modes[(modes.indexOf(nightMode) + 1) % modes.length]; + try { + localStorage.setItem("nightMode", nightMode); + } catch {} + updateNight(); +}); +updateNight(); +map.on("moveend", updateNight); +setInterval(updateNight, 60000); + const sidebar = document.getElementById("sidebar"); // Grouped into the TODO's planned 4-module menu (Explorer / Offline hub / diff --git a/views/index.erb b/views/index.erb index 29ce812..e270192 100644 --- a/views/index.erb +++ b/views/index.erb @@ -7,6 +7,7 @@ +
<% if logged_in %> <%= user %>