import { initMarkers, createMarker } from "./markerHandler.js"; import { initEvents } from "./eventHandler.js"; import { mapInit } from "./mapInit.js"; let editMode = false; let lastUpdateCheck = Date.now(); const map = mapInit(); initEvents(map); async function fetchAllMarkers() { const response = await fetch("/fetchMarkers"); let markers = await response.json(); console.log(markers); markers.forEach((marker) => { createMarker(marker, L, map); }); } export async function fetchNewMarkers() { const searchParams = new URLSearchParams({ fromDate: lastUpdateCheck }); const response = await fetch(`/updateMarkers?${searchParams.toString()}`); const markers = await response.json(); markers.forEach((marker) => { createMarker(marker, L, map); }); lastUpdateCheck = Date.now(); } const main = async () => { await fetchAllMarkers(); setInterval(fetchNewMarkers, 5000); }; main() .then(() => { console.log("Completed"); }) .catch(console.error);