Following the GNSS receiver or the browser's own position turns the map heading-up in the 3D view, position in the lower part of the screen, like a car navigation
This commit is contained in:
1 parent
fdd77986c1
commit
e9c9e96b92
2 files changed
+19
-4
No files matched your search
+4
-3
@@ -1,4 +1,5 @@
|
||||
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { followPosition } from "/js/gnss.js";
|
||||
|
||||
// Replaces MapLibre's own GeolocateControl (browser Geolocation API only)
|
||||
// with one that prefers this app's own GNSS receiver when it's turned on
|
||||
@@ -105,7 +106,7 @@ export class LocateControl {
|
||||
this._active = true;
|
||||
this._button.classList.add("maplibregl-ctrl-geolocate-active");
|
||||
this._watchId = navigator.geolocation.watchPosition(
|
||||
(position) => this._setPosition(position.coords.longitude, position.coords.latitude, position.coords.accuracy),
|
||||
({ coords }) => this._setPosition(coords.longitude, coords.latitude, coords.accuracy, coords.heading, coords.speed),
|
||||
() => {
|
||||
window.alert("Could not determine your location.");
|
||||
this._stop();
|
||||
@@ -128,7 +129,7 @@ export class LocateControl {
|
||||
// .gnss-marker — reusing that green for a browser-estimated position too
|
||||
// looked like this control was somehow still using GNSS data even when
|
||||
// it very much wasn't; distinct colors for distinct sources.
|
||||
_setPosition(lon, lat, accuracy) {
|
||||
_setPosition(lon, lat, accuracy, heading, speed) {
|
||||
this._accuracy = accuracy;
|
||||
if (!this._marker) {
|
||||
const el = document.createElement("div");
|
||||
@@ -141,7 +142,7 @@ export class LocateControl {
|
||||
} else {
|
||||
this._marker.setLngLat([lon, lat]);
|
||||
this._circleMarker.setLngLat([lon, lat]);
|
||||
this._map.easeTo({ center: [lon, lat] });
|
||||
followPosition(this._map, [lon, lat], heading, speed);
|
||||
}
|
||||
this._updateCircleRadius();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user