Search: highlight the found spot, open a waypoint's popup, full-height list

A point result (typed coordinates, a geocoded place, a waypoint) leaves
a pulsing marker on the map until the next jump or a click on it. A
result from a layer opens that point's popup as if clicked on the map.
The panel grows to the window height so long result lists fit.
This commit is contained in:
randy committed 2026-11-12 12:13:13 +01:00
1 parent 81e688be9b
commit ba9c40ac3d
4 files changed
+76 -17

No files matched your search

+27 -12
View File
@@ -485,11 +485,23 @@ export class GpxPanelControl {
// Called by the search box (search.js) when a result comes from a file
// that isn't shown yet — same as ticking its box in the tree by hand.
show(path) {
async show(path) {
if (this._visible.has(path)) return;
const checkbox = [...this._treeContainer.querySelectorAll("input[data-path]")].find((input) => input.dataset.path === path);
if (checkbox) checkbox.checked = true;
this._toggleFile(path, true, checkbox);
await this._toggleFile(path, true, checkbox);
}
// Search result picked: show its file, then open the matching point's
// popup as if it had been clicked on the map. Matched by exact
// coordinates (the search index reads the same GeoJSON); a track/line
// result has no popup to open, so it just shows the file.
async showFeature(path, [lng, lat]) {
await this.show(path);
const feature = this._pointsByPath
.get(path)
?.features.find((f) => f.geometry.coordinates[0] === lng && f.geometry.coordinates[1] === lat);
if (feature) this._openPointPopup(path, feature, [lng, lat]);
}
async _toggleFile(path, visible, checkbox) {
@@ -716,16 +728,7 @@ export class GpxPanelControl {
this._map.on("click", layerId, (event) => {
const feature = event.features[0];
if (!feature) return;
// properties.id is what update/delete target by — a note saved before
// that existed (see `rake gpx:backfill_note_ids`) doesn't have one
// yet, and offering Edit/Delete for it would just 404.
const editable = feature.properties.category === "Note" && !!feature.properties.id && isLoggedIn();
const popup = new Popup({ closeButton: true, maxWidth: "260px" })
.setLngLat(event.lngLat)
.setHTML(popupHtml(feature.properties, { editable }))
.addTo(this._map);
if (editable) this._wireNoteActions(popup, path, feature);
if (feature) this._openPointPopup(path, feature, event.lngLat);
});
this._map.on("mouseenter", layerId, () => {
this._map.getCanvas().style.cursor = "pointer";
@@ -735,6 +738,18 @@ export class GpxPanelControl {
});
}
_openPointPopup(path, feature, lngLat) {
// properties.id is what update/delete target by — a note saved before
// that existed (see `rake gpx:backfill_note_ids`) doesn't have one
// yet, and offering Edit/Delete for it would just 404.
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 }))
.addTo(this._map);
if (editable) this._wireNoteActions(popup, path, feature);
}
// 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
+1 -1
View File
@@ -571,7 +571,7 @@ gpxPanel.mount(sidebar);
const overlaysControl = new OverlaysControl(map);
overlaysControl.mount(sidebar);
searchControl.setLayerOpeners({
layers: (path) => gpxPanel.show(path),
layers: (path, result) => gpxPanel.showFeature(path, result.bbox.slice(0, 2)),
hiking_trails: (code) => overlaysControl.showHikingTrailsCountry(code),
});
pitchToggle.setOverlaysControl(overlaysControl);
+18 -3
View File
@@ -1,3 +1,4 @@
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { SEARCH_ICON } from "/js/icons.js";
import { escapeHtml } from "/js/gpx.js";
@@ -123,7 +124,7 @@ export class SearchControl {
name: result.name,
where: result.source_label,
bbox: result.bbox,
open: () => this._openers[result.source]?.(result.ref),
open: () => this._openers[result.source]?.(result.ref, result),
}));
} catch {
return [{ status: "Local search failed." }];
@@ -173,12 +174,26 @@ export class SearchControl {
});
}
// A point target (typed coordinates, a geocoded place, a waypoint) also
// gets a highlight marker so it's findable once the map stops moving —
// one at a time, cleared by the next jump or by clicking it.
_jumpTo({ lat, lng, bbox }) {
this._marker?.remove();
this._marker = null;
if (bbox && (bbox[0] !== bbox[2] || bbox[1] !== bbox[3])) {
this._map.fitBounds(bbox, { padding: 40, maxZoom: 15 });
} else {
const [x, y] = bbox || [lng, lat];
this._map.flyTo({ center: [x, y], zoom: Math.max(this._map.getZoom(), 14) });
const center = bbox ? bbox.slice(0, 2) : [lng, lat];
this._map.flyTo({ center, zoom: Math.max(this._map.getZoom(), 14) });
const el = document.createElement("div");
el.className = "search-highlight";
el.title = "Click to clear";
el.addEventListener("click", (event) => {
event.stopPropagation();
this._marker?.remove();
this._marker = null;
});
this._marker = new Marker({ element: el }).setLngLat(center).addTo(this._map);
}
this._panel.hidden = true;
this._button.classList.remove("active");