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
+11
-5
@@ -360,12 +360,18 @@ map.addControl(new HomeButton({ bounds: SLOVAKIA_BOUNDS }), "top-left");
|
||||
map.addControl(new NavigationControl({ showCompass: false }), "top-left");
|
||||
map.addControl(new ZoomLevelControl(), "top-left");
|
||||
map.addControl(new MeasureControl(), "top-left");
|
||||
// Constructed here (rather than down where it's mounted, alongside the
|
||||
// other sidebar controls) so LocateControl can hold the same instance —
|
||||
// its constructor only touches `map`, mount() (which needs the sidebar
|
||||
// element) can still happen later.
|
||||
const gnssControl = new GnssControl(map);
|
||||
// Not MapLibre's own GeolocateControl (browser Geolocation API only) —
|
||||
// this app has its own GNSS receiver (gpsd, possibly a simulated one, see
|
||||
// bin/gnss_simulator.rb) and "find my location" should prefer that over a
|
||||
// device's separate, often less accurate location service when it has a
|
||||
// fix. See locate.js.
|
||||
map.addControl(new LocateControl(), "top-left");
|
||||
// bin/gnss_simulator.rb), and "find my location" should prefer that over a
|
||||
// device's separate, often less accurate location service, but only once
|
||||
// the "GNSS" sidebar icon actually turns it on — not just whenever a
|
||||
// receiver happens to have a fix. See locate.js.
|
||||
map.addControl(new LocateControl(gnssControl), "top-left");
|
||||
|
||||
// A small inset map showing where the current view sits in context — NPS's
|
||||
// own overview plugin (docs/nps-resources.adoc's "overview" entry, still on
|
||||
@@ -398,7 +404,7 @@ const profilePanel = new TrackProfilePanel(map);
|
||||
profilePanel.mount();
|
||||
new GpxPanelControl(map, profilePanel).mount(sidebar);
|
||||
new RadarControl(map).mount(sidebar);
|
||||
new GnssControl(map).mount(sidebar);
|
||||
gnssControl.mount(sidebar);
|
||||
new LiveTrackPanelControl(map).mount(sidebar);
|
||||
|
||||
function applyStyle(name) {
|
||||
|
||||
Reference in new issue
Block a user