Files
maptool/public/js/panels.js
T
randy aa2b96ac70 Add a "user overlay" tool: click the map, save a note
New map-corner "Add note" control (public/js/notes.js), mirroring
measure.js's click-to-place UX. Click the map, write a short note,
pick an existing .geojson layer file or name a new one — saved via a
new GpxStore#append_feature (grows the target file in place, unlike
save()'s always-disambiguate-the-filename behavior) through a new
POST /api/gpx/notes route.

No new rendering path: a note is just another point in a .geojson
file the Tracks panel's tree already lists, checkboxes, and pops up —
visibility toggling ("layers") comes for free from that existing
machinery, per-file, with no changes needed there.

Points only for now — a polygon mode would need gpx.js's point/line
split taught a third Polygon bucket first, or a saved polygon
wouldn't render back on reload (see TODO.adoc).

Covered by new tests: GpxStore#append_feature (create/append/missing-
path/filename-safety) and the /api/gpx/notes route (auth gate, create,
append, malformed/missing-geometry rejection, 404 on a missing
target). Full suite: 97 runs, 0 failures.
2026-09-09 10:18:50 +02:00

31 lines
1.0 KiB
JavaScript

// Keeps at most one full-height side panel (base map, GPX, ...) open at a
// time — they all dock to the same spot next to the sidebar, so two open
// together would just stack on top of each other.
const OPEN_EVENT = "side-panel-open";
export function notifySidePanelOpen(panel) {
document.dispatchEvent(new CustomEvent(OPEN_EVENT, { detail: panel }));
}
export function onlyOneSidePanelOpen(panel, onClosedByOther) {
document.addEventListener(OPEN_EVENT, (event) => {
if (event.detail !== panel && !panel.hidden) {
panel.hidden = true;
onClosedByOther();
}
});
}
// Lets a control that writes into the GPX store (e.g. notes.js saving a
// drawn point) tell GpxPanelControl its tree is stale, without either one
// holding a reference to the other.
const STORE_CHANGED_EVENT = "gpx-store-changed";
export function notifyGpxStoreChanged() {
document.dispatchEvent(new CustomEvent(STORE_CHANGED_EVENT));
}
export function onGpxStoreChanged(callback) {
document.addEventListener(STORE_CHANGED_EVENT, callback);
}