-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (27 loc) · 907 Bytes
/
Copy pathscript.js
File metadata and controls
33 lines (27 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const MAPBOX_ACCESS_TOKEN =
"pk.eyJ1IjoibnN1bmFtaSIsImEiOiJjbHM5Y2dsNHkwMmlsMm5vNm16eDZmbGJlIn0.nh_8PWUFOjNvCcKrMQETcA"
navigator.geolocation.getCurrentPosition(successLocation, errorLocation, {
enableHighAccuracy: true,
})
function setupMap(centerPosition) {
const map = new mapboxgl.Map({
accessToken: MAPBOX_ACCESS_TOKEN,
container: "map",
style: "mapbox://styles/mapbox/navigation-night-v1",
center: centerPosition,
zoom: 13,
})
const navigationControls = new mapboxgl.NavigationControl()
map.addControl(navigationControls, "top-right")
const directionControls = new MapboxDirections({
accessToken: MAPBOX_ACCESS_TOKEN,
})
map.addControl(directionControls, "top-left")
}
function successLocation(position) {
setupMap([position.coords.longitude, position.coords.latitude])
console.log(position)
}
function errorLocation() {
setupMap([5.31, 51.68])
}