-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
108 lines (74 loc) · 2.34 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
mapboxgl.accessToken =
"pk.eyJ1Ijoia2FwaWxiaGlzZSIsImEiOiJja2psMXV6ZnQwNDlqMnpsOXI5MTBvNmtxIn0.rSEXmuMHuTEohbUCUYpjaw";
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: 8,
});
const nav = new mapboxgl.NavigationControl();
map.addControl(nav);
var directions = new MapboxDirections({
accessToken: mapboxgl.accessToken,
});
map.addControl(directions, "top-left");
// Add geolocate control to the map.
map.addControl(
new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true,
},
trackUserLocation: true,
})
);
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl,
});
document.getElementById("geocoder").appendChild(geocoder.onAdd(map));
}
// const mapboxgl=require("react-map-gl");
// mapboxgl.accessToken =
// "pk.eyJ1Ijoia2FwaWxiaGlzZSIsImEiOiJja2dkNjBucjAwdTlrMnhxYXdoczM4dmloIn0.c_1C2Qk7UPsCmwdFlostzQ";
// 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");
// }
// var layerList = document.getElementById("menu");
// var inputs = layerList.getElementsByTagName("input");
// function switchLayer(layer) {
// var layerId = layer.target.id;
// map.setStyle("mapbox://styles/mapbox/" + layerId);
// }
// for (var i = 0; i < inputs.length; i++) {
// inputs[i].onclick = switchLayer;
// }