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
This commit is contained in:
1 parent
0eb9d05cdc
commit
809e88ab1a
14 files changed
+517
-101
No files matched your search
+6
-70
@@ -1,28 +1,9 @@
|
||||
import { DEBUG_ICON } from "/js/icons.js";
|
||||
import { escapeHtml } from "/js/gpx.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||
|
||||
// Every read-only status endpoint, dumped as raw JSON. No check-update
|
||||
// routes here — those reach out to Geofabrik/the internet, not just report
|
||||
// local state.
|
||||
const ENDPOINTS = [
|
||||
"/api/health",
|
||||
"/api/offline-tiles",
|
||||
"/api/offline-tiles/build-status",
|
||||
"/api/offline-regions",
|
||||
"/api/offline-tiles/cache",
|
||||
"/api/terrain-tiles",
|
||||
"/api/terrain-tiles/build-status",
|
||||
"/api/build-history",
|
||||
"/api/hiking-trails",
|
||||
"/api/kiwix",
|
||||
"/api/plugins",
|
||||
"/api/gnss/position",
|
||||
"/api/livetrack/sessions",
|
||||
];
|
||||
const REFRESH_MS = 5000; // while open — a running build's progress shows up live
|
||||
|
||||
// Sidebar icon pinned to the bottom of the rail, logged-in only (map.js).
|
||||
// Sidebar icon pinned to the bottom of the rail, logged-in only (map.js):
|
||||
// a panel of links — every endpoint's state on the full-screen
|
||||
// /status.html, the CANopen diagnostics — and the update check.
|
||||
export class DebugControl {
|
||||
mount(sidebar) {
|
||||
this._container = document.createElement("div");
|
||||
@@ -32,9 +13,8 @@ export class DebugControl {
|
||||
this._icon.addEventListener("click", () => this._togglePanel());
|
||||
|
||||
this._panel = document.getElementById("debug-panel");
|
||||
this._body = this._panel.querySelector(".debug-panel__body");
|
||||
this._panel.querySelector(".basemap-panel__close").addEventListener("click", () => this._togglePanel(false));
|
||||
onlyOneSidePanelOpen(this._panel, () => this._stop());
|
||||
onlyOneSidePanelOpen(this._panel, () => this._icon.classList.remove("active"));
|
||||
|
||||
sidebar.appendChild(this._container);
|
||||
}
|
||||
@@ -42,51 +22,7 @@ export class DebugControl {
|
||||
_togglePanel(force) {
|
||||
const open = force === undefined ? this._panel.hidden : force;
|
||||
this._panel.hidden = !open;
|
||||
if (!open) return this._stop();
|
||||
|
||||
this._icon.classList.add("active");
|
||||
notifySidePanelOpen(this._panel);
|
||||
this._refresh();
|
||||
this._timer = setInterval(() => this._refresh(), REFRESH_MS);
|
||||
}
|
||||
|
||||
_stop() {
|
||||
this._icon.classList.remove("active");
|
||||
clearInterval(this._timer);
|
||||
}
|
||||
|
||||
async _refresh() {
|
||||
const sections = await Promise.all(
|
||||
ENDPOINTS.map(async (url) => {
|
||||
let text;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const body = await response.text();
|
||||
try {
|
||||
text = JSON.stringify(JSON.parse(body), null, 2);
|
||||
} catch {
|
||||
text = body;
|
||||
}
|
||||
if (!response.ok) text = `HTTP ${response.status}\n${text}`;
|
||||
} catch (error) {
|
||||
text = `request failed: ${error.message}`;
|
||||
}
|
||||
return { url, text };
|
||||
}),
|
||||
);
|
||||
if (this._panel.hidden) return;
|
||||
|
||||
// Keep whichever sections the user collapsed collapsed across refreshes.
|
||||
const closed = new Set([...this._body.querySelectorAll("details:not([open])")].map((el) => el.dataset.url));
|
||||
this._body.innerHTML = sections
|
||||
.map(
|
||||
({ url, text }) => `
|
||||
<details data-url="${url}" ${closed.has(url) ? "" : "open"}>
|
||||
<summary>${url}</summary>
|
||||
<pre>${escapeHtml(text)}</pre>
|
||||
</details>
|
||||
`,
|
||||
)
|
||||
.join("");
|
||||
this._icon.classList.toggle("active", open);
|
||||
if (open) notifySidePanelOpen(this._panel);
|
||||
}
|
||||
}
|
||||
+120
-2
@@ -1,6 +1,7 @@
|
||||
import { LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { requestGnssFollow, onRouteChanged } from "/js/panels.js";
|
||||
import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js";
|
||||
import { formatDuration } from "/js/route.js";
|
||||
|
||||
// Driving mode: the few things needed on the road as big buttons, the
|
||||
// planning sidebar and panels out of the way. After the research in
|
||||
@@ -11,8 +12,11 @@ import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js";
|
||||
const KEY = "drivingMode";
|
||||
const PITCH_3D = 60; // as map.js's 3D toggle
|
||||
const CHECK_MS = 1000; // how often the recenter button looks whether the map follows
|
||||
const SEARCH_DELAY_MS = 300; // after the last key
|
||||
|
||||
export function setupDriving(map, nightButton) {
|
||||
const escapeHtml = (text) => String(text).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||||
|
||||
export function setupDriving(map, nightButton, routePanel) {
|
||||
let route = onRouteChanged((r) => (route = r));
|
||||
const toggle = document.createElement("button");
|
||||
toggle.type = "button";
|
||||
@@ -38,6 +42,7 @@ export function setupDriving(map, nightButton) {
|
||||
button("zoomIn", "+", "Zoom in", () => map.zoomIn()),
|
||||
button("zoomOut", "−", "Zoom out", () => map.zoomOut()),
|
||||
button("pitch", "3D", "2D / 3D", () => map.easeTo({ pitch: map.getPitch() > 0 ? 0 : PITCH_3D, ...(map.getPitch() > 0 && { bearing: 0 }), duration: 300 })),
|
||||
button("trip", "Trip", "The trip's stops: add, move, remove", () => openTrip(tripPanel.hidden)),
|
||||
button("overview", "Route", "The whole route (the follow pauses)", () => {
|
||||
const coords = route?.geometry?.coordinates;
|
||||
if (!coords?.length) return;
|
||||
@@ -53,7 +58,119 @@ export function setupDriving(map, nightButton) {
|
||||
recenter.hidden = true;
|
||||
});
|
||||
recenter.hidden = true;
|
||||
map.getContainer().append(bar, recenter);
|
||||
// The Trip menu (the navigator's, docs/design.adoc): the stops as big
|
||||
// rows — tap a name to look at it, ↑ ↓ to reorder, ✕ to drop — and big
|
||||
// actions: a stop where the crosshair is (pan the map there first), the
|
||||
// start moved to the car. One level, no dragging, no typing.
|
||||
const tripPanel = document.createElement("div");
|
||||
tripPanel.className = "drive-trip";
|
||||
tripPanel.hidden = true;
|
||||
tripPanel.innerHTML = `<div class="drive-trip__head"><span>Trip <small class="drive-trip__total"></small></span><button type="button" class="drive-trip__close" aria-label="Close">✕</button></div>
|
||||
<div class="drive-trip__search"><input type="search" placeholder="Search saved points and places…" enterkeyhint="search"></div>
|
||||
<ol class="drive-trip__stops"></ol>
|
||||
<div class="drive-trip__actions">
|
||||
<button type="button" data-action="add">+ Stop at the crosshair</button>
|
||||
<button type="button" data-action="start">Start from here (the car)</button>
|
||||
</div>`;
|
||||
const crosshair = document.createElement("div");
|
||||
crosshair.className = "drive-crosshair";
|
||||
crosshair.hidden = true;
|
||||
const visibleCenter = () => {
|
||||
const { clientWidth: w, clientHeight: h } = map.getContainer();
|
||||
return [(w - tripPanel.offsetWidth) / 2, h / 2];
|
||||
};
|
||||
const placeCrosshair = () => {
|
||||
const [x, y] = visibleCenter();
|
||||
crosshair.style.left = `${x}px`;
|
||||
crosshair.style.top = `${y}px`;
|
||||
};
|
||||
// Search: saved points (the library) and places (the offline POI
|
||||
// database), nearest the crosshair first; a result's name shows it, + adds
|
||||
// it as a stop. While there's a query the list shows results, not stops.
|
||||
const input = tripPanel.querySelector(".drive-trip__search input");
|
||||
let results = null;
|
||||
let searchTimer = null;
|
||||
let searchSeq = 0;
|
||||
input.addEventListener("input", () => {
|
||||
clearTimeout(searchTimer);
|
||||
if (!input.value.trim()) {
|
||||
results = null;
|
||||
return renderTrip();
|
||||
}
|
||||
searchTimer = setTimeout(async () => {
|
||||
const mine = ++searchSeq;
|
||||
const { lng, lat } = map.unproject(visibleCenter());
|
||||
const url = new URL("/api/search", window.location.origin);
|
||||
url.search = new URLSearchParams({ q: input.value, sources: "layers,places", lat, lng });
|
||||
let found = [];
|
||||
try { found = (await (await fetch(url)).json()).results; } catch { /* offline for a moment: nothing */ }
|
||||
if (mine !== searchSeq) return;
|
||||
results = found.filter(({ bbox }) => bbox).map(({ name, bbox, source_label: where }) => ({ name, where, lngLat: [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2] }));
|
||||
renderTrip();
|
||||
}, SEARCH_DELAY_MS);
|
||||
});
|
||||
const lookAt = (lngLat) => {
|
||||
pauseFollow(map);
|
||||
map.easeTo({ center: lngLat, zoom: Math.max(map.getZoom(), 14), padding: { right: tripPanel.offsetWidth } });
|
||||
};
|
||||
const renderResults = (list) => {
|
||||
list.replaceChildren(...results.map((r) => {
|
||||
const li = document.createElement("li");
|
||||
const name = button("stop-name", r.name, "Show it on the map", () => lookAt(r.lngLat));
|
||||
name.innerHTML = `${escapeHtml(r.name)}<small>${escapeHtml(r.where || "")}</small>`;
|
||||
const add = button("stop-add", "+", "Add as a stop", () => {
|
||||
input.value = "";
|
||||
results = null; // back to the stops, the new one among them
|
||||
routePanel.addStop(r.lngLat, r.name);
|
||||
});
|
||||
li.append(name, add);
|
||||
return li;
|
||||
}));
|
||||
if (!results.length) list.innerHTML = `<li class="drive-trip__empty">Nothing found.</li>`;
|
||||
};
|
||||
const renderTrip = () => {
|
||||
if (tripPanel.hidden || !routePanel) return;
|
||||
if (results) return renderResults(tripPanel.querySelector(".drive-trip__stops"));
|
||||
const stops = routePanel.stops();
|
||||
const list = tripPanel.querySelector(".drive-trip__stops");
|
||||
list.replaceChildren(...stops.map((stop, i) => {
|
||||
const li = document.createElement("li");
|
||||
const name = button("stop-name", "", "Show it on the map", () => lookAt(stop.lngLat));
|
||||
const leg = stop.leg ? `<small>+${stop.leg.km.toFixed(1)} km${stop.leg.s != null ? ` · ${formatDuration(stop.leg.s)}` : ""}</small>` : "";
|
||||
name.innerHTML = `${escapeHtml(stop.label)} · ${escapeHtml(stop.name || `${stop.lngLat[1].toFixed(4)}, ${stop.lngLat[0].toFixed(4)}`)}${leg}`;
|
||||
const done = button("stop-done", "✓", stop.passed ? "Passed — tap to route through it again" : "Mark as passed (not routed any more)", () => routePanel.togglePassed(i));
|
||||
done.classList.toggle("active", !!stop.passed);
|
||||
li.classList.toggle("drive-trip__passed", !!stop.passed || stop.behind);
|
||||
const up = button("stop-up", "↑", "Earlier", () => routePanel.moveStop(i, -1));
|
||||
const down = button("stop-down", "↓", "Later", () => routePanel.moveStop(i, 1));
|
||||
const drop = button("stop-drop", "✕", "Remove this stop", () => routePanel.removeStop(i));
|
||||
up.disabled = i === 0;
|
||||
down.disabled = i === stops.length - 1;
|
||||
li.append(name, done, up, down, drop);
|
||||
return li;
|
||||
}));
|
||||
if (!stops.length) list.innerHTML = `<li class="drive-trip__empty">No stops yet — pan the map to a place and add it.</li>`;
|
||||
const p = route?.properties;
|
||||
tripPanel.querySelector(".drive-trip__total").textContent = p && stops.length > 1 ? `${p.distance_km.toFixed(1)} km · ${formatDuration(p.time_s)}` : "";
|
||||
};
|
||||
function openTrip(open) {
|
||||
tripPanel.hidden = !open;
|
||||
crosshair.hidden = !open;
|
||||
bar.querySelector(".drive-bar__trip").classList.toggle("active", open);
|
||||
if (open) {
|
||||
renderTrip();
|
||||
placeCrosshair();
|
||||
}
|
||||
}
|
||||
tripPanel.querySelector(".drive-trip__close").addEventListener("click", () => openTrip(false));
|
||||
tripPanel.querySelector('[data-action="add"]').addEventListener("click", () => {
|
||||
const { lng, lat } = map.unproject(visibleCenter());
|
||||
routePanel?.addStop([lng, lat]);
|
||||
});
|
||||
tripPanel.querySelector('[data-action="start"]').addEventListener("click", () => routePanel?.startHere());
|
||||
routePanel?.onStopsChanged(renderTrip);
|
||||
window.addEventListener("resize", placeCrosshair);
|
||||
map.getContainer().append(bar, recenter, tripPanel, crosshair);
|
||||
|
||||
const render = () => {
|
||||
bar.querySelector(".drive-bar__pitch").textContent = map.getPitch() > 0 ? "2D" : "3D";
|
||||
@@ -65,6 +182,7 @@ export function setupDriving(map, nightButton) {
|
||||
setInterval(render, CHECK_MS);
|
||||
|
||||
function set(on) {
|
||||
if (!on) openTrip(false);
|
||||
document.documentElement.classList.toggle("driving", on);
|
||||
bar.hidden = !on;
|
||||
toggle.classList.toggle("active", on);
|
||||
|
||||
+3
-2
@@ -532,7 +532,6 @@ nightButton.addEventListener("click", () => {
|
||||
updateNight();
|
||||
map.on("moveend", updateNight);
|
||||
setInterval(updateNight, 60000);
|
||||
setupDriving(map, nightButton);
|
||||
|
||||
const sidebar = document.getElementById("sidebar");
|
||||
|
||||
@@ -562,7 +561,9 @@ if (isLoggedIn()) new PluginsControl(map).mount(sidebar);
|
||||
sidebar.insertAdjacentHTML("beforeend", `<div class="sidebar-group-label" title="Offline hub"></div>`);
|
||||
layerToggle.mount(sidebar);
|
||||
layerToggle.setActive("online");
|
||||
new RoutePanelControl(map, gnssControl, profilePanel).mount(sidebar);
|
||||
const routePanel = new RoutePanelControl(map, gnssControl, profilePanel);
|
||||
routePanel.mount(sidebar);
|
||||
setupDriving(map, nightButton, routePanel);
|
||||
new OfflineDataControl().mount(sidebar);
|
||||
|
||||
sidebar.insertAdjacentHTML("beforeend", `<div class="sidebar-group-label" title="Navigation"></div>`);
|
||||
|
||||
+108
-13
@@ -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`;
|
||||
}
|
||||
Reference in new issue
Block a user