Prefer this app's own GNSS receiver for "find my location"
LocateControl (public/js/locate.js) replaces MapLibre's own GeolocateControl -- same button, reusing its exact CSS/icon so it's a visual drop-in, but sourced differently. Checks GET /api/gnss/position once on click: if a fix is available (gpsd, possibly bin/gnss_simulator.rb's simulated one), tracks that instead of the browser's separate (and often less accurate) location service, which is now only a fallback. Only the first fix recenters the map; later updates just move the marker, unlike GeolocateControl's own default of recentering on every update, which would fight a pan/zoom made in the meantime. Verified end to end with the GNSS simulator running: clicking the button centered on the simulated position and dropped a marker, clicking again cleared both, no console errors.
This commit is contained in:
1 parent
64a85afe6a
commit
aec665179f
3 files changed
+176
-17
No files matched your search
+31
-7
@@ -166,8 +166,8 @@ sits top-left on the map. It fits to `SLOVAKIA_BOUNDS` (a country-wide
|
||||
bounding box) rather than the plain `CENTER`/`ZOOM` point the map
|
||||
itself starts at — "home" is meant as a full-country overview, not a
|
||||
re-centering on Bratislava. It resets to that fixed default view, not
|
||||
the visitor's own location — that's `GeolocateControl`, a separate
|
||||
button in the same stack (below).
|
||||
the visitor's own location — that's `LocateControl`, a separate button
|
||||
in the same stack (below).
|
||||
|
||||
That Home button is the top of a small top-left stack — Home, zoom
|
||||
in/out (`NavigationControl`, `showCompass: false` since this map never
|
||||
@@ -175,11 +175,12 @@ rotates), a passive zoom-level readout (`ZoomLevelControl`, a plain div
|
||||
updated on the map's `zoom` event — not a button, since it has no
|
||||
click behavior of its own), a distance/area measuring tool
|
||||
(`MeasureControl`, `public/js/measure.js`), locate-me
|
||||
(`GeolocateControl`), and a "Base map" button — matching the National
|
||||
Park Service's own map control layout (grouped together on the map
|
||||
itself, rather than split across corners or between the map and a side
|
||||
panel). The last of those, `MapLayersButton` (`public/js/map.js`), is
|
||||
a second entry point into the exact same Online/Offline panel
|
||||
(`LocateControl`, `public/js/locate.js`), and a "Base map" button —
|
||||
matching the National Park Service's own map control layout (grouped
|
||||
together on the map itself, rather than split across corners or
|
||||
between the map and a side panel). The last of those,
|
||||
`MapLayersButton` (`public/js/map.js`), is a second entry point into
|
||||
the exact same Online/Offline panel
|
||||
`LayerToggleControl` already manages in the page's own sidebar — both
|
||||
call the same `LayerToggleControl#toggle()`, so there's one source of
|
||||
truth for the panel's open/closed state either way.
|
||||
@@ -220,6 +221,29 @@ long any one leg was on its own. Area mode has no equivalent yet;
|
||||
a polygon's edges are its perimeter, not a path, so the same treatment
|
||||
may not even read the same way there.
|
||||
|
||||
=== Finding your location
|
||||
|
||||
`LocateControl` (`public/js/locate.js`) replaces MapLibre's own
|
||||
`GeolocateControl` — same button, reusing its exact CSS classes/icon
|
||||
(`.maplibregl-ctrl-geolocate`) rather than a new one, so it's a visual
|
||||
drop-in — but sourced differently. This app has its own GNSS receiver
|
||||
(gpsd, possibly `bin/gnss_simulator.rb`'s simulated one — see
|
||||
`docs/development.adoc`/`docs/deployment.adoc`), and "find my
|
||||
location" should mean that receiver first, not a device's separate
|
||||
(and often less accurate, e.g. wifi-based) location service, when the
|
||||
receiver actually has a fix. Clicking it checks
|
||||
`GET /api/gnss/position` once: if `available`, it polls that
|
||||
endpoint (same 1.5s cadence as `GnssControl`'s own sidebar polling)
|
||||
and shows the fix with the same `.gnss-marker` styling that control
|
||||
uses; if not, it falls back to the browser's own
|
||||
`navigator.geolocation.watchPosition`, GeolocateControl's own
|
||||
mechanism. Either way, only the *first* fix recenters the map —
|
||||
later updates move the marker without fighting a pan/zoom the visitor
|
||||
made in the meantime, unlike GeolocateControl's own default of
|
||||
recentering on every update. Clicking again stops tracking (clears
|
||||
the poll timer or browser watch, whichever was active) and removes
|
||||
the marker.
|
||||
|
||||
=== Debug inspector (Alt+click)
|
||||
|
||||
Alt+click anywhere on the map opens a popup listing every rendered
|
||||
|
||||
Reference in new issue
Block a user