Route panel: points from search, GPS and library points, reordering, editing a saved route

This commit is contained in:
randy committed 2026-11-13 22:37:49 +01:00
1 parent 3146478c23
commit abde7fe5f9
10 files changed
+214 -25

No files matched your search

+25 -1
View File
@@ -11,7 +11,7 @@ import {
POI_ICONS,
PARK4NIGHT_TAGS,
} from "/js/icons.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, onGpxStoreChanged, notifyGpxStoreChanged } from "/js/panels.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, onGpxStoreChanged, notifyGpxStoreChanged, addRoutePoint, editRoute } from "/js/panels.js";
import { formatActivityType } from "/js/track_profile.js";
import { isLoggedIn } from "/js/auth.js";
@@ -366,6 +366,7 @@ export class GpxPanelControl {
{ label: "Color…", run: () => this._pickColor(file) },
file.color && { label: "Default color", run: () => this._patchNode(file.path, { color: "" }) },
file.layer && { label: "Split into items", run: () => this._splitLayer(file) },
(file.kinds || []).includes("route") && { label: "Edit route", run: () => this._editRoute(file) },
]);
}
@@ -757,6 +758,17 @@ export class GpxPanelControl {
.setHTML(popupHtml(feature.properties, { editable }))
.addTo(this._map);
if (editable) this._wireNoteActions(popup, path, feature);
if (feature.geometry.type === "Point") {
const button = document.createElement("button");
button.type = "button";
button.className = "gpx-popup__route";
button.textContent = "Add to route";
button.addEventListener("click", () => {
addRoutePoint(feature.geometry.coordinates, feature.properties.name);
popup.remove();
});
popup.getElement().querySelector(".maplibregl-popup-content").appendChild(button);
}
}
// Edit swaps the popup's content for a plain textarea + Save/Cancel (the
@@ -1123,6 +1135,18 @@ export class GpxPanelControl {
}
}
// A route saved from the route panel keeps its points (properties.via);
// one without them (an imported GPX route) can't be re-routed.
async _editRoute(file) {
const { features } = await (await fetch(gpxFileUrl(file.path))).json();
const route = features.find((f) => f.geometry.type === "LineString" && Array.isArray(f.properties.via));
if (!route) {
window.alert("This route has no saved route points, so it can't be edited.");
return;
}
editRoute(file.path, route);
}
async _splitLayer(file) {
if (!window.confirm(`Split "${file.name}" into separate points and tracks? This can't be undone.`)) return;