From 07f371176006647393986d69a19a436589d32fdb Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Thu, 19 Nov 2026 00:03:39 +0100 Subject: [PATCH] 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 --- public/css/style.css | 138 ++++++++++++++++++++++++++++++++++-------- public/js/gpx.js | 80 +++++++++++++++++++------ public/js/notes.js | 139 ++++++++++++++++++++++++++++++++----------- 3 files changed, 280 insertions(+), 77 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index 6255ed4..18dbd02 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -975,9 +975,43 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr } .gpx-tree summary { + display: flex; + align-items: center; cursor: pointer; font-weight: 600; border-radius: 3px; + list-style: none; +} + +.gpx-tree summary::-webkit-details-marker { + display: none; +} + +/* The open/close arrow for folders and tracks with points: a real hit area + (the browser's own marker, or a 12px glyph, was a fingertip miss). */ +.gpx-tree summary::before { + content: "▸"; + flex: none; + display: flex; + align-items: center; + justify-content: center; + width: 24px; + height: 28px; + color: #888; + font-size: 13px; + transition: transform 0.15s; +} + +.gpx-tree details[open] > summary::before { + transform: rotate(90deg); +} + +@media (pointer: coarse) { + .gpx-tree summary::before { + width: 36px; + height: 40px; + font-size: 16px; + } } .gpx-tree__folder-row { @@ -985,7 +1019,8 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr align-items: center; justify-content: space-between; gap: 4px; - width: calc(100% - 18px); + flex: 1; + min-width: 0; } .gpx-tree__folder-row > :first-child { @@ -997,34 +1032,13 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr outline: 1px dashed #4a90d9; } -/* A track/route holding points: its row is the summary, a small - triangle (not the browser's marker, gone with display:flex) opens the - point list. */ +/* A track/route holding points: its row is the summary, the shared + .gpx-tree summary::before arrow opens the point list. */ .gpx-tree__track > summary { - display: flex; - align-items: center; font-weight: normal; - list-style: none; margin-left: -12px; } -.gpx-tree__track > summary::-webkit-details-marker { - display: none; -} - -.gpx-tree__track > summary::before { - content: "▸"; - width: 12px; - flex: none; - color: #888; - font-size: 10px; - transition: transform 0.15s; -} - -.gpx-tree__track[open] > summary::before { - transform: rotate(90deg); -} - .gpx-tree__track > summary > .gpx-tree__file { flex: 1; min-width: 0; @@ -1697,6 +1711,73 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr background: var(--accent-bg); } +/* Point color swatches (PointStyleFields, notes.js); the first is "default". */ +.notes-panel__colors { + display: flex; + flex-wrap: wrap; + gap: 4px; + margin: 4px 0; +} + +.notes-panel__color { + width: 24px; + height: 24px; + padding: 0; + border: 2px solid #fff; + border-radius: 50%; + background: var(--swatch, repeating-linear-gradient(45deg, #fff 0 3px, #ccc 3px 6px)); + box-shadow: 0 0 0 1px #bbb; + cursor: pointer; +} + +.notes-panel__color.active { + box-shadow: 0 0 0 2px var(--accent); +} + +/* B / I above a note's text (formatToolbar, notes.js). */ +.notes-panel__format { + display: flex; + gap: 4px; + margin: 4px 0 2px; +} + +.notes-panel__format button { + min-width: 32px; + height: 28px; + border: 1px solid #ccc; + border-radius: 4px; + background: #fff; + font: inherit; + cursor: pointer; +} + +.notes-panel__format button:hover { + background: #f0f0f0; +} + +/* Moving a note: the marker takes the accent color, the hint + Save/Cancel + ride in a popup above it. */ +.note-move-marker { + background: var(--accent); +} + +.gpx-popup__move-bar p { + margin: 0 0 6px; + font-size: 13px; +} + +@media (pointer: coarse) { + .notes-panel__color { + width: 32px; + height: 32px; + } + + .notes-panel__format button { + min-width: 44px; + height: 36px; + } +} + /* The pending-note marker shown on the map while the save form is open — updates live to whatever icon is picked (see notes.js's onIconChange). A plain round badge (not a drop-pin shape) since MapLibre anchors a custom @@ -2644,6 +2725,15 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr cursor: grab; } +/* An invisible 48px grab area around the 26px dot: a finger missed the dot + itself and panned the map instead (the marker is already absolutely + positioned by MapLibre, so this needs no position of its own). */ +.route-marker::after { + content: ""; + position: absolute; + inset: -11px; +} + .route-panel__remove:disabled { visibility: hidden; } diff --git a/public/js/gpx.js b/public/js/gpx.js index 36ea094..3d8924e 100644 --- a/public/js/gpx.js +++ b/public/js/gpx.js @@ -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 = `
+
@@ -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 = `

Drag the point or tap its new spot

`; + 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] ? `${POI_ICONS[icon]}` : ""; @@ -1482,7 +1528,7 @@ function popupHtml({ name, description, time, category, photos, icon }, { editab } if (editable) { parts.push( - `
`, + `
${movable ? `` : ""}
`, ); } return parts.length > 0 ? parts.join("") : "No details"; diff --git a/public/js/notes.js b/public/js/notes.js index 82635c8..77833dd 100644 --- a/public/js/notes.js +++ b/public/js/notes.js @@ -38,6 +38,102 @@ const PICKER_ICONS = [ .map((name) => [name, name.replace(/-/g, " ")]), ]; +// Badge colors a point can take: the track palette plus NPS olive, brown and +// black. "" = no color of its own (the layer's default badge color). +const POINT_COLORS = ["#e63946", "#e0a32e", "#7cc957", "#2aa7a0", "#5a55e0", "#9058d6", "#546619", "#5e4b3c", "#1a1a1a"]; + +// Icon + color for a point — shared by the new-note form and the Edit form +// in a point's popup (gpx.js), so both offer the same choices. +export class PointStyleFields { + constructor(container, { onIconChange } = {}) { + this._onIconChange = onIconChange; + this.el = document.createElement("div"); + this.el.className = "notes-panel__style"; + this.el.innerHTML = ` +
+ + ${POINT_COLORS.map((c) => ``).join("")} +
+
+ +
+ + ${PICKER_ICONS.map( + ([key, label]) => + ``, + ).join("")} +
+
+ `; + container.appendChild(this.el); + this._filter = this.el.querySelector(".notes-panel__icon-filter"); + this._filter.addEventListener("input", () => { + const query = this._filter.value.trim().toLowerCase(); + this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => { + b.hidden = query !== "" && !`${b.title} ${b.dataset.icon}`.toLowerCase().includes(query); + }); + }); + this.el.querySelectorAll(".notes-panel__icon-option").forEach((button) => + button.addEventListener("click", () => { + this._setIcon(button.dataset.icon); + this._onIconChange?.(this.icon); + }), + ); + this.el.querySelectorAll(".notes-panel__color").forEach((button) => button.addEventListener("click", () => this._setColor(button.dataset.color))); + this.set(); + } + + // Resets the filter too; an unknown color/icon just leaves none selected. + set(icon = "", color = "") { + this._filter.value = ""; + this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => (b.hidden = false)); + this._setIcon(icon); + this._setColor(color); + } + + // An icon only makes sense on a single point (not a measured line/area). + set iconsVisible(visible) { + this.el.querySelector(".notes-panel__icon-picker").hidden = !visible; + } + + _setIcon(icon) { + this.icon = icon; + this.el.querySelectorAll(".notes-panel__icon-option").forEach((b) => b.classList.toggle("active", b.dataset.icon === icon)); + } + + _setColor(color) { + this.color = color; + this.el.querySelectorAll(".notes-panel__color").forEach((b) => b.classList.toggle("active", b.dataset.color === color)); + } + + // Writes icon/color into a feature's properties (removing the ones unset). + applyTo(properties) { + for (const [key, value] of [["icon", this.icon], ["color", this.color]]) { + if (value) properties[key] = value; + else delete properties[key]; + } + return properties; + } +} + +// B / I buttons above a note's textarea: wrap the selection in the light +// markdown formatNoteBody renders (**bold**, *italic*), or insert an empty +// pair with the cursor in between. +export function formatToolbar(textarea) { + const bar = document.createElement("div"); + bar.className = "notes-panel__format"; + bar.innerHTML = ``; + bar.addEventListener("click", (event) => { + const mark = event.target.closest("button")?.dataset.mark; + if (!mark) return; + const { selectionStart: start, selectionEnd: end, value } = textarea; + textarea.value = value.slice(0, start) + mark + value.slice(start, end) + mark + value.slice(end); + textarea.focus(); + textarea.setSelectionRange(start + mark.length, end + mark.length); + }); + return bar; +} + const NEW_FOLDER_VALUE = "__new__"; // Every hand-drawn note (from here or measure.js's "Save as note") gets one @@ -67,16 +163,7 @@ export class NoteSaveForm { this._el.hidden = true; this._el.innerHTML = ` -
- -
- - ${PICKER_ICONS.map( - ([key, label]) => - ``, - ).join("")} -
-
+
@@ -88,27 +175,12 @@ export class NoteSaveForm { container.appendChild(this._el); this._title = this._el.querySelector(".notes-panel__title"); - this._iconPicker = this._el.querySelector(".notes-panel__icon-picker"); - this._iconFilter = this._el.querySelector(".notes-panel__icon-filter"); - this._iconFilter.addEventListener("input", () => { - const query = this._iconFilter.value.trim().toLowerCase(); - this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b) => { - b.hidden = query !== "" && !`${b.title} ${b.dataset.icon}`.toLowerCase().includes(query); - }); - }); + this._style = new PointStyleFields(this._el.querySelector(".notes-panel__style-slot"), { onIconChange: (icon) => this._onIconChange?.(icon) }); this._body = this._el.querySelector(".notes-panel__body"); + this._body.before(formatToolbar(this._body)); this._target = this._el.querySelector(".notes-panel__target"); this._newName = this._el.querySelector(".notes-panel__new-name"); this._saveButton = this._el.querySelector(".notes-panel__save"); - this._selectedIcon = ""; - - this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((button) => { - button.addEventListener("click", () => { - this._selectedIcon = button.dataset.icon; - this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b) => b.classList.toggle("active", b === button)); - this._onIconChange?.(this._selectedIcon); - }); - }); this._target.addEventListener("change", () => { this._newName.hidden = this._target.value !== NEW_FOLDER_VALUE; if (!this._newName.hidden) this._newName.focus(); @@ -126,17 +198,12 @@ export class NoteSaveForm { this._el.hidden = false; this._title.value = ""; this._body.value = ""; - this._selectedIcon = ""; - this._iconFilter.value = ""; - this._iconPicker.querySelectorAll(".notes-panel__icon-option").forEach((b, i) => { - b.classList.toggle("active", i === 0); - b.hidden = false; - }); - this._onIconChange?.(this._selectedIcon); + this._style.set(); + this._onIconChange?.(""); // An icon only makes sense on a single point — Measure's "Save as // note" can hand this a LineString/Polygon, which has no one spot for // a badge glyph to sit at. - this._iconPicker.hidden = geometry.type !== "Point"; + this._style.iconsVisible = geometry.type === "Point"; this._title.focus(); await this._populateTargets(); } @@ -192,10 +259,10 @@ export class NoteSaveForm { category: "Note", time: new Date().toISOString(), ...(details ? { description: details } : {}), - ...(this._selectedIcon ? { icon: this._selectedIcon } : {}), }, geometry: this._geometry, }; + this._style.applyTo(feature.properties); const intoLine = folder.startsWith("item:"); const requestBody = new URLSearchParams({ feature: JSON.stringify(feature), ...(intoLine ? {} : { folder }) });