Dashboard: altitude (gnss.alt, the terrain's while simulating), the car tilted by the terrain's slope while simulating; free look while following (the map moved by hand pauses the follow, "Back to the position" or 15 s resumes it); overlays and shown library files remembered per device (localStorage), back after a reload once the offline checks are in
CI / check (push) Successful in 24s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 00:15:08 +01:00
1 parent 8c999919b8
commit 12b4ac6725
9 files changed
+199 -19

No files matched your search

+40 -4
View File
@@ -1,5 +1,6 @@
import { isLoggedIn } from "/js/auth.js";
import { onRouteChanged, requestReroute, requestGnssFollow } from "/js/panels.js";
import { elevationAt } from "/js/dem.js";
// The car's dashboard over the map, off the CAN signals (GET /api/can,
// names from data/can.json): one inclinometer — compass ring around a rear
@@ -9,10 +10,15 @@ import { onRouteChanged, requestReroute, requestGnssFollow } from "/js/panels.js
// Heading: driving, the GNSS course (from consecutive fixes); standing
// still, the compass (imu.heading, once the node sends it) — else the
// last course stays, dimmed.
const SIGNALS = { pitch: "imu.pitch", roll: "imu.roll", heading: "imu.heading", speed: "gnss.speed", lat: "gnss.lat", lon: "gnss.lon", hdop: "gnss.hdop" };
const SIGNALS = { pitch: "imu.pitch", roll: "imu.roll", heading: "imu.heading", speed: "gnss.speed", alt: "gnss.alt", lat: "gnss.lat", lon: "gnss.lon", hdop: "gnss.hdop" };
const MOVING_MS = 1.5; // m/s: above this the GNSS course counts
const COURSE_MIN_M = 5; // fixes closer than this: too noisy for a course
const POLL_MS = 500;
// Simulated tilt: the terrain's slope along the course (pitch) and across
// it (roll), from the DEM 2·TILT_HALF_M apart — the terrain, not the road:
// a road cut into a hillside is flatter across than this reads.
const TILT_ZOOM = 12; // ~20–40 m pixels (offline terrain goes to 13)
const TILT_HALF_M = 15;
const STALE_S = 5; // older signal: shown as missing
const WARN = { roll: 20, pitch: 25 }; // ° — amber past these, red past 1.5×
const STORE_KEY = "maptool.dashboard";
@@ -31,7 +37,7 @@ const REROUTE_EVERY_MS = 15000;
const ROAD_EVERY_MS = 4000; // /api/road at most this often, only while moving
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, navigation: true, banner: true };
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
const DEFAULT_OPACITY = 0.45; // the card's background, the map shows through
@@ -164,6 +170,31 @@ export class DashboardControl {
this._rerouteAt = 0;
}
// What the simulation doesn't send, from the terrain at its position: the
// altitude, and pitch / roll in degrees (nose up and right side down
// positive, as the inclinometer draws them) — unless a node sends them.
async _simulateTerrain() {
const { lat, lon } = this._values;
if (lat == null) return;
this._offlineTerrain ??= fetch("/api/terrain-tiles").then((r) => r.json()).then((d) => d.available).catch(() => false);
const offline = await this._offlineTerrain;
const rad = Math.PI / 180;
const at = (bearing) => {
const dx = TILT_HALF_M * Math.sin(bearing * rad);
const dy = TILT_HALF_M * Math.cos(bearing * rad);
return elevationAt(lon + dx / (111320 * Math.cos(lat * rad)), lat + dy / 111320, offline, { zoom: TILT_ZOOM, smooth: true });
};
if (this._values.alt == null) {
this._values.alt = await elevationAt(lon, lat, offline, { zoom: TILT_ZOOM, smooth: true });
}
if (this._course == null || this._values.pitch != null || this._values.roll != null) return;
const [front, back, right, left] = await Promise.all([0, 180, 90, 270].map((b) => at(this._course + b)));
if ([front, back, right, left].includes(null)) return;
const deg = (rise) => Math.atan(rise / (2 * TILT_HALF_M)) / rad;
this._values.pitch = deg(front - back);
this._values.roll = deg(left - right);
}
// The limit and what's ahead: from the route while on it, else the road.
_navigate() {
const { lat, lon, speed } = this._values;
@@ -237,6 +268,7 @@ export class DashboardControl {
<div class="overlays-panel__details" hidden>
<label class="live-tracker__row"><input type="checkbox" data-widget="inclinometer"> Inclinometer &amp; compass</label>
<label class="live-tracker__row"><input type="checkbox" data-widget="speed"> Speed</label>
<label class="live-tracker__row"><input type="checkbox" data-widget="altitude"> Altitude</label>
<label class="live-tracker__row"><input type="checkbox" data-widget="navigation"> Speed limit &amp; ahead (route)</label>
<label class="live-tracker__row"><input type="checkbox" data-widget="banner"> Navigation banner (next turn)</label>
<label class="live-tracker__row">Background <input type="range" class="dash-opacity" min="0" max="1" step="0.05"></label>
@@ -307,7 +339,7 @@ export class DashboardControl {
this._card = document.createElement("div");
this._card.className = "dash-card";
this._card.style.setProperty("--dash-alpha", this._settings.opacity ?? DEFAULT_OPACITY);
this._card.innerHTML = `<div class="dash-nav"><div class="dash-limit"></div><div class="dash-ahead"></div></div>${INCLINOMETER}<div class="dash-speed"><span></span> km/h</div>`;
this._card.innerHTML = `<div class="dash-nav"><div class="dash-limit"></div><div class="dash-ahead"></div></div>${INCLINOMETER}<div class="dash-speed"><span></span> km/h</div><div class="dash-alt"><span></span> m</div>`;
this._map.getContainer().appendChild(this._card);
// the next turn across the top, as in a car navigation
this._banner = document.createElement("div");
@@ -341,6 +373,7 @@ export class DashboardControl {
return [key, s && now - s.at < STALE_S + 1 ? s.value : null];
}));
this._updateCourse(this._values);
if (this._simRunning) await this._simulateTerrain();
this._navigate();
this._status.textContent = this._simRunning ? "Simulated GNSS" : data.available ? "" : "CAN is off on this server";
this._status.hidden = !this._status.textContent;
@@ -363,7 +396,10 @@ export class DashboardControl {
speed.style.display = widgets.speed ? "" : "none";
const nav = this._card.querySelector(".dash-nav");
nav.style.display = widgets.navigation ? "" : "none";
this._card.hidden = !widgets.inclinometer && !widgets.speed && !widgets.navigation;
const alt = this._card.querySelector(".dash-alt");
alt.style.display = widgets.altitude ? "" : "none";
alt.querySelector("span").textContent = v.alt == null ? "—" : Math.round(v.alt);
this._card.hidden = !widgets.inclinometer && !widgets.speed && !widgets.altitude && !widgets.navigation;
this._renderNav(nav);
this._renderBanner();