From cbc0c114eb9510c65b974c8e9ff965668f2af18f Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 01:49:17 -0800 Subject: [PATCH] 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. --- src/layers/localAdsb/index.js | 14 +++++++++---- src/layers/localAdsb/index.test.mjs | 32 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/layers/localAdsb/index.js b/src/layers/localAdsb/index.js index 6560d8b4b..491dc36bd 100644 --- a/src/layers/localAdsb/index.js +++ b/src/layers/localAdsb/index.js @@ -654,10 +654,16 @@ export function createLocalAdsbLayer({ const top = event.drawHit; const own = ownHit(top); if (own) return own; - // What is on top when it is no draw-set item: a sibling's contact - // drawn on its own, a tile, or (on a coarse pointer) a contact found - // under the touch. - const topId = top ? top.id : event.id; + // What is exactly on top when it is no draw-set item: a sibling's + // contact drawn on its own, or a tile. Never a touch's wider contact + // search: a tap that misses an aircraft selects nothing, and one near + // 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; const trail = Boolean(topId) && String(topId).startsWith(TRAIL_PICK_PREFIX); if (ownedElsewhere(topId) && !trail) return 'other'; diff --git a/src/layers/localAdsb/index.test.mjs b/src/layers/localAdsb/index.test.mjs index c50d3bbd3..5c9e6615a 100644 --- a/src/layers/localAdsb/index.test.mjs +++ b/src/layers/localAdsb/index.test.mjs @@ -1370,3 +1370,35 @@ test('a click on a UAT ring selects its aircraft, as the ring was a point on its harness.click(); 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, []); +});