Add Chandler layer

Also enable es2022 to allow top-level await (supported by 2021-era+
browsers)
This commit is contained in:
Chandler Swift 2023-07-24 23:17:18 -05:00
parent be8cf4e5f0
commit 066315f36a
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
4 changed files with 55 additions and 0 deletions

32
layers/chandler/layer.js Normal file
View file

@ -0,0 +1,32 @@
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];
const vectorLayer = new VectorLayer({
source: new VectorSource({
features: [
new Feature({
geometry: new Point(fromLonLat([loc.lon, loc.lat])),
})
]
}),
style: new Style({
image: new Icon({
anchor: [0.5, 1],
src: pinURL,
}),
}),
});
export default vectorLayer;