Autorefresh Chandler location every 10 seconds

This commit is contained in:
Chandler Swift 2023-09-01 22:19:45 -05:00
parent bd31c08c16
commit ac2728b393
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F

View file

@ -13,11 +13,13 @@ const res = await fetch("https://whereis.chandlerswift.com/api/0/last");
const locs = await res.json(); const locs = await res.json();
const loc = locs[0]; const loc = locs[0];
let geometry = new Point(fromLonLat([loc.lon, loc.lat]));
const vectorLayer = new VectorLayer({ const vectorLayer = new VectorLayer({
source: new VectorSource({ source: new VectorSource({
features: [ features: [
new Feature({ new Feature({
geometry: new Point(fromLonLat([loc.lon, loc.lat])), geometry: geometry,
}) })
] ]
}), }),
@ -29,4 +31,11 @@ const vectorLayer = new VectorLayer({
}), }),
}); });
setInterval(async function(){
const res = await fetch("https://whereis.chandlerswift.com/api/0/last");
const locs = await res.json();
const loc = locs[0];
geometry.setCoordinates(fromLonLat([loc.lon, loc.lat]));
}, 10 * 1000);
export default vectorLayer; export default vectorLayer;