Tablet-friendlier points: route markers get a 48px grab area, notes can be moved (Move in the popup: drag or tap the new spot), new and edited points pick an icon and a color with B/I buttons for their text, and the Tracks & Points open/close arrows get a real hit area
This commit is contained in:
1 parent
3e5fada66a
commit
07f3711760
3 files changed
+280
-77
No files matched your search
+63
-17
@@ -1,4 +1,5 @@
|
||||
import { Popup, LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { Popup, LngLatBounds, Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { PointStyleFields, formatToolbar } from "/js/notes.js";
|
||||
import {
|
||||
GPX_ICON,
|
||||
NEW_FOLDER_ICON,
|
||||
@@ -874,7 +875,7 @@ export class GpxPanelControl {
|
||||
const editable = feature.properties.category === "Note" && !!feature.properties.id && isLoggedIn();
|
||||
const popup = new Popup({ closeButton: true, maxWidth: "260px" })
|
||||
.setLngLat(lngLat)
|
||||
.setHTML(popupHtml(feature.properties, { editable }))
|
||||
.setHTML(popupHtml(feature.properties, { editable, movable: feature.geometry.type === "Point" }))
|
||||
.addTo(this._map);
|
||||
if (editable) this._wireNoteActions(popup, path, feature);
|
||||
if (feature.geometry.type === "Point") {
|
||||
@@ -946,6 +947,7 @@ export class GpxPanelControl {
|
||||
content.innerHTML = `
|
||||
<div class="gpx-popup__edit-form">
|
||||
<input type="text" class="gpx-popup__edit-title" value="${escapeHtml(feature.properties.name || "")}">
|
||||
<div class="gpx-popup__edit-style"></div>
|
||||
<textarea class="gpx-popup__edit-body" rows="3" placeholder="Details (optional) — **bold**, *italic*, links">${escapeHtml(feature.properties.description || "")}</textarea>
|
||||
<div class="gpx-popup__edit-actions">
|
||||
<button type="button" class="gpx-popup__edit-save">Save</button>
|
||||
@@ -955,31 +957,75 @@ export class GpxPanelControl {
|
||||
`;
|
||||
const titleInput = content.querySelector(".gpx-popup__edit-title");
|
||||
const bodyInput = content.querySelector(".gpx-popup__edit-body");
|
||||
bodyInput.before(formatToolbar(bodyInput));
|
||||
const style = new PointStyleFields(content.querySelector(".gpx-popup__edit-style"));
|
||||
style.set(feature.properties.icon || "", feature.properties.color === TRACK_COLOR ? "" : feature.properties.color || "");
|
||||
style.iconsVisible = feature.geometry.type === "Point";
|
||||
titleInput.focus();
|
||||
content.querySelector(".gpx-popup__edit-cancel").addEventListener("click", () => {
|
||||
content.innerHTML = popupHtml(feature.properties, { editable: true });
|
||||
content.innerHTML = popupHtml(feature.properties, { editable: true, movable: feature.geometry.type === "Point" });
|
||||
this._wireNoteActions(popup, path, feature);
|
||||
});
|
||||
content.querySelector(".gpx-popup__edit-save").addEventListener("click", async () => {
|
||||
const title = titleInput.value.trim();
|
||||
if (!title) return;
|
||||
const details = bodyInput.value.trim();
|
||||
const properties = { ...feature.properties, name: title };
|
||||
const properties = style.applyTo({ ...feature.properties, name: title });
|
||||
if (details) properties.description = details;
|
||||
else delete properties.description;
|
||||
const updated = { ...feature, properties };
|
||||
try {
|
||||
const body = new URLSearchParams({ path, id, feature: JSON.stringify(updated) });
|
||||
const response = await fetch("/api/library/notes", { method: "PUT", body });
|
||||
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
||||
popup.remove();
|
||||
notifyGpxStoreChanged();
|
||||
await this._reloadFile(path);
|
||||
} catch (err) {
|
||||
window.alert("Could not save the note — check your connection and try again.");
|
||||
}
|
||||
if (await this._saveNote(path, { ...feature, properties })) popup.remove();
|
||||
});
|
||||
});
|
||||
|
||||
// Move: a draggable marker at the point — drag it, or tap the new spot —
|
||||
// with Save/Cancel in a popup that follows it.
|
||||
element.querySelector(".gpx-popup__move")?.addEventListener("click", () => {
|
||||
popup.remove();
|
||||
this._moveNote(path, feature);
|
||||
});
|
||||
}
|
||||
|
||||
_moveNote(path, feature) {
|
||||
this._cancelMove?.();
|
||||
const markerEl = document.createElement("div");
|
||||
markerEl.className = "route-marker note-move-marker";
|
||||
const marker = new Marker({ element: markerEl, draggable: true }).setLngLat(feature.geometry.coordinates).addTo(this._map);
|
||||
const bar = document.createElement("div");
|
||||
bar.className = "gpx-popup__move-bar";
|
||||
bar.innerHTML = `<p>Drag the point or tap its new spot</p><div class="gpx-popup__edit-actions"><button type="button" class="gpx-popup__edit-save">Save</button><button type="button" class="gpx-popup__edit-cancel">Cancel</button></div>`;
|
||||
const barPopup = new Popup({ closeButton: false, closeOnClick: false, offset: 22, maxWidth: "240px" }).setDOMContent(bar);
|
||||
marker.setPopup(barPopup).togglePopup();
|
||||
const onMapClick = (event) => {
|
||||
marker.setLngLat(event.lngLat);
|
||||
if (!barPopup.isOpen()) marker.togglePopup();
|
||||
};
|
||||
this._map.on("click", onMapClick);
|
||||
const end = () => {
|
||||
this._map.off("click", onMapClick);
|
||||
marker.remove();
|
||||
this._cancelMove = null;
|
||||
};
|
||||
this._cancelMove = end;
|
||||
bar.querySelector(".gpx-popup__edit-cancel").addEventListener("click", end);
|
||||
bar.querySelector(".gpx-popup__edit-save").addEventListener("click", async () => {
|
||||
const { lng, lat } = marker.getLngLat();
|
||||
if (await this._saveNote(path, { ...feature, geometry: { ...feature.geometry, coordinates: [lng, lat] } })) end();
|
||||
});
|
||||
}
|
||||
|
||||
// PUTs the edited note and reloads its file's layers; false on failure.
|
||||
async _saveNote(path, updated) {
|
||||
try {
|
||||
const body = new URLSearchParams({ path, id: updated.properties.id, feature: JSON.stringify(updated) });
|
||||
const response = await fetch("/api/library/notes", { method: "PUT", body });
|
||||
if (!response.ok) throw new Error(`save failed: ${response.status}`);
|
||||
notifyGpxStoreChanged();
|
||||
await this._reloadFile(path);
|
||||
return true;
|
||||
} catch (err) {
|
||||
window.alert("Could not save the note — check your connection and try again.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async _reloadFile(path) {
|
||||
@@ -1459,7 +1505,7 @@ function nodeKeys(node) {
|
||||
// for — see _registerPointInteractivity) adds Edit/Delete buttons; the
|
||||
// click handling for them lives in _wireNoteActions, not here, since this
|
||||
// only builds markup, it has no map/store access of its own.
|
||||
function popupHtml({ name, description, time, category, photos, icon }, { editable = false } = {}) {
|
||||
function popupHtml({ name, description, time, category, photos, icon }, { editable = false, movable = false } = {}) {
|
||||
const parts = [];
|
||||
if (name) {
|
||||
const glyph = icon && POI_ICONS[icon] ? `<span class="gpx-popup__header-icon">${POI_ICONS[icon]}</span>` : "";
|
||||
@@ -1482,7 +1528,7 @@ function popupHtml({ name, description, time, category, photos, icon }, { editab
|
||||
}
|
||||
if (editable) {
|
||||
parts.push(
|
||||
`<div class="gpx-popup__note-actions"><button type="button" class="gpx-popup__edit">Edit</button><button type="button" class="gpx-popup__delete">Delete</button></div>`,
|
||||
`<div class="gpx-popup__note-actions"><button type="button" class="gpx-popup__edit">Edit</button>${movable ? `<button type="button" class="gpx-popup__move">Move</button>` : ""}<button type="button" class="gpx-popup__delete">Delete</button></div>`,
|
||||
);
|
||||
}
|
||||
return parts.length > 0 ? parts.join("") : "<em>No details</em>";
|
||||
|
||||
Reference in new issue
Block a user