ADSB updates

This commit is contained in:
2026-06-25 09:13:16 -04:00
parent e91876b7b7
commit 19d2dd2d9d
3 changed files with 53 additions and 59 deletions

View File

@@ -213,7 +213,7 @@ export class AirTrafficLayer {
if (this.visible) return
this.visible = true
if (!this.shapes) this.shapes = await fetch(`${API}/air-traffic-shapes`).then(r => r.json())
if (!this.shapes) this.shapes = await fetch(`${API}/vehicles`).then(r => r.json())
this.layer = new VectorLayer({ source: new VectorSource(), zIndex: 100 })
this.map.addLayer(this.layer)
@@ -226,7 +226,7 @@ export class AirTrafficLayer {
await this._fetch()
this._draw()
this._refreshPopups()
}, 15_000)
}, 1_000)
}
hide() {
@@ -247,7 +247,7 @@ export class AirTrafficLayer {
// ── Private ───────────────────────────────────────────────────────────────
private async _fetch() {
const j = await fetch(`${API}/air-traffic`).then(r => r.json())
const j = await fetch(`${API}/adsb`).then(r => r.json())
this.data = (j.data || []).map((a: any) => ({
...a,
icao: a.hex,
@@ -261,47 +261,31 @@ export class AirTrafficLayer {
}
private _draw() {
const source = this.layer.getSource()!
const existing: Record<string, Feature> = {}
source.getFeatures().forEach(f => { existing[f.get('icao')] = f })
const incoming = new Set(this.data.filter(p => p.latitude != null).map(p => p.icao))
const source = this.layer.getSource()!
source.clear()
// Remove stale
Object.keys(existing).forEach(icao => {
if (!incoming.has(icao)) { source.removeFeature(<any>existing[icao]); this._closePopup(icao) }
})
// Update / add
for (const plane of this.data) {
if (plane.latitude == null) continue
const coord = fromLonLat([plane.longitude, plane.latitude])
const style = new Style({
const f = new Feature({ geometry: new Point(coord) })
f.set('icao', plane.icao)
f.set('planeData', plane)
f.setStyle(new Style({
image: new Icon({
src: buildPlaneIcon(plane, this.shapes),
scale: 1,
rotation: (plane.heading ?? 0) * (Math.PI / 180),
anchor: [0.5, 0.5],
}),
})
if (existing[plane.icao]) {
;(<any>((<any>existing[plane.icao]).getGeometry() as Point)).setCoordinates(coord)
(<any>existing[plane.icao]).setStyle(style)
(<any>existing[plane.icao]).set('planeData', plane)
} else {
const f = new Feature({ geometry: new Point(coord) })
f.set('icao', plane.icao)
f.set('planeData', plane)
f.setStyle(style)
source.addFeature(f)
}
}))
source.addFeature(f)
}
}
private async _fetchTrace(plane: any) {
const icao = plane.icao
if (!this.historyCache[icao]) {
const j = await fetch(`${API}/air-traffic/${icao}`).then(r => r.json())
const j = await fetch(`${API}/adsb/${icao}`).then(r => r.json())
this.historyCache[icao] = j.history || []
}