mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 04:16:24 -05:00
map: clicking a POI shows its kind, detail, elevation and coordinates (#738)
The Protomaps basemap keeps a few attributes per POI beyond the name the map already labels: kind, kind_detail and elevation. Clicking a POI now opens a popup with those, plus the feature's coordinates (or the click location when the feature has no point). The same POI appears at several min_zoom levels within one tile, so features are deduped by name and kind. Map popups (this one and the existing pin popup) now follow the active theme's tokens instead of MapLibre's fixed white, covering light, dark, night and amber. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
15d3792b0e
commit
4fea50943b
4 changed files with 187 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import {MAP_VIEWER_URI} from "./Vars";
|
|||
import {Button, Checkbox, Header, Icon, Panel, TextInput, Toggle} from "./ui";
|
||||
import {SettingsContext, ThemeContext} from "../contexts/contexts";
|
||||
import {mapFlavor, mapSprite} from "../themes/names";
|
||||
import {poiPopupHtml} from "./mapPoiPopup";
|
||||
|
||||
// Terrain DEM file prefix for hillshade and contours.
|
||||
const TERRAIN_PREFIX = "terrain-";
|
||||
|
|
@ -675,6 +676,29 @@ export default function MapViewer() {
|
|||
map.on("click", () => setContextMenu(null));
|
||||
map.on("movestart", () => setContextMenu(null));
|
||||
|
||||
// Click a POI to see the details the pmtiles file already has (kind, detail, elevation).
|
||||
const poiLayerIds = () => (map.getStyle()?.layers || [])
|
||||
.map(l => l.id)
|
||||
.filter(id => id === "pois" || id.endsWith(":pois"))
|
||||
.filter(id => map.getLayer(id));
|
||||
map.on("click", (e) => {
|
||||
if (destroyed) return;
|
||||
const layers = poiLayerIds();
|
||||
if (!layers.length) return;
|
||||
const html = poiPopupHtml(map.queryRenderedFeatures(e.point, {layers}), e.lngLat);
|
||||
if (!html) return;
|
||||
new maplibregl.Popup({offset: 8, maxWidth: "260px", className: "wrolpi-map-popup"})
|
||||
.setLngLat(e.lngLat)
|
||||
.setHTML(html)
|
||||
.addTo(map);
|
||||
});
|
||||
map.on("mousemove", (e) => {
|
||||
if (destroyed) return;
|
||||
const layers = poiLayerIds();
|
||||
const hit = layers.length && map.queryRenderedFeatures(e.point, {layers}).length;
|
||||
map.getCanvas().style.cursor = hit ? "pointer" : "";
|
||||
});
|
||||
|
||||
// Long-press context menu (mobile).
|
||||
let longPressTimer = null;
|
||||
let touchStartPos = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue