-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.js
32 lines (25 loc) · 769 Bytes
/
script.js
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
mapboxgl.accessToken =
"pk.eyJ1Ijoid2ViZGV2c2ltcGxpZmllZCIsImEiOiJja2d1c2x2djAwODE1MnltaGNzeHljcWN4In0.4u6YymF-wOIYpDoUTMcNOQ"
navigator.geolocation.getCurrentPosition(successLocation, errorLocation, {
enableHighAccuracy: true
})
function successLocation(position) {
setupMap([position.coords.longitude, position.coords.latitude])
}
function errorLocation() {
setupMap([-2.24, 53.48])
}
function setupMap(center) {
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
center: center,
zoom: 15
})
const nav = new mapboxgl.NavigationControl()
map.addControl(nav)
var directions = new MapboxDirections({
accessToken: mapboxgl.accessToken
})
map.addControl(directions, "top-left")
}