ruscomap/public/js/map.js

43 lines
996 B
JavaScript

import { initMarkers, createMarker } from "./markerHandler.js";
import { initEvents } from "./eventHandler.js";
import { mapInit } from "./mapInit.js";
let editMode = false
let map = mapInit()
let lastUpdateCheck = new Date().getTime();
// initMarkers(markerPopupExample, L, map);
initEvents(map);
await fetchAllMarkers();
setInterval(fetchNewMarkers, 5000)
async function fetchAllMarkers() {
let response = await fetch('/fetchMarkers', {
method: 'GET',
})
let markers = await response.json()
console.log(markers)
markers.forEach(marker => {
createMarker(marker, L, map);
});
}
export async function fetchNewMarkers() {
let response = await fetch('/updateMarkers?' + new URLSearchParams({ fromDate: lastUpdateCheck }), {
method: 'GET',
})
let markers = await response.json()
console.log(markers)
markers.forEach(marker => {
createMarker(marker, L, map);
});
lastUpdateCheck = new Date().getTime();
}