diff --git a/src/layers/flights/motion.test.mjs b/src/layers/flights/motion.test.mjs index 2ea413a41a..3fd23d7f15 100644 --- a/src/layers/flights/motion.test.mjs +++ b/src/layers/flights/motion.test.mjs @@ -399,14 +399,20 @@ test('an aircraft fix is told to the placement live, with its drawn height', () 'aircraft', ); const state = { timeline: { active: () => false } }; - const meta = { rawLat: 1, rawLon: 2, renderAltitudeM: 300, onGround: false }; + const meta = { + rawLat: 1, + rawLon: 2, + renderAltitudeM: 300, + groundM: 1656, + onGround: false, + }; observeLiveAircraft(state, placement, 'abc123', 5000, meta, 80, 270); observeLiveAircraft( state, placement, 'abc123', 6000, - { ...meta, renderAltitudeInvented: true, onGround: true }, + { ...meta, renderAltitudeInvented: true, groundM: null, onGround: true }, null, undefined, ); @@ -421,12 +427,15 @@ test('an aircraft fix is told to the placement live, with its drawn height', () lat: 1, lon: 2, altitudeM: 300, + groundM: 1656, speedMps: 80, courseDeg: 270, headingDeg: NaN, onGround: false, }, ]); + // Where the layer does not know the ground, it says so. + assert.ok(Number.isNaN(told[1][1].groundM)); assert.ok(Number.isNaN(told[1][1].altitudeM)); assert.ok(Number.isNaN(told[1][1].speedMps)); assert.ok(Number.isNaN(told[1][1].courseDeg)); diff --git a/src/layers/flights/placed.js b/src/layers/flights/placed.js index f9fa2bd92f..b17afb678c 100644 --- a/src/layers/flights/placed.js +++ b/src/layers/flights/placed.js @@ -95,13 +95,15 @@ export function forgetPlacedAircraft(placement, ids) { * Tell the host-supplied placement an aircraft's fix as the layer took it * (nothing while the layer follows the world clock): its own time, its * position, the height the layer draws it at (NaN when that height is - * invented), and its reported speed, course and ground state. + * invented), the ground under it in that height's reference (NaN where the + * layer does not know it), and its reported speed, course and ground state. * @param {object} flightState * @param {object|null|undefined} placement * @param {string} icao24 * @param {number} fixEpochMs * @param {{rawLat: number, rawLon: number, renderAltitudeM: number, - * renderAltitudeInvented?: boolean, onGround?: boolean}} meta + * renderAltitudeInvented?: boolean, groundM?: number|null, + * onGround?: boolean}} meta * @param {number|null|undefined} speedMps * @param {number|null|undefined} courseDeg */ @@ -121,6 +123,7 @@ export function observeLiveAircraft( lon: meta.rawLon, altitudeM: meta.renderAltitudeInvented === true ? NaN : meta.renderAltitudeM, + groundM: Number.isFinite(meta.groundM) ? meta.groundM : NaN, speedMps: Number.isFinite(speedMps) ? speedMps : NaN, courseDeg: Number.isFinite(courseDeg) ? courseDeg : NaN, headingDeg: NaN, diff --git a/src/layers/flights/records.js b/src/layers/flights/records.js index 1c5ca6c538..9b4653330c 100644 --- a/src/layers/flights/records.js +++ b/src/layers/flights/records.js @@ -283,6 +283,10 @@ export class FlightRecords { // within GROUND_FLOOR_CLAMP_RADIUS_KM of the viewer — the only ones // whose burial is visible. Cells warm in one batch after the loop. // Airborne only (grounded planes keep the surface-cache path above). + // The ground under the contact in its render height's reference, where + // the warm cache knows it: the surface it stands on, or the floor under a + // low contact near the view. A landing is judged above it. + let groundM = onGround ? surfaceM : null; if ( !onGround && renderAltitudeM < GROUND_FLOOR_WARM_MAX_ALT_M && @@ -291,10 +295,8 @@ export class FlightRecords { approxDistanceKm(viewerLatDeg, viewerLonDeg, lat, lon) <= GROUND_FLOOR_CLAMP_RADIUS_KM)) ) { - renderAltitudeM = floorAltitudeM( - renderAltitudeM, - cachedGroundFloor(lat, lon), - ); + groundM = cachedGroundFloor(lat, lon); + renderAltitudeM = floorAltitudeM(renderAltitudeM, groundM); floorWarmPoints.push({ lat, lon }); } @@ -334,6 +336,7 @@ export class FlightRecords { geoAltitudeM, renderAltitudeM, renderAltitudeInvented, + groundM: Number.isFinite(groundM) ? groundM : null, onGround, // Round 7: sticky airborne history — the landed fast-cull only // applies to contacts that actually flew this session. diff --git a/src/layers/flights/records.test.mjs b/src/layers/flights/records.test.mjs index d3a7ddcee0..9ec4b74679 100644 --- a/src/layers/flights/records.test.mjs +++ b/src/layers/flights/records.test.mjs @@ -515,3 +515,38 @@ test('a contact reported with no course faces the way its newer fixes went', () taxi(30.188, 20); assert.equal(course(), 0); }); + +test('a low contact near the view carries the ground under it; others carry none', () => { + const store = new FlightRecords({ + geoidHeight: () => 40, + cachedGroundFloor: () => 1656, + floorAltitudeM: (altitude, ground) => + Math.max(altitude, ground ?? -Infinity), + fleetModels: () => null, + }); + const denver = { latitude: 39.85, longitude: -104.67 }; + const near = { ...view(), viewerLatDeg: 39.8, viewerLonDeg: -104.7 }; + // Landing at Denver: 1,900 m above the ellipsoid over 1,656 m ground. + const landing = store.receive( + observation({ id: 'l1', ...denver, ellipsoidAltitudeM: 1900 }), + near, + ).meta; + assert.equal(landing.groundM, 1656); + // At cruise the ground is not read. + const cruise = store.receive( + observation({ + id: 'c1', + ...denver, + ellipsoidAltitudeM: 11000, + baroAltitudeM: 11000, + }), + near, + ).meta; + assert.equal(cruise.groundM, null); + // Nor without a view to be near. + const away = store.receive( + observation({ id: 'a1', ...denver, ellipsoidAltitudeM: 1900 }), + view(), + ).meta; + assert.equal(away.groundM, null); +});