56 lines
2.1 KiB
JavaScript
56 lines
2.1 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. path (the .geojson file just written
|
|
// to) lets the listener also auto-show that file instead of just refreshing
|
|
// the tree — the point/shape just saved is otherwise invisible until the
|
|
// user finds and checks it by hand.
|
|
const STORE_CHANGED_EVENT = "gpx-store-changed";
|
|
|
|
export function notifyGpxStoreChanged(path) {
|
|
document.dispatchEvent(new CustomEvent(STORE_CHANGED_EVENT, { detail: path }));
|
|
}
|
|
|
|
export function onGpxStoreChanged(callback) {
|
|
document.addEventListener(STORE_CHANGED_EVENT, (event) => callback(event.detail));
|
|
}
|
|
|
|
// Anything with a location (a search result, a library point) hands it to
|
|
// the route panel (route.js) the same decoupled way.
|
|
const ROUTE_POINT_EVENT = "route-point";
|
|
const ROUTE_EDIT_EVENT = "route-edit";
|
|
|
|
export function addRoutePoint(lngLat, name) {
|
|
document.dispatchEvent(new CustomEvent(ROUTE_POINT_EVENT, { detail: { lngLat, name } }));
|
|
}
|
|
|
|
export function onRoutePoint(callback) {
|
|
document.addEventListener(ROUTE_POINT_EVENT, (event) => callback(event.detail));
|
|
}
|
|
|
|
// A saved route (its library node key and feature) back into the panel.
|
|
export function editRoute(key, feature) {
|
|
document.dispatchEvent(new CustomEvent(ROUTE_EDIT_EVENT, { detail: { key, feature } }));
|
|
}
|
|
|
|
export function onRouteEdit(callback) {
|
|
document.addEventListener(ROUTE_EDIT_EVENT, (event) => callback(event.detail));
|
|
}
|