fix(local-adsb): a double-click follows a local aircraft with its card again

Each aircraft was an entity, which the default renderer's double-click
followed, showing its tracked card; an aircraft that expired took the
follow with it. As a draw-port icon it took no part in it. A double-click
follow can now carry the holder whose entity record shows the card.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:12:14 -08:00
1 parent f2983e8c1a
commit 766cf68272
3 files changed
+71 -3

No files matched your search

+9 -3
View File
@@ -9,6 +9,7 @@
*/
import { followOffsetFitting } from '../geo/frames.js';
import { findCamera, findQuery } from '../render/rendererOf.js';
import { entityFollowTarget } from './followed.js';
/**
* Where the camera frames a part it starts following: `followOffsetFitting`
@@ -37,11 +38,13 @@ export function followViewFrom(sphere, at, camera) {
* @param {() => boolean} options.enabled Whether the layer takes clicks now.
* @param {(hit: import('../render/contract/query').Hit) =>
* ({key: string, position: () => ({x: number, y: number, z: number}|null),
* sphere?: {center: object, radius: number}}
* sphere?: {center: object, radius: number}, entity?: object}
* | {zoomTo: {center: object, radius: number}}
* | null)} options.targetFor What a hit on one of the layer's items is
* followed by (`key`, its live `position`, the bounds it is framed by,
* radius 0 by default), or zoomed to (`zoomTo`); null for anything else.
* radius 0 by default, and the holder whose entity record shows it, as
* `entityFollowTarget` reads one), or zoomed to (`zoomTo`); null for
* anything else.
* @returns {{readonly following: object|null, stop(): void, destroy(): void}}
*/
export function followOnDoubleClick({
@@ -77,7 +80,7 @@ export function followOnDoubleClick({
}
const at = found.position();
if (!at) return;
const target = {
const fields = {
key: found.key,
position: found.position,
frame: 'enu',
@@ -87,6 +90,9 @@ export function followOnDoubleClick({
camera,
),
};
const target = found.entity
? entityFollowTarget(found.entity, fields)
: fields;
camera.follow(target);
follow = target;
} catch (error) {
+26
View File
@@ -13,6 +13,7 @@ import {
findQuery,
} from '../../render/rendererOf.js';
import { inputFor } from '../../input/dispatcher.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
import { pickRenderAltitudeM } from '../../data/renderAltitude.js';
import { routePlausible } from '../../data/routePlausible.js';
import {
@@ -152,6 +153,8 @@ export function createLocalAdsbLayer({
let tickTimer = null;
let syncTimer = null;
let clickSubscription = null;
/** The follow a double-click on a marker started, while installed. */
let stockFollow = null;
let removePreRender = null;
let renderHeld = false;
let selectedId = null;
@@ -587,6 +590,9 @@ export function createLocalAdsbLayer({
if (ringsGone.length) sets.rings.remove(ringsGone);
// Expired aircraft take their 3D models (and pending loads) with them.
if (removed) models?.retain(markers);
// An aircraft that went took the follow a double-click gave it.
const followed = stockFollow?.following;
if (followed && !markers.has(followed.key)) stockFollow.stop();
if (selectedId && !live.has(selectedId))
clearSelection({ evicted: enabled });
removeEntityContextsForLayer(LAYER_ID, { retainIds: live });
@@ -692,6 +698,24 @@ export function createLocalAdsbLayer({
function installInteraction() {
if (clickSubscription || !viewer) return;
// A double-click follows a local aircraft, its card shown, as the
// default renderer followed its entity.
stockFollow = followOnDoubleClick({
viewer,
inputFor,
name: LAYER_ID,
enabled: () => enabled,
targetFor: (hit) => {
const marker =
!hit.surface && hit.set === sets?.markers.id && markers.get(hit.id);
if (!marker?.carrier) return null;
return {
key: marker.id,
position: () => (marker.position ? { ...marker.position } : null),
entity: marker.carrier,
};
},
});
clickSubscription = inputFor(viewer).onClick((event) => {
if (!enabled) return;
const target = clickTarget(event);
@@ -712,6 +736,8 @@ export function createLocalAdsbLayer({
}
function releaseInteraction() {
stockFollow?.destroy();
stockFollow = null;
clickSubscription?.();
clickSubscription = null;
}
+36
View File
@@ -1300,3 +1300,39 @@ test('a type change takes its belly offset with the new model, however soon it i
);
models.destroy();
});
test('a double-click follows a local aircraft with its card, until it goes, as its entity was', async (t) => {
const { bindRenderer } = await import('../../render/rendererOf.js');
const { createStubRenderer } = await import('../../render/stub/index.js');
const { followedOf } = await import('../../data/followed.js');
const renderer = createStubRenderer();
const viewer = { isDestroyed: () => false };
const unbind = bindRenderer(viewer, renderer);
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
const clock = { now: 100_000 };
const { layer } = await enabledLayer(receiver, clock, null, {
viewer: { viewer, draw: renderer.draw },
});
t.after(() => {
layer.destroy();
unbind();
renderer.destroy();
});
receiver.set({ aircraft: [record()] });
await layer.update();
const set = renderer.testing.sets().find((id) => id.endsWith(':markers'));
renderer.testing.scriptPicks(() => [
{ set, id: 'local-adsb:abc123', surface: false },
]);
renderer.testing.pointer('dblclick', 10, 10);
const followed = followedOf(viewer);
assert.ok(followed, 'the aircraft is followed');
assert.equal(followed.key, 'local-adsb:abc123');
assert.ok(followed.entity, 'its entity record shows the tracked card');
assert.equal(typeof followed.displayPosition, 'function');
assert.ok(followed.labelModel?.title, 'with its card');
receiver.set({ aircraft: [] });
clock.now += 10 * 60_000;
await layer.update();
assert.equal(followedOf(viewer), null, 'gone, it is no longer followed');
});