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:
1 parent
81e688be9b
commit
ba9c40ac3d
4 files changed
+76
-17
No files matched your search
+30
-1
@@ -1261,6 +1261,12 @@ html, body {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
||||
padding: 6px 8px;
|
||||
font-size: 13px;
|
||||
/* Grows with its results up to the window's height (it opens ~10px
|
||||
below the 44px topbar), then only the result list scrolls. */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: calc(100vh - 70px);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.search-panel[hidden] {
|
||||
@@ -1280,7 +1286,8 @@ html, body {
|
||||
list-style: none;
|
||||
margin: 6px 0 0;
|
||||
padding: 0;
|
||||
max-height: 220px;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@@ -1308,6 +1315,28 @@ html, body {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
/* Pulsing ring left on the map where a point search result landed. */
|
||||
.search-highlight {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: 3px solid #e2442f;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 0 2px #fff;
|
||||
cursor: pointer;
|
||||
animation: search-highlight-pulse 1.4s ease-out infinite;
|
||||
}
|
||||
|
||||
@keyframes search-highlight-pulse {
|
||||
0% { box-shadow: 0 0 0 2px #fff, 0 0 0 2px rgba(226, 68, 47, 0.6); }
|
||||
100% { box-shadow: 0 0 0 2px #fff, 0 0 0 16px rgba(226, 68, 47, 0); }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.search-highlight {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
.search-panel__where {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
|
||||
+27
-12
@@ -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
@@ -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
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user