|
|
@@ -1,20 +1,82 @@
|
|
|
"use strict";
|
|
|
|
|
|
-let map = undefined;
|
|
|
+let dashboard = undefined;
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
|
- map = L.map('map', {
|
|
|
- center: [53.2212, 6.5586],
|
|
|
- zoom: 16,
|
|
|
- minZoom: 15,
|
|
|
- maxZoom: 17,
|
|
|
- maxBounds: [
|
|
|
- [53.2338, 6.5083],
|
|
|
- [53.2005, 6.6031]
|
|
|
- ]
|
|
|
- });
|
|
|
-
|
|
|
- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
- attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
|
- maxZoom: 17
|
|
|
- }).addTo(map);
|
|
|
+ dashboard = new Dashboard();
|
|
|
});
|
|
|
+
|
|
|
+class Dashboard {
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ this.markers = [];
|
|
|
+ this.map = this.initMap();
|
|
|
+ setInterval(() => this.updateTeams(), 3000)
|
|
|
+ console.log("puzzeltocht dashboard initialised");
|
|
|
+ }
|
|
|
+
|
|
|
+ initMap() {
|
|
|
+ let map = L.map('map', {
|
|
|
+ center: [53.2212, 6.5586],
|
|
|
+ zoom: 16,
|
|
|
+ minZoom: 15,
|
|
|
+ maxZoom: 18,
|
|
|
+ maxBounds: [
|
|
|
+ [53.2338, 6.5083],
|
|
|
+ [53.2005, 6.6031]
|
|
|
+ ]
|
|
|
+ });
|
|
|
+
|
|
|
+ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
+ attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
|
+ maxZoom: 18
|
|
|
+ }).addTo(map);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateTeams() {
|
|
|
+ FetchJson.get("/api/dashboard/teams")
|
|
|
+ .then(m => {
|
|
|
+ this.showTeams(m);
|
|
|
+ this.updateMarkers(m);
|
|
|
+ })
|
|
|
+ .catch(console.log);
|
|
|
+ }
|
|
|
+
|
|
|
+ showTeams(teams) {
|
|
|
+ let teamlist = '';
|
|
|
+ teams.forEach(t => {
|
|
|
+ teamlist += '<li>' + t.name + ' - ' + t.mission
|
|
|
+ + ' (' + t.location.latitude + ', ' + t.location.longitude + ') </li>';
|
|
|
+ });
|
|
|
+ document.getElementById("teamlist").innerHTML = teamlist;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateMarkers(teams) {
|
|
|
+ this.markers.forEach(m => m.remove());
|
|
|
+ this.markers = [];
|
|
|
+ teams.forEach(t => {
|
|
|
+ if (t.location !== null) {
|
|
|
+ let marker = L.marker([t.location.latitude, t.location.longitude]).addTo(this.map);
|
|
|
+ marker.bindPopup(t.name).openPopup();
|
|
|
+ this.markers.push(marker);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+class FetchJson {
|
|
|
+
|
|
|
+ static get(url) {
|
|
|
+ return fetch(url, {method: "GET"})
|
|
|
+ .then(FetchJson.responseBody)
|
|
|
+ }
|
|
|
+
|
|
|
+ static responseBody(r) {
|
|
|
+ if (!r.ok) {
|
|
|
+ throw Error("HTTP " + r.status + " " + r.statusText + " " + r.url);
|
|
|
+ }
|
|
|
+ return r.json();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|