Add properties to Chandler's location

main
Chandler Swift 2024-02-02 03:33:09 -06:00
parent 0c6f056543
commit 572a8c6d3c
Signed by: chandlerswift
GPG Key ID: A851D929D52FB93F
1 changed files with 7 additions and 5 deletions

View File

@ -13,14 +13,15 @@ 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])); let feature = new Feature({
geometry: new Point(fromLonLat([loc.lon, loc.lat])),
...loc
});
const vectorLayer = new VectorLayer({ const vectorLayer = new VectorLayer({
source: new VectorSource({ source: new VectorSource({
features: [ features: [
new Feature({ feature,
geometry: geometry,
})
] ]
}), }),
style: new Style({ style: new Style({
@ -35,7 +36,8 @@ setInterval(async function(){
const res = await fetch("https://whereis.chandlerswift.com/api/0/last"); 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];
geometry.setCoordinates(fromLonLat([loc.lon, loc.lat])); feature.setProperties(loc); // TODO: this won't remove a property if it was in a previous response but not this one
feature.getGeometry().setCoordinates(fromLonLat([loc.lon, loc.lat]));
}, 10 * 1000); }, 10 * 1000);
export default vectorLayer; export default vectorLayer;