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

+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");