Driving mode ("Drive": big buttons — follow, zoom, 2D/3D, night, route overview — the sidebar hidden); palettes instead of the inversion (the UI's greys onto --ui-*, MapLibre's controls too, night → Night, new ◑ Dusk); the navigated route magenta, the driven part dimmed; route progress only forward (locate near the last position first); rerouting on the server off its own GNSS (TripStore#follow), the browser's only without the shared trip; the overview map hidden while following in 3D; the topbar's items apart
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 01:44:54 +01:00
1 parent 12b4ac6725
commit 07a4d363ec
13 files changed
+520 -219

No files matched your search

+33 -6
View File
@@ -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();