From 4f24b9a062c3afae8302a90c78a319deea9be2c9 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 01:51:24 -0800 Subject: [PATCH] fix(wildlife): a tap selects only a sighting exactly under it again A click read the scene's exact pick 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 sighting selected it, and one near another layer's contact kept the selection. It reads the exact top hit again, as the shipwrecks and Local ADS-B layers do. --- .../wildlifeSightings/ownership.test.mjs | 4 +++- src/layers/wildlifeSightings/selection.js | 8 ++++++- .../wildlifeSightings/selection.test.mjs | 21 ++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/layers/wildlifeSightings/ownership.test.mjs b/src/layers/wildlifeSightings/ownership.test.mjs index c7807afdb..057c80519 100644 --- a/src/layers/wildlifeSightings/ownership.test.mjs +++ b/src/layers/wildlifeSightings/ownership.test.mjs @@ -204,7 +204,9 @@ function harness( clicks.callback = (click) => fn({ screenPosition: click.position, - id: picked?.id ?? picked?.primitive?.id ?? null, + topHit: picked + ? { set: 'wildlife', id: picked.id ?? picked.primitive?.id } + : null, }); return () => { clicks.destroyed = true; diff --git a/src/layers/wildlifeSightings/selection.js b/src/layers/wildlifeSightings/selection.js index c13171c01..dc0b7c126 100644 --- a/src/layers/wildlifeSightings/selection.js +++ b/src/layers/wildlifeSightings/selection.js @@ -498,7 +498,13 @@ export function createSelection({ state, services, parts }) { return; } // A sighting icon's item id is its pick id, `wildlife:`. - const id = click.id; + // Read from what is exactly under the click, as the scene's pick was: + // a touch's wider contact search would select a sighting the tap + // missed, or keep one open for a tap near another layer's contact. + const picked = click.topHit; + const id = picked + ? (services.picking?.resolvePickId?.(picked) ?? picked.id ?? null) + : null; if ( typeof id === 'string' && id.startsWith('wildlife:') && diff --git a/src/layers/wildlifeSightings/selection.test.mjs b/src/layers/wildlifeSightings/selection.test.mjs index d3162ddcc..bf623526b 100644 --- a/src/layers/wildlifeSightings/selection.test.mjs +++ b/src/layers/wildlifeSightings/selection.test.mjs @@ -99,9 +99,13 @@ function fixture(sighting = row, extraServices = {}) { for (const id of ids) painted.add(id); selection.photoCardsChanged(); }, - click(id = `wildlife:${sighting.stableId}`) { - // The input dispatcher hands the pick's registry-resolved id. - click({ screenPosition: { x: 10, y: 20 }, id: id ?? undefined }); + click(id = `wildlife:${sighting.stableId}`, { touchId } = {}) { + // The exact top hit, and the id a touch's wider contact search finds. + click({ + screenPosition: { x: 10, y: 20 }, + topHit: id ? { set: 'wildlife', id } : null, + id: touchId ?? id ?? undefined, + }); }, }; } @@ -300,6 +304,17 @@ test('empty clicks and layer removal release the selected row and its overlay', assert.equal(f.entries.size, 0); }); +test('a tap selects only a sighting exactly under it, not one the touch search found near it', () => { + const f = fixture(); + f.selection.install(); + f.click(null, { touchId: `wildlife:${row.stableId}` }); + assert.equal(f.state.selectedId, null); + f.click(); + assert.ok(f.state.selectedId); + f.click(null, { touchId: 'other:aircraft' }); + assert.equal(f.state.selectedId, null, 'a tap near another contact clears'); +}); + test('each sighting in context carries the point voice projects to find what is in view', () => { const registered = []; const f = fixture(row, {