Navigation: arrived 30 m from the end (banner, drive mode), navigating on past it (the reroute turns back); the next maneuver's lanes from 1 km or 45 s at the speed driven, in drive mode a cell under the maneuver over the map ("ahead" in the profile, shown only with something in it) with the next traffic signal; signals with no route: /api/road also routes 1.5 km straight on from the last fix and gives that way's signals, the nearest one in front shown. TODO: the CAN GNSS follow done (the LTE tracker a layer to switch on), any tracker point followable later
CI / check (push) Successful in 1m22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 17:57:27 +01:00
1 parent ad975bcf62
commit a6158f4083
7 files changed
+110 -15

No files matched your search

+31 -6
View File
@@ -36,7 +36,10 @@ const MAX_HDOP = 5; // ~ over 10 m off at the NEO-6M's few m UERE
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 LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close (or LANES_AHEAD_S at the speed driven)
const LANES_AHEAD_S = 45;
const ARRIVE_M = 30; // this close to the end: arrived (navigation goes on: past it, the route turns back)
const ARRIVE_TYPES = [4, 5, 6]; // Valhalla's destination maneuvers
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
@@ -86,7 +89,7 @@ const LANE_ANGLES = { 2: 0, 16: -45, 8: -90, 4: -135, 32: 45, 64: 90, 128: 135,
const LANE_REVERSE = 256;
// One lane as an SVG: an arrow per direction it allows; `active` (the
// directions to take, a bitmask too) drawn bold.
function laneSvg({ directions, active = 0 }) {
export function laneSvg({ directions, active = 0 }) {
const arrow = (bit) => {
const cls = `dash-lane__arrow${active & bit ? " dash-lane__take" : ""}`;
return bit === LANE_REVERSE ? uturnPath(cls) : arrowPath(LANE_ANGLES[bit], cls);
@@ -236,6 +239,21 @@ export class DashboardControl {
notifyRouteProgress(km);
}
// With no route: the nearest of /api/road's signals ahead that's still in
// front (within 90° of the heading), straight-line metres.
_signalAhead(position) {
const heading = this._heading()?.deg;
if (heading == null || !this._road?.signals?.length) return null;
const ahead = this._road.signals
.map(([lon, lat]) => {
const dx = (lon - position[0]) * Math.cos(position[1] * RAD), dy = lat - position[1];
const off = Math.abs((((Math.atan2(dx, dy) / RAD - heading) % 360) + 540) % 360 - 180);
return off < 90 ? meters(position, [lon, lat]) : null;
})
.filter((m) => m != null);
return ahead.length ? Math.min(...ahead) : null;
}
_speak(index, maneuver, m, speed) {
let voiceOn = false;
try { voiceOn = localStorage.getItem(VOICE_KEY) === "on"; } catch { /* private window */ }
@@ -283,12 +301,14 @@ export class DashboardControl {
maneuver: maneuver && { ...maneuver, m: (maneuver.at - at) * 1000 },
then: maneuver && then && then.at - maneuver.at <= THEN_M / 1000 ? then : null,
street: onStreet,
arrived: ARRIVE_TYPES.includes(maneuvers.at(-1)?.type) && (!maneuver || (index === maneuvers.length - 1 && (maneuver.at - at) * 1000 <= ARRIVE_M)),
lanesM: Math.max(LANES_AHEAD_M, (speed ?? 0) * LANES_AHEAD_S),
};
if (maneuver && off <= ON_ROUTE_M) this._speak(index, maneuver, (maneuver.at - at) * 1000, speed ?? 0);
return;
}
this._progress(null);
this._nav = { limit: this._road?.speed_limit ?? null, offRoute: !!this._route, street: this._road?.name };
this._nav = { limit: this._road?.speed_limit ?? null, offRoute: !!this._route, street: this._road?.name, signal: this._signalAhead(position) };
if (this._route && (speed ?? 0) >= MOVING_MS && Date.now() - this._rerouteAt >= REROUTE_EVERY_MS) {
this._rerouteAt = Date.now();
requestReroute(position, this._route.viaKm.filter((km) => km <= this._lastAt).length);
@@ -502,7 +522,7 @@ export class DashboardControl {
if (n?.maneuver && !this._settings.widgets.banner) {
const { text, m, lanes } = n.maneuver;
rows.push(`<div class="dash-maneuver">${distance(m)} · ${esc(text)}</div>`);
if (lanes && m <= LANES_AHEAD_M) {
if (lanes && m <= (n.lanesM ?? LANES_AHEAD_M)) {
rows.push(`<div class="dash-lanes">${lanes.map(laneSvg).join("")}</div>`);
}
}
@@ -514,14 +534,19 @@ export class DashboardControl {
// closely, its lanes from LANES_AHEAD_M, and the street being driven.
_renderBanner() {
const n = this._nav;
const show = this._settings.widgets.banner && !!n?.maneuver;
const show = this._settings.widgets.banner && !!(n?.maneuver || n?.arrived);
this._banner.hidden = !show;
if (!show) return;
this._banner.style.setProperty("--dash-alpha", Math.max(0.8, this._settings.opacity ?? DEFAULT_OPACITY));
if (n.arrived) {
this._banner.innerHTML = `<div class="dash-banner__main">${maneuverSvg(4)}<div><div class="dash-banner__distance">Arrived</div>` +
`<div class="dash-banner__street">${esc(n.street || "")}</div></div></div>`;
return;
}
const { m, type, street, text, exit, lanes } = n.maneuver;
const what = street ? `${exit ? `${exit}. exit · ` : ""}${esc(street)}` : esc(text);
const then = n.then ? `<div class="dash-banner__then">then ${maneuverSvg(n.then.type)} ${esc(n.then.street || n.then.text)}</div>` : "";
const lanesRow = lanes && m <= LANES_AHEAD_M ? `<div class="dash-lanes dash-banner__lanes">${lanes.map(laneSvg).join("")}</div>` : "";
const lanesRow = lanes && m <= (n.lanesM ?? LANES_AHEAD_M) ? `<div class="dash-lanes dash-banner__lanes">${lanes.map(laneSvg).join("")}</div>` : "";
const onStreet = n.street ? `<div class="dash-banner__on">on ${esc(n.street)}</div>` : "";
this._banner.innerHTML = `<div class="dash-banner__main">${maneuverSvg(type)}<div><div class="dash-banner__distance">${distance(m)}</div>` +
`<div class="dash-banner__street">${what}</div></div></div>${lanesRow}${then}${onStreet}`;