Driving menu Trip: the stops as big rows (look, ✓ passed, ↑ ↓, ✕), a stop at the crosshair, the start at the car, search of saved points and offline places; each leg's km and time (legs_s) and the total, in the route panel too; passed stops kept (not routed, dimmed, editable) — a reroute marks them instead of dropping them; /status.html: every status endpoint full width (the debug panel links it); the trip-as-plan-and-log model and planned-vs-driven colors in docs/TODO
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 02:21:14 +01:00
1 parent 0eb9d05cdc
commit 809e88ab1a
14 files changed
+517 -101

No files matched your search

+108 -13
View File
@@ -53,13 +53,21 @@ export class RoutePanelControl {
// already passed give way to the current position.
onReroute(({ from, passed }) => {
// 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());
if (this._shared || this._active().length < 2) return;
const reached = this._active().slice(0, 1 + passed);
if (reached[0]?.name === "My position") this._removePoint(reached.shift(), { quiet: true });
reached.forEach((p) => this._setPassed(p, true));
this._addPoint(from, "My position", { quiet: true });
this._points.unshift(this._points.pop());
const position = this._points.pop();
const next = this._points.findIndex((p) => !p.passed);
this._points.splice(next < 0 ? this._points.length : next, 0, position);
this._changed();
});
onRouteProgress((km) => this._showProgress(km));
onRouteProgress((km) => {
this._showProgress(km);
this._progressKm = km;
this._stopListeners?.forEach((callback) => callback());
});
onRoutePoint(({ lngLat, name }) => {
this._setOpen(true);
this._addPoint(lngLat, name);
@@ -147,7 +155,7 @@ export class RoutePanelControl {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
points: this._points.map(({ lngLat, name, nav }) => ({ lngLat, name, nav })),
points: this._points.map(({ lngLat, name, nav, passed }) => ({ lngLat, name, nav, passed })),
vehicle: this._vehicleId,
avoid: this._avoid,
editing: this._editing,
@@ -171,7 +179,7 @@ export class RoutePanelControl {
if (fromElsewhere) {
this._points.forEach((p) => p.marker.remove());
this._points = [];
trip.points.forEach((p) => this._addPoint(p.lngLat, p.name, { quiet: true, nav: !!p.nav }));
trip.points.forEach((p) => this._addPoint(p.lngLat, p.name, { quiet: true, nav: !!p.nav, passed: !!p.passed }));
this._editing = trip.editing;
this._avoid = { ...trip.avoid };
this._panel.querySelectorAll(".route-panel__avoid input").forEach((input) => (input.checked = !!this._avoid[input.name]));
@@ -200,11 +208,12 @@ export class RoutePanelControl {
// A named place (a saved point, a search result) is shown in navigation
// by default; a plain map click only shapes the route.
_addPoint(lngLat, name, { quiet = false, nav = !!name && name !== "My position" } = {}) {
_addPoint(lngLat, name, { quiet = false, nav = !!name && name !== "My position", passed = false } = {}) {
const element = document.createElement("div");
element.className = "route-marker";
const marker = new Marker({ element, draggable: true }).setLngLat(lngLat).addTo(this._map);
const point = { lngLat, name, nav, marker };
this._setPassed(point, passed);
marker.on("dragend", () => {
const { lng, lat } = marker.getLngLat();
point.lngLat = [lng, lat];
@@ -249,10 +258,91 @@ export class RoutePanelControl {
this._changed();
}
_removePoint(point) {
// For the driving mode's Trip menu (driving.js): the stops, and editing
// them by index — the same points the panel edits, so the shared trip,
// routing and markers follow as from the panel.
// passed: marked (by a reroute or by hand) — not routed — or behind the
// car by the dashboard's progress along the route; both shown dimmed.
stops() {
return this._points.map((p, i) => ({ name: p.name, lngLat: p.lngLat, label: i === 0 ? "Start" : i === this._points.length - 1 ? "End" : `Via ${i}`,
leg: this._leg(i), passed: p.passed, behind: this._behind(i) }));
}
togglePassed(index) {
const point = this._points[index];
if (!point) return;
this._setPassed(point, !point.passed);
this._changed();
}
_setPassed(point, passed) {
point.passed = !!passed;
point.marker.getElement().classList.toggle("route-marker--passed", point.passed);
}
// The points routed: the ones not passed.
_active() {
return this._points.filter((p) => !p.passed);
}
// The way to point i from the routed one before: { km, s } of the route's
// leg, null for the first routed point, a passed one, or while the route
// doesn't match the points (routing).
_leg(i) {
const { legs_km: km, legs_s: s } = this._route?.properties || {};
const active = this._active();
const at = active.indexOf(this._points[i]);
if (at < 1 || !km || km.length !== active.length - 1) return null;
return { km: km[at - 1], s: s?.[at - 1] };
}
// Behind the car: the dashboard's km along the route past this point's.
_behind(i) {
if (this._progressKm == null || this._points[i]?.passed) return false;
const { legs_km: km } = this._route?.properties || {};
const active = this._active();
const at = active.indexOf(this._points[i]);
if (at < 0 || !km || km.length !== active.length - 1) return false;
return km.slice(0, at).reduce((sum, length) => sum + length, 0) <= this._progressKm + 0.03;
}
onStopsChanged(callback) {
(this._stopListeners ??= []).push(callback);
}
moveStop(index, step) {
if (this._points[index]) this._move(this._points[index], step);
}
removeStop(index) {
if (this._points[index]) this._removePoint(this._points[index]);
}
// A stop before the end (the trip goes on to where it was going), or the
// end itself while there's no route yet.
addStop(lngLat, name = null) {
this._addPoint(lngLat, name, { quiet: true });
if (this._points.length > 2) this._points.splice(this._points.length - 2, 0, this._points.pop());
this._changed();
}
// The start moved to where the car is (GNSS, else the browser's position).
startHere() {
const set = (lngLat) => {
if (this._points[0]?.name === "My position") this._removePoint(this._points[0]);
this._addPoint(lngLat, "My position", { quiet: true });
this._points.unshift(this._points.pop());
this._changed();
};
const fix = this._gnss?.getPosition();
if (fix) return set([fix.lng, fix.lat]);
navigator.geolocation.getCurrentPosition((p) => set([p.coords.longitude, p.coords.latitude]), () => window.alert("Could not determine your location."), { enableHighAccuracy: true });
}
_removePoint(point, { quiet = false } = {}) {
point.marker.remove();
this._points = this._points.filter((p) => p !== point);
this._changed();
if (!quiet) this._changed();
}
_clear() {
@@ -273,9 +363,12 @@ export class RoutePanelControl {
const label = index === 0 ? "Start" : index === this._points.length - 1 ? "End" : `Via ${index}`;
point.marker.getElement().textContent = index === 0 ? "S" : index === this._points.length - 1 ? "E" : String(index);
const li = document.createElement("li");
li.classList.toggle("route-panel__passed", !!point.passed || this._behind(index));
const text = document.createElement("span");
text.className = "route-panel__point";
text.textContent = `${label} · ${point.name || `${point.lngLat[1].toFixed(5)}, ${point.lngLat[0].toFixed(5)}`}`;
const leg = this._leg(index);
if (leg) text.append(Object.assign(document.createElement("small"), { className: "route-panel__leg", textContent: `+${leg.km.toFixed(1)} km${leg.s != null ? ` · ${formatDuration(leg.s)}` : ""}` }));
li.append(
text,
this._navButton(point, label),
@@ -288,6 +381,7 @@ export class RoutePanelControl {
text.addEventListener("click", () => this._map.easeTo({ center: point.lngLat, zoom: Math.max(this._map.getZoom(), 14) }));
this._list.appendChild(li);
});
this._stopListeners?.forEach((callback) => callback());
this._editingNote.hidden = !this._editing;
if (this._editing) this._editingNote.textContent = `Editing "${this._editing.name}"`;
this._saveButton.textContent = this._editing ? "Save changes" : "Save to library";
@@ -330,7 +424,7 @@ export class RoutePanelControl {
if (this._shared) return this._pushTrip();
const request = ++this._request;
this._route = null;
if (this._points.length < 2) {
if (this._active().length < 2) {
this._showResult(null, "");
return;
}
@@ -342,7 +436,7 @@ export class RoutePanelControl {
const response = await fetch(ROUTE_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ locations: this._points.map((p) => p.lngLat), vehicle: this._vehicleId, avoid: this._avoid }),
body: JSON.stringify({ locations: this._active().map((p) => p.lngLat), vehicle: this._vehicleId, avoid: this._avoid }),
});
data = await response.json().catch(() => ({}));
if (!response.ok) error = data.error || `routing failed (${response.status})`;
@@ -358,6 +452,7 @@ export class RoutePanelControl {
_showResult(route, message) {
this._draw();
notifyRouteChanged(route);
this._renderPoints(); // the legs' km and time next to the points (the Trip menu's too)
this._saveButton.hidden = !route || !isLoggedIn();
this._directions.hidden = !route;
this._profileButton.hidden = true;
@@ -516,7 +611,7 @@ export class RoutePanelControl {
...this._profileProperties(),
name: name.trim(),
via: this._points.map((p) => p.lngLat),
via_points: this._points.map((p) => ({ name: p.name || null, nav: !!p.nav })),
via_points: this._points.map((p) => ({ name: p.name || null, nav: !!p.nav, passed: !!p.passed })),
vehicle: this._vehicle,
},
};
@@ -778,7 +873,7 @@ function distanceM([lon1, lat1], [lon2, lat2]) {
return 12742000 * Math.asin(Math.sqrt(a));
}
function formatDuration(seconds) {
export function formatDuration(seconds) {
const minutes = Math.round(seconds / 60);
return minutes < 60 ? `${minutes} min` : `${Math.floor(minutes / 60)} h ${minutes % 60} min`;
}