-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (46 loc) · 1.48 KB
/
script.js
File metadata and controls
55 lines (46 loc) · 1.48 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
// Connection with api / our python logic
try {
const ws = new WebSocket(
"wss://gannon-unfiscal-reactively.ngrok-free.dev/ws",
);
if (ws) {
ws.onmessage = (event) => {
showNotification();
};
}
} catch (err) {
console.log(err);
console.log("Websocket is not open");
}
const notification = document.getElementById("notification");
const request = document.getElementById("request");
const helpPersonBtn = document.getElementById("helpPersonBtn");
const crxCoordinates = [45.42193, -75.6817];
function showNotification(
message = "A user is requesting help!",
duration = 3000,
) {
notification.textContent = message;
notification.classList.remove("hidden");
request.classList.remove("hidden");
document.getElementById("no-requests").classList.add("hidden");
// Currently hardcoded the location of the client in need of help
L.marker(crxCoordinates)
.addTo(map)
.bindPopup("Person in need of help")
.openPopup();
map.setView(crxCoordinates, 18);
setTimeout(() => {
notification.classList.add("hidden");
}, duration);
}
helpPersonBtn.addEventListener("click", () => {
map.setView(crxCoordinates, 20);
});
// ############# MAP LOGIC ##############
const map = L.map("map").setView(crxCoordinates, 17);
// OpenStreetMap
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution: "© OpenStreetMap contributors",
}).addTo(map);