-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
164 lines (143 loc) · 5.32 KB
/
script.js
File metadata and controls
164 lines (143 loc) · 5.32 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const menudiv = document.getElementById('menudiv');
const menuItems = document.getElementById('menuitems');
const mainButton = document.querySelector('#menu');
const friendButton = document.querySelector('.fa-user-friends')
const infopane = document.querySelector('#info')
const loading = document.getElementById("loading")
mainButton.addEventListener('click', call911);
friendButton.addEventListener('click', call911);
mainButton.addEventListener('mouseover', showMenu);
mainButton.addEventListener('touchstart', showMenu);
menudiv.addEventListener('mouseleave', hideMenu);
function showMenu() {
menudiv.style.display = "block";
}
function hideMenu() {
menudiv.style.display = "none";
}
function call911(e) {
console.log(e.target.innerHTML);
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic QUMxYmY4ZjljMmM1N2Y5MzkzZjRmNGRjNzFiMWE4YTY3ZjozNzQ2YWJlOGIwOTllNDE3ZWVjNDI3NmZlNTg5ZGM0Nw==");
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append('Url', 'https://raw.githubusercontent.com/TonyxSun/mapbox/master/voice.xml');
urlencoded.append("To", "+16812990111");
urlencoded.append("From", "+12264077191");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("https://api.twilio.com/2010-04-01/Accounts/AC1bf8f9c2c57f9393f4f4dc71b1a8a67f/Calls.json", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
loading.style.display = 'block';
setTimeout(function () {
loading.style.display = 'none';
getRoute([-79.386871, 43.659225]);
}, 10000);
}
mapboxgl.accessToken = 'pk.eyJ1IjoidG9ueXhzdW4iLCJhIjoiY2t6MDJqazd4MTg2ZzJxcDFlM2g4djg0ciJ9.GY5feDZWRZ6GsVKc-N1W_A'; //Mapbox token
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11', // style: https://docs.mapbox.com/api/maps/#styles
center: [-76.49500, 44.22500], // starting position [lng, lat]
zoom: 14,// starting zoom
// transformRequest: transformRequest
});
// Add geolocate control to the map.
var geolocate = new mapboxgl.GeolocateControl();
map.addControl(geolocate);
let lon = 0;
let lat = 0;
let position = geolocate.on('geolocate', function (e) {
var lon = e.coords.longitude;
var lat = e.coords.latitude;
start = [lon, lat]
});
let start = [-76.49500, 44.22500];
// create a function to make a directions request
async function getRoute(end) {
// make a directions request using cycling profile
// an arbitrary start will always be the same
// only the end or destination will change
const query = await fetch(
`https://api.mapbox.com/directions/v5/mapbox/driving/${start[0]},${start[1]};${end[0]},${end[1]}?steps=true&geometries=geojson&access_token=${mapboxgl.accessToken}`,
{ method: 'GET' }
);
const json = await query.json();
const data = json.routes[0];
const route = data.geometry.coordinates;
const geojson = {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: route
}
};
// if the route already exists on the map, we'll reset it using setData
if (map.getSource('route')) {
map.getSource('route').setData(geojson);
}
// otherwise, we'll make a new request
else {
map.addLayer({
id: 'route',
type: 'line',
source: {
type: 'geojson',
data: geojson
},
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#3887be',
'line-width': 5,
'line-opacity': 0.75
}
});
}
// get the sidebar and add the info
const info = document.getElementById('info');
let responder = '<img id="truck" src="./assets/truck.png" alt="truck" /><br><br> <h2>Responding:</h2><strong>\n\nTruck 81</strong><br><sub>Social Credit: 2200</sub>';
info.innerHTML = `<img id="siren" src="./assets/siren.png" alt="siren" /><br><br> <h2>Help is coming</h2><sub>Time</sub><br><strong>${Math.floor(
data.duration / 60
)} minutes </strong> <br> <sub> Distance </sub><br> <strong>${Math.floor(data.distance / 10) / 100} km </strong> <br><br><br><br><br>` + responder;
info.style.display = 'block';
}
function directions() {
// make an initial directions request that
// starts and ends at the same location
getRoute(start);
// Add starting point to the map
map.addLayer({
id: 'point',
type: 'circle',
source: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: start
}
}
]
}
},
paint: {
'circle-radius': 10,
'circle-color': '#3887be'
}
});
};