Tracks and routes as containers of points: listed (collapsed) under them in the tree, added via a point's popup, a new note or the route planner's navigation pins, and written as course points into the FIT course
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-18 12:39:04 +01:00
1 parent 6aa7b34f92
commit 4265421457
10 files changed
+354 -20

No files matched your search

+89 -1
View File
@@ -251,6 +251,9 @@ export class GpxPanelControl {
}
_renderTree(node) {
this._files = new Map();
const index = (n) => (n.children || []).forEach((c) => (c.type === "folder" ? index(c) : this._files.set(c.path, c)));
index(node);
this._treeContainer.innerHTML = "";
this._treeContainer.appendChild(this._renderChildren(node.children));
}
@@ -269,6 +272,8 @@ export class GpxPanelControl {
const li = document.createElement("li");
if (child.type === "folder") {
li.appendChild(this._renderFolder(child));
} else if (child.points) {
li.appendChild(this._renderTrackWithPoints(child));
} else {
li.appendChild(this._renderFile(child));
}
@@ -278,6 +283,62 @@ export class GpxPanelControl {
return ul;
}
// A track/route holding points: collapsed by default (there can be many),
// each point zooms to itself and can be taken out again.
_renderTrackWithPoints(file) {
this._openTracks ||= new Set();
const details = document.createElement("details");
details.className = "gpx-tree__track";
details.open = this._openTracks.has(file.path);
details.addEventListener("toggle", () => (details.open ? this._openTracks.add(file.path) : this._openTracks.delete(file.path)));
const summary = document.createElement("summary");
summary.appendChild(this._renderFile(file));
details.appendChild(summary);
const ul = document.createElement("ul");
ul.className = "gpx-tree__points";
file.points.forEach((point) => {
const li = document.createElement("li");
li.className = "gpx-tree__point";
const name = document.createElement("button");
name.type = "button";
name.className = "gpx-tree__point-name";
name.textContent = point.name;
name.addEventListener("click", () => this._goToPoint(file.path, point));
li.appendChild(name);
if (isLoggedIn()) li.appendChild(this._deleteButton(() => this._removePoint(file, point)));
ul.appendChild(li);
});
details.appendChild(ul);
return details;
}
async _goToPoint(path, point) {
await this.show(path);
this._map.flyTo({ center: point.coordinates, zoom: Math.max(this._map.getZoom(), 15) });
const feature = this._pointsByPath.get(path)?.features.find((f) => f.properties.id === point.id);
if (feature) this._openPointPopup(path, feature, point.coordinates);
}
async _removePoint(file, point) {
if (!window.confirm(`Remove "${point.name}" from "${file.name}"?`)) return;
const response = await fetch(`/api/library/notes?${new URLSearchParams({ path: file.path, id: point.id })}`, { method: "DELETE" });
if (!response.ok) return window.alert("Could not remove the point.");
await this._loadTree();
if (this._visible.has(file.path)) await this._reloadFile(file.path);
}
// A copy of the point into a shown track/route, which keeps it from
// then on (exported with it, a course point in its FIT course).
async _addPointTo(target, feature) {
const { id, ...properties } = feature.properties;
const body = new URLSearchParams({ feature: JSON.stringify({ type: "Feature", geometry: { type: "Point", coordinates: feature.geometry.coordinates }, properties }) });
const response = await fetch(`${gpxFileUrl(target)}/points`, { method: "POST", body });
if (!response.ok) return window.alert("Could not add the point.");
this._renderTree((await response.json()).tree);
await this._reloadFile(target);
}
_renderFolder(folder) {
const details = document.createElement("details");
details.open = true;
@@ -831,10 +892,37 @@ export class GpxPanelControl {
addRoutePoint(feature.geometry.coordinates, feature.properties.name);
popup.remove();
});
popup.getElement().querySelector(".maplibregl-popup-content").appendChild(button);
const content = popup.getElement().querySelector(".maplibregl-popup-content");
content.appendChild(button);
if (isLoggedIn()) {
// Into any track/route shown right now, or out of the one holding it.
const holder = this._files?.get(path)?.points?.some((p) => p.id === feature.properties.id) && this._files.get(path);
const targets = [...this._visible].filter((p) => p !== path && p.startsWith("item:") && this._files?.get(p)?.kinds?.some((k) => k === "track" || k === "route") && !this._files.get(p).layer);
targets.forEach((target) => {
content.appendChild(this._popupButton(`Add to "${this._files.get(target).name}"`, async () => {
popup.remove();
await this._addPointTo(target, feature);
}));
});
if (holder) {
content.appendChild(this._popupButton(`Remove from "${holder.name}"`, async () => {
popup.remove();
await this._removePoint(holder, { id: feature.properties.id, name: feature.properties.name || "Point" });
}));
}
}
}
}
_popupButton(label, onClick) {
const button = document.createElement("button");
button.type = "button";
button.className = "gpx-popup__route";
button.textContent = label;
button.addEventListener("click", onClick);
return button;
}
// Edit swaps the popup's content for a plain textarea + Save/Cancel (the
// note's location doesn't change, just its text, so there's no need for
// NoteSaveForm's fuller target-file picker here). Delete just confirms