Add geolocate control to the map

Lets the user center the map on their current location, with an
accuracy circle and continuous tracking.
This commit is contained in:
randy committed 2026-08-25 15:18:55 +02:00
1 parent d813dd0b20
commit 008e034932
1 file changed
+9
+9
View File
@@ -1,6 +1,7 @@
import { import {
Map as MaplibreMap, Map as MaplibreMap,
NavigationControl, NavigationControl,
GeolocateControl,
addProtocol, addProtocol,
} from "/vendor/maplibre-gl/maplibre-gl.mjs"; } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { RadarControl } from "/js/radar.js"; import { RadarControl } from "/js/radar.js";
@@ -70,6 +71,14 @@ const map = new MaplibreMap({
}); });
map.addControl(new NavigationControl(), "top-right"); map.addControl(new NavigationControl(), "top-right");
map.addControl(
new GeolocateControl({
positionOptions: { enableHighAccuracy: true },
trackUserLocation: true,
showAccuracyCircle: true,
}),
"top-right",
);
map.addControl(new RadarControl(map), "top-right"); map.addControl(new RadarControl(map), "top-right");
const layerToggle = new LayerToggleControl(applyStyle); const layerToggle = new LayerToggleControl(applyStyle);