2023-07-24 23:17:18 -05:00
|
|
|
import VectorLayer from 'ol/layer/Vector';
|
|
|
|
import {Vector as VectorSource} from 'ol/source.js';
|
|
|
|
|
|
|
|
import {Style} from 'ol/style.js';
|
|
|
|
import Icon from 'ol/style/Icon.js';
|
|
|
|
|
|
|
|
import pinURL from '/layers/chandler/pin.svg?url'; // TODO: remove `?url`?
|
|
|
|
import { Feature } from 'ol';
|
|
|
|
import { Point } from 'ol/geom';
|
|
|
|
import { fromLonLat } from 'ol/proj';
|
|
|
|
|
|
|
|
const res = await fetch("https://whereis.chandlerswift.com/api/0/last");
|
|
|
|
const locs = await res.json();
|
|
|
|
const loc = locs[0];
|
|
|
|
|
2024-02-02 03:33:09 -06:00
|
|
|
let feature = new Feature({
|
|
|
|
geometry: new Point(fromLonLat([loc.lon, loc.lat])),
|
|
|
|
...loc
|
|
|
|
});
|
2023-09-01 22:19:45 -05:00
|
|
|
|
2023-07-24 23:17:18 -05:00
|
|
|
const vectorLayer = new VectorLayer({
|
|
|
|
source: new VectorSource({
|
|
|
|
features: [
|
2024-02-02 03:33:09 -06:00
|
|
|
feature,
|
2023-07-24 23:17:18 -05:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
style: new Style({
|
|
|
|
image: new Icon({
|
|
|
|
anchor: [0.5, 1],
|
|
|
|
src: pinURL,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2023-09-01 22:19:45 -05:00
|
|
|
setInterval(async function(){
|
|
|
|
const res = await fetch("https://whereis.chandlerswift.com/api/0/last");
|
|
|
|
const locs = await res.json();
|
|
|
|
const loc = locs[0];
|
2024-02-02 03:33:09 -06:00
|
|
|
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]));
|
2023-09-01 22:19:45 -05:00
|
|
|
}, 10 * 1000);
|
|
|
|
|
2023-07-24 23:17:18 -05:00
|
|
|
export default vectorLayer;
|