diff --git a/src/layers/flights/queries.js b/src/layers/flights/queries.js index 7ebb9feb12..681db5c9cf 100644 --- a/src/layers/flights/queries.js +++ b/src/layers/flights/queries.js @@ -546,7 +546,9 @@ export function createQueries({ object._labelCallsign = callsign; object._labelRegistration = registration; } - const altitude = info?.altitude; + // A grounded contact shows no flight level: its sticky `altitude` may + // still be the approach height. + const altitude = info?.onGround ? 0 : info?.altitude; if (object._altitude !== altitude) { object._altitude = altitude; object.metric = formatFlightLevel(altitude); // altitude is metres diff --git a/src/layers/flights/records.js b/src/layers/flights/records.js index eeb25a8cc1..1f2922606e 100644 --- a/src/layers/flights/records.js +++ b/src/layers/flights/records.js @@ -232,7 +232,13 @@ export class FlightRecords { surfaceM = geoidSurfaceLastResortM({ geoAltM: geo_alt, baroAltM: baro_alt, - priorRenderM: prevMeta?.renderAltitudeM, + // Only a height held ON THE GROUND counts as prior: straight after a + // landing the previous render height is the approach height, and + // holding it left the plane hanging there until a cell warmed — + // forever for a contact far from the viewer, whose cell is never + // queued (HAL-1032). + priorRenderM: + prevMeta?.onGround === true ? prevMeta.renderAltitudeM : null, geoidN, }); } @@ -266,10 +272,15 @@ export class FlightRecords { let renderAltitudeM; if (pickedAltM != null) { renderAltitudeM = pickedAltM; - } else if (Number.isFinite(prevMeta?.renderAltitudeM)) { + } else if ( + Number.isFinite(prevMeta?.renderAltitudeM) && + (!onGround || prevMeta.onGround === true) + ) { renderAltitudeM = prevMeta.renderAltitudeM; } else { - renderAltitudeM = alt; + // A grounded contact with nothing better sits at 0 m: `alt` is sticky, + // so after a landing it still holds the approach altitude. + renderAltitudeM = onGround ? 0 : alt; } // Field-test fix (WAKE01/RS46 class, 2026-07-06; widened round 3): // floor a low airborne contact's render height at the local coarse diff --git a/src/layers/flights/records.test.mjs b/src/layers/flights/records.test.mjs index 9ec4b74679..fdf067c72f 100644 --- a/src/layers/flights/records.test.mjs +++ b/src/layers/flights/records.test.mjs @@ -112,16 +112,52 @@ test('civil record owners isolate state and preserve partial, missing-poll and l ); }); -test('ground transitions preserve last render height while a surface cell is cold', () => { +test('a landing with a cold surface cell sits on the geoid, not at its approach height', () => { const store = records(); + store.geoidReady = true; store.receive(observation({ ellipsoidAltitudeM: 1040 }), view()); + // Every grounded poll, not just the first: a contact far from the viewer + // never has its cell warmed (HAL-1032). + for (let poll = 0; poll < 3; poll += 1) { + const next = store.receive( + observation({ + onGround: true, + baroAltitudeM: null, + positionTimeMs: 1700000010000 + poll * 10000, + }), + view(), + ); + assert.equal(next.groundFlipped, poll === 0); + assert.equal(next.meta.renderAltitudeM, 40); + assert.equal(next.meta.wasAirborne, true); + } +}); + +test('a landing before the geoid loads sits at 0 m, not at its approach height', () => { + const store = records(); + store.receive(observation({ baroAltitudeM: 1539 }), view()); const next = store.receive( observation({ onGround: true, baroAltitudeM: null }), view(), ); - assert.equal(next.groundFlipped, true); - assert.equal(next.meta.renderAltitudeM, 1040); - assert.equal(next.meta.wasAirborne, true); + assert.equal(next.meta.renderAltitudeM, 0); +}); + +test('a parked contact whose surface cell goes cold holds its ground height', () => { + let floor = 312; + const store = new FlightRecords({ + geoidHeight: () => 40, + cachedGroundFloor: () => floor, + floorAltitudeM: (altitude) => altitude, + approxDistanceKm: () => 0, + fleetModels: () => null, + }); + store.geoidReady = true; + const grounded = () => + store.receive(observation({ onGround: true, baroAltitudeM: null }), view()); + assert.equal(grounded().meta.renderAltitudeM, 312); + floor = null; + assert.equal(grounded().meta.renderAltitudeM, 312); }); test('complete snapshots age out vanished aircraft and retain position-less ones unless landed', () => { diff --git a/src/layers/flights/tracking.js b/src/layers/flights/tracking.js index d4aa51a710..0ab27b03ea 100644 --- a/src/layers/flights/tracking.js +++ b/src/layers/flights/tracking.js @@ -900,13 +900,19 @@ export function createTracking({ // the ICAO hex, so a callsign-less enriched contact heads its readout with // the tail number rather than raw hex. const cs = parts.queries._contactLabel(icao24, info); - const altFt = Math.round((info.altitude || 0) * 3.28084); + const altFt = info.onGround + ? null + : Math.round((info.altitude || 0) * 3.28084); // Flight levels are an aviation code; feet and knots read in the active // language ("0 фт · 1 уз"). const quantity = (value, unit) => `${formatNumber(value, { useGrouping: false })} ${unitLabel(unit)}`; const fl = - altFt >= 18000 ? `FL${Math.round(altFt / 100)}` : quantity(altFt, 'ft'); + altFt == null + ? t('On the ground') + : altFt >= 18000 + ? `FL${Math.round(altFt / 100)}` + : quantity(altFt, 'ft'); const spd = info.velocity ? quantity(Math.round(info.velocity * 1.944), 'kts') : ''; @@ -1164,7 +1170,7 @@ export function createTracking({ // viewFrom — behind + above, distance scaled to altitude — for a readable // initial frame with surrounding context. (ENU: east=+X, north=+Y, up=+Z.) const followRange = Math.min( - Math.max((info.altitude || 1500) * 1.1 + 2500, 3000), + Math.max((info.onGround ? 0 : info.altitude || 1500) * 1.1 + 2500, 3000), 30000, ); const viewFrom = vec(0, -followRange * 0.8, followRange * 0.55); diff --git a/src/layers/military/queries.js b/src/layers/military/queries.js index 8b14315781..048b4d2a05 100644 --- a/src/layers/military/queries.js +++ b/src/layers/military/queries.js @@ -194,9 +194,12 @@ export function createQueries({ lon: num(info?.rawLon), // altitudeFt is the sticky barometric/MSL aviation field — converted to // meters here for shape parity with the flights layer. - altitudeM: Number.isFinite(info?.altitudeFt) - ? info.altitudeFt * 0.3048 - : null, + // A grounded contact reports only an altitude it gave on the ground. + altitudeM: info?.onGround + ? (info.groundAltitudeM ?? null) + : Number.isFinite(info?.altitudeFt) + ? info.altitudeFt * 0.3048 + : null, speedMps: num(info?.speedMps), heading: num(info?.track), verticalRateMps: num(info?.verticalRateMps), @@ -510,7 +513,9 @@ export function createQueries({ // TR-3B, not the airframe underneath it. const klass = tr3bTypeLabel(icao24, info?.type || 'MIL'); if (object.klass !== klass) object.klass = klass; - const altitudeFt = info?.altitudeFt ?? 0; + // A grounded contact shows no flight level, like the civil layer; its + // sticky altitudeFt may still be the approach height. + const altitudeFt = info?.onGround ? 0 : (info?.altitudeFt ?? 0); if (object._altitudeFt !== altitudeFt) { object._altitudeFt = altitudeFt; // military metadata stores altitudeFt (feet); the helper takes metres diff --git a/src/layers/military/records.js b/src/layers/military/records.js index 23581c3456..cefa1773da 100644 --- a/src/layers/military/records.js +++ b/src/layers/military/records.js @@ -70,19 +70,25 @@ export class MilitaryFlightRecords { this.missingPolls.delete(icao24); const prevMeta = this.data.get(icao24); // adsb.lol/readsb reports GROUND traffic as alt_baro === "ground" (no - // separate boolean). Grounded planes fall back to their last known - // altitude (field elevation is unknowable here), else 0 m — never the - // 3 km airborne default (a parked plane must not float). + // separate boolean). Grounded planes fall back to an altitude they + // reported while on the ground (field elevation is unknowable here), + // else 0 m — never the 3 km airborne default, and never the last + // AIRBORNE altitude: `altitudeFt` is sticky across the landing, so it + // still holds the approach height, and the icon would hang there while + // the ground-snapped model sits on the field (a parked plane must not + // float). `groundAltitudeM` is that ground-only altitude: set by a + // grounded report that carries one, held while grounded, dropped on + // takeoff. const onGround = aircraft.onGround; const altitudeFt = aircraft.baroAltitudeM == null ? null : aircraft.baroAltitudeM / 0.3048; + const groundAltitudeM = onGround + ? (aircraft.baroAltitudeM ?? + (prevMeta?.onGround === true ? prevMeta.groundAltitudeM : null) ?? + null) + : null; const altitudeM = - aircraft.baroAltitudeM ?? - (onGround - ? Number.isFinite(prevMeta?.altitudeFt) - ? prevMeta.altitudeFt * 0.3048 - : 0 - : 3048); + aircraft.baroAltitudeM ?? (onGround ? (groundAltitudeM ?? 0) : 3048); const verticalRateMps = aircraft.verticalRateMps; const callsign = aircraft.callsign; const type = aircraft.typeCode; @@ -198,6 +204,7 @@ export class MilitaryFlightRecords { registration: stickyText(registration, prevMeta?.registration), operator: stickyText(operator, prevMeta?.operator), altitudeFt: stickyNumber(altitudeFt, prevMeta?.altitudeFt, null), + groundAltitudeM, // geoAltitudeM/renderAltitudeM are ADDITIVE fields alongside the // untouched aviation `altitudeFt` — never rename/replace it (labels, // the FL readout, and the landed-fast-cull heuristic all still read diff --git a/src/layers/military/records.test.mjs b/src/layers/military/records.test.mjs index bbea594d87..9348574487 100644 --- a/src/layers/military/records.test.mjs +++ b/src/layers/military/records.test.mjs @@ -65,6 +65,52 @@ test('military ground records leave model-owned placement alone and warm the sam assert.deepEqual(unowned.floorWarmPoints, owned.floorWarmPoints); }); +test('a military contact that lands with no altitude sits on the ground, not at its last airborne height', () => { + for (const [modelOwnsVisual, expected] of [ + [false, 201.5], + [true, 0], + ]) { + const records = store(); + records.receive( + observation({ baroAltitudeM: 1539 }), + context({ modelOwnsVisual }), + ); + // Every grounded report, not just the first after the landing. + for (let poll = 0; poll < 3; poll += 1) { + const landed = records.receive( + observation({ onGround: true, baroAltitudeM: null, speedMps: 4.6 }), + context({ modelOwnsVisual }), + ); + assert.equal(landed.meta.renderAltitudeM, expected); + // The aviation readout keeps the last reported altitude, as before. + assert.equal(landed.meta.altitudeFt, 1539 / 0.3048); + } + } +}); + +test('a grounded military contact holds a ground altitude it reported earlier', () => { + const records = store(); + records.receive( + observation({ onGround: true, baroAltitudeM: 320 }), + context({ modelOwnsVisual: true }), + ); + for (let poll = 0; poll < 2; poll += 1) { + const next = records.receive( + observation({ onGround: true, baroAltitudeM: null }), + context({ modelOwnsVisual: true }), + ); + assert.equal(next.meta.renderAltitudeM, 320); + } + // Airborne again: that ground altitude is forgotten, so the next landing + // without an altitude starts from the ground, not from it. + records.receive(observation({ baroAltitudeM: 900 }), context()); + const relanded = records.receive( + observation({ onGround: true, baroAltitudeM: null }), + context({ modelOwnsVisual: true }), + ); + assert.equal(relanded.meta.renderAltitudeM, 0); +}); + test('military records keep bounded partial retention and release metadata only after removal admission', () => { const first = store(); const second = store(); diff --git a/src/layers/military/tracking.js b/src/layers/military/tracking.js index f1ffefcd7d..03e0c40b4c 100644 --- a/src/layers/military/tracking.js +++ b/src/layers/military/tracking.js @@ -365,7 +365,9 @@ export function createTracking({ parts.queries._toCleanText(info?.registration) || t('Reg unknown'); const operator = parts.queries._toCleanText(info?.operator) || t('Operator unknown'); - const altitude = parts.queries._formatAltitude(info?.altitudeFt); + const altitude = info?.onGround + ? t('On the ground') + : parts.queries._formatAltitude(info?.altitudeFt); const speedKt = info?.speedMps ? Math.round(info.speedMps * 1.944) : null; const tail = speedKt ? `${altitude} · ${speedKt} kt` : altitude; return [ @@ -1124,7 +1126,11 @@ export function createTracking({ // renderer's default follow distance is far too tight. It gets a calibrated // viewFrom — behind + above, distance scaled to altitude — for a readable // initial frame with surrounding context. (ENU: east=+X, north=+Y, up=+Z.) - const altM = info?.altitudeFt ? info.altitudeFt * 0.3048 : 1500; + const altM = info?.onGround + ? 0 + : info?.altitudeFt + ? info.altitudeFt * 0.3048 + : 1500; const followRange = Math.min(Math.max(altM * 1.1 + 2500, 3000), 30000); const viewFrom = vec(0, -followRange * 0.8, followRange * 0.55);