micodus_server/html/old/engine.js

44 lines
901 B
JavaScript

let map;
let circle;
function update() {
get_data().then(c=> {
const d = [c.latitude,c.longitude];
if (!map) {
map = L.map('map', {
center: d,
zoom: 13
});
L.tileLayer(`https://tile.openstreetmap.org/{z}/{x}/{y}.png`, {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
}
if (circle) {
circle.remove();
circle=null;
}
if (circle == null) {
circle = L.circle(d, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 50
}).addTo(map).bindPopup('I\'m here.');
}
});
}
function get_data() {
const res = fetch("lastloc.json").then((a)=> {
const b = a.json().then((j) => {
return j;
})
return b;
})
return res;
}
update();
setInterval(update,10000);