Fixed plane trace history

This commit is contained in:
2026-09-11 10:36:33 -04:00
parent 7cc60afbae
commit 688552d0d3

View File

@@ -116,9 +116,9 @@ export class AirTrafficLayer {
const j = await fetch(`${API}/adsb/${icao}`).then(r => r.json()) const j = await fetch(`${API}/adsb/${icao}`).then(r => r.json())
this.historyCache[icao] = j.history || [] this.historyCache[icao] = j.history || []
} }
const history = [...this.historyCache[icao]] const history = this.historyCache[icao]
const cur = { latitude: plane.latitude, longitude: plane.longitude, altitude: plane.alt_baro ?? plane.alt_geom ?? 0 } const cur = { latitude: plane.latitude, longitude: plane.longitude, altitude: plane.alt_baro ?? plane.alt_geom ?? 0 }
const last = history[history.length - 1] const last = history[history.length - 1]
if (!last || last.latitude !== cur.latitude || last.longitude !== cur.longitude) history.push(cur) if (!last || last.latitude !== cur.latitude || last.longitude !== cur.longitude) history.push(cur)
if (history.length < 2) return if (history.length < 2) return
@@ -133,11 +133,12 @@ export class AirTrafficLayer {
this.traceSegs[icao] = [] this.traceSegs[icao] = []
} else { } else {
vs = traceLayer.getSource()! vs = traceLayer.getSource()!
;(this.traceSegs[icao] || []).forEach(f => vs.removeFeature(f))
} }
const segs: Feature[] = [] // Only draw segments that haven't been drawn yet
for (let i = 0; i < history.length - 1; i++) { const segs = <any>this.traceSegs[icao]
const start = segs.length
for (let i = start; i < history.length - 1; i++) {
const s = history[i], e = history[i + 1] const s = history[i], e = history[i + 1]
const sc = getAltColor(s.altitude || 0) const sc = getAltColor(s.altitude || 0)
const ec = getAltColor(e.altitude || 0) const ec = getAltColor(e.altitude || 0)
@@ -147,7 +148,6 @@ export class AirTrafficLayer {
vs.addFeature(f) vs.addFeature(f)
segs.push(f) segs.push(f)
} }
this.traceSegs[icao] = segs
} }
private _calcPopupPos(plane: any): { x: number; y: number } { private _calcPopupPos(plane: any): { x: number; y: number } {