2024-07-16 18:31:53 +02:00
|
|
|
import { initMarkers, createMarker } from "./markerHandler.js";
|
2024-06-30 22:56:19 +02:00
|
|
|
import { initEvents } from "./eventHandler.js";
|
|
|
|
import { mapInit } from "./mapInit.js";
|
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
let editMode = false;
|
2024-09-21 01:31:23 +02:00
|
|
|
let lastUpdateCheck = Date.now();
|
2024-06-30 22:56:19 +02:00
|
|
|
|
2024-09-21 01:11:50 +02:00
|
|
|
const map = mapInit();
|
2024-06-30 22:56:19 +02:00
|
|
|
|
2024-09-21 01:31:23 +02:00
|
|
|
initEvents(map);
|
2024-06-30 22:56:19 +02:00
|
|
|
|
2024-07-16 17:04:32 +02:00
|
|
|
async function fetchAllMarkers() {
|
2024-09-21 01:11:50 +02:00
|
|
|
const response = await fetch("/fetchMarkers");
|
2024-09-21 00:36:00 +02:00
|
|
|
|
|
|
|
let markers = await response.json();
|
|
|
|
console.log(markers);
|
|
|
|
markers.forEach((marker) => {
|
|
|
|
createMarker(marker, L, map);
|
|
|
|
});
|
2024-07-16 17:04:32 +02:00
|
|
|
}
|
|
|
|
|
2024-08-17 19:07:38 +02:00
|
|
|
export async function fetchNewMarkers() {
|
2024-09-21 01:11:50 +02:00
|
|
|
const searchParams = new URLSearchParams({ fromDate: lastUpdateCheck });
|
2024-07-16 17:04:32 +02:00
|
|
|
|
2024-09-21 01:11:50 +02:00
|
|
|
const response = await fetch(`/updateMarkers?${searchParams.toString()}`);
|
|
|
|
|
|
|
|
const markers = await response.json();
|
2024-07-16 17:04:32 +02:00
|
|
|
|
2024-09-21 00:36:00 +02:00
|
|
|
markers.forEach((marker) => {
|
|
|
|
createMarker(marker, L, map);
|
|
|
|
});
|
2024-07-17 12:00:34 +02:00
|
|
|
|
2024-09-21 01:31:23 +02:00
|
|
|
lastUpdateCheck = Date.now();
|
2024-06-30 22:56:19 +02:00
|
|
|
}
|
2024-09-21 01:11:50 +02:00
|
|
|
|
|
|
|
const main = async () => {
|
2024-09-21 01:31:23 +02:00
|
|
|
await fetchAllMarkers();
|
|
|
|
|
|
|
|
setInterval(fetchNewMarkers, 5000);
|
|
|
|
};
|
2024-09-21 01:11:50 +02:00
|
|
|
|
2024-09-21 01:31:23 +02:00
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
console.log("Completed");
|
|
|
|
})
|
|
|
|
.catch(console.error);
|