fix(local-adsb): a tap selects only an aircraft exactly under it again

A click read the scene's exact pick and a drill at the tap. Through the
input dispatcher it read the click's id, which on a touch screen comes
from the wider contact search: a tap near a local aircraft selected it,
and one near another layer's contact kept the selection. It reads the
exact top hit again, as the shipwrecks layer does.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:49:17 -08:00
1 parent 805c9b5ccd
commit cbc0c114eb
2 files changed
+42 -4

No files matched your search

+10 -4
View File
@@ -654,10 +654,16 @@ export function createLocalAdsbLayer({
const top = event.drawHit; const top = event.drawHit;
const own = ownHit(top); const own = ownHit(top);
if (own) return own; if (own) return own;
// What is on top when it is no draw-set item: a sibling's contact // What is exactly on top when it is no draw-set item: a sibling's
// drawn on its own, a tile, or (on a coarse pointer) a contact found // contact drawn on its own, or a tile. Never a touch's wider contact
// under the touch. // search: a tap that misses an aircraft selects nothing, and one near
const topId = top ? top.id : event.id; // another layer's contact clears the selection, as the exact pick did.
const exact = top ? null : event.topHit;
const topId = top
? top.id
: exact && !exact.surface && exact.id != null
? String(exact.id)
: null;
if (!top && topId && markers.has(topId)) return topId; if (!top && topId && markers.has(topId)) return topId;
const trail = Boolean(topId) && String(topId).startsWith(TRAIL_PICK_PREFIX); const trail = Boolean(topId) && String(topId).startsWith(TRAIL_PICK_PREFIX);
if (ownedElsewhere(topId) && !trail) return 'other'; if (ownedElsewhere(topId) && !trail) return 'other';
+32
View File
@@ -1370,3 +1370,35 @@ test('a click on a UAT ring selects its aircraft, as the ring was a point on its
harness.click(); harness.click();
assert.deepEqual(calls.selected, ['local-adsb:a1b2c3']); assert.deepEqual(calls.selected, ['local-adsb:a1b2c3']);
}); });
test('a tap near a local aircraft but on nothing selects nothing, as the exact pick did', async (t) => {
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
const clock = { now: 100_000 };
const harness = clickHarness();
const { layer, calls, draw } = await enabledLayer(receiver, clock, null, {
viewer: harness.viewer,
});
t.after(() => layer.destroy());
const priorMatch = globalThis.matchMedia;
globalThis.matchMedia = () => ({ matches: true });
t.after(() => {
if (priorMatch === undefined) delete globalThis.matchMedia;
else globalThis.matchMedia = priorMatch;
});
receiver.set({ aircraft: [record()] });
await layer.update();
// The touch search finds contacts by their registered owner.
const { registerPickOwner, unregisterPickOwner } =
await import('../../data/pickRegistry.js');
registerPickOwner('local-adsb-test', (id) =>
String(id).startsWith('local-adsb:'),
);
t.after(() => unregisterPickOwner('local-adsb-test'));
// Nothing exactly under the tap; the aircraft is within a touch's reach.
harness.scene.pickResult = null;
harness.scene.drillPick = (position, limit, width = 1) =>
width > 1 ? [iconPick(draw, 'local-adsb:abc123')] : [];
harness.viewer.viewer.drillHits = [];
harness.click();
assert.deepEqual(calls.selected, []);
});