Make "find my location" actually follow GNSS, gated on the sidebar toggle
Two fixes based on feedback after the last commit: 1. The map wasn't following the position at all -- only the first fix recentered, later updates just moved the marker. Now every fix recenters (easeTo, not flyTo, after the first one, so it doesn't repeat that zoom swoop on every update) -- matches how GeolocateControl's own trackUserLocation always behaved. 2. GNSS should only be used when explicitly turned on via the sidebar "GNSS" icon, not whenever a receiver happens to have a fix -- simpler to test against the simulator that way, and puts the visitor in control of whether GNSS is engaged at all. GnssControl now owns following the map on its own (same flyTo-once/easeTo-after pattern) whenever it's enabled; LocateControl checks GnssControl#isEnabled() and, when true, just jumps to #getPosition()'s current fix and reuses its existing .gnss-marker instead of polling/marking on its own. Only falls back to the browser's own geolocation when GNSS is off. Verified end to end with the GNSS simulator: enabling sidebar GNSS recenters immediately and keeps following over several polls; clicking Locate while GNSS is on jumps to the same position without creating a second marker or touching its own active state; turning GNSS back off and clicking Locate correctly falls through to the browser geolocation path instead.
This commit is contained in:
1 parent
aec665179f
commit
6e5676c890
4 files changed
+93
-76
No files matched your search
+26
-17
@@ -229,20 +229,28 @@ may not even read the same way there.
|
||||
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.
|
||||
location" should mean that receiver, not a device's separate (and
|
||||
often less accurate, e.g. wifi-based) location service — but only
|
||||
once it's actually turned on, via the sidebar's "GNSS" icon
|
||||
(`GnssControl`, `public/js/gnss.js`), not just whenever a receiver
|
||||
happens to have a fix. `GnssControl` itself now recenters the map on
|
||||
every fix while enabled (`flyTo` for the first one, `easeTo` — a
|
||||
plainer follow, no zoom swoop — for each update after), the same way
|
||||
LocateControl's own browser-geolocation fallback follows below;
|
||||
clicking Locate while GNSS is already on just jumps to
|
||||
`GnssControl#getPosition()`'s current fix for the same instant
|
||||
feedback the button has always given, reusing its existing
|
||||
`.gnss-marker` rather than placing a second one — GNSS following the
|
||||
map is `GnssControl`'s job for as long as it's enabled, regardless of
|
||||
whether Locate was ever clicked. Both controls are constructed
|
||||
together in `map.js` (`GnssControl` first, `LocateControl` holding
|
||||
that same instance) specifically so `LocateControl` can call
|
||||
`isEnabled()`/`getPosition()` on it. Only when GNSS is off does
|
||||
Locate fall back to the browser's own
|
||||
`navigator.geolocation.watchPosition` — GeolocateControl's own
|
||||
mechanism — with its own toggle/marker/recentering-per-fix, since
|
||||
that's the one case this control does own the tracking itself;
|
||||
clicking again in that case stops the watch and removes the marker.
|
||||
|
||||
=== Debug inspector (Alt+click)
|
||||
|
||||
@@ -665,9 +673,10 @@ toggling is a cheap re-render of just that strip.
|
||||
|
||||
A "GNSS" map control (`public/js/gnss.js`) shows the fix from a local
|
||||
GNSS receiver (a real one, plugged into the machine running the
|
||||
server — distinct from `NavigationControl`'s browser
|
||||
`navigator.geolocation`, which the OS may or may not derive from such
|
||||
a receiver at all).
|
||||
server, or `bin/gnss_simulator.rb`'s simulated one — distinct from
|
||||
`LocateControl`'s browser-geolocation fallback, `navigator.geolocation`,
|
||||
which the OS may or may not derive from such a receiver at all —
|
||||
see "Finding your location" above).
|
||||
|
||||
`lib/maptool/gpsd_client.rb` is a small client for
|
||||
https://gpsd.io[gpsd]'s JSON protocol over TCP (port 2947 by default):
|
||||
|
||||
Reference in new issue
Block a user