diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 064fa13e44..712b3af4c0 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2064,7 +2064,9 @@ vessels act on that contact, and so do radio and Street Level, which also pick through their own windows (17 and 9 px). A station or Street Level item found only through that window, not as the exact hit or the touch contact, yields to another layer's card or label painted over it, so a quake card or label beside -one acts alone, with a mouse or a coarse pointer. Fire and CCTV cards in turn +one acts alone, with a mouse or a coarse pointer; under such a card, their own +touch contact stays theirs even when the window names another item. Fire and +CCTV cards in turn yield to a touch contact whose layer acts on it. The aircraft a layer already tracks and Street Level's position marker are passive picks, since a click on either does nothing. The pick registry records which owners act on a click's diff --git a/src/layers/radio/interaction.js b/src/layers/radio/interaction.js index 9e1b59f134..154652aed3 100644 --- a/src/layers/radio/interaction.js +++ b/src/layers/radio/interaction.js @@ -51,9 +51,11 @@ export function createInteraction({ if (!stationId) continue; // Found only through our wider window, not as the tap's touch contact: // another layer's card or label painted here is that layer's click, - // since its handler never sees this window. - if (stationFromPick(event.hit) !== stationId && foreignCardAt(event)) - return null; + // since its handler never sees this window. A station of ours that is + // the contact is still ours: that card yields to it. + const contactStationId = stationFromPick(event.hit); + if (contactStationId !== stationId && foreignCardAt(event)) + return contactStationId; return stationId; } return null; diff --git a/src/layers/radio/interaction.test.mjs b/src/layers/radio/interaction.test.mjs index 40d2e48a37..e11dd61bdf 100644 --- a/src/layers/radio/interaction.test.mjs +++ b/src/layers/radio/interaction.test.mjs @@ -101,3 +101,35 @@ test('a window-only station yields to a card painted over it', () => { top = { sourceId: 'radio', entryId: 'radio:kexp' }; assert.equal(radio.pickedRadioStationAt(near()), 'kexp', 'our own card'); }); + +// Under another layer's card, radio's window can name a different station +// from the tap's touch contact. The card yields to that contact, a station of +// ours, so radio acts on it instead of leaving the click dead. +test('under a card, the touch contact station is ours even when the window names another', () => { + const radio = createInteraction({ + state: { _stationById: new Map([['kexp', {}], ['kuow', {}]]) }, + services: { + picking: { + resolvePickId: (picked) => picked?.id ?? null, + isOwnedByOtherLayer: () => false, + registerPickOwner() {}, + unregisterPickOwner() {}, + }, + overlays: { + setOverlaySourceVisible() {}, + hitTestWorldOverlay: () => ({ + sourceId: 'earthquake-card', + entryId: 'earthquake-card:ak1', + }), + }, + }, + parts: { rendering: { radioStationIdFromPick } }, + }); + const tap = (contact) => ({ + ...clickEvent({ windowHits: [hit('radio:kexp')] }), + hit: contact, + screenPosition: { x: 5, y: 5 }, + }); + assert.equal(radio.pickedRadioStationAt(tap(hit('radio:kuow'))), 'kuow'); + assert.equal(radio.pickedRadioStationAt(tap(null)), null, 'no contact'); +}); diff --git a/src/layers/streetLevel/selection.js b/src/layers/streetLevel/selection.js index 1d7a673c23..9a7cfea8f5 100644 --- a/src/layers/streetLevel/selection.js +++ b/src/layers/streetLevel/selection.js @@ -36,9 +36,14 @@ export function createSelection({ state, parts }) { // Found only through our window, not as the contact (which is the exact // hit whenever there is one): another layer's card or label painted here // is that layer's click, since its handler never sees this window. + // An item of ours that is the contact is still ours: that card yields + // to it. if (route && windowId !== contactId) { const at = event.screenPosition; - if (state.services.overlayHit?.(at?.x, at?.y)) return; + if (state.services.overlayHit?.(at?.x, at?.y)) { + route = contactId ? parts.router.resolve(contactId) : null; + if (!route) return; + } } if (!route && contactId) route = parts.router.resolve(contactId); // Not ours: the ground handler decides whether it is the map itself. diff --git a/src/layers/streetLevel/selection.test.mjs b/src/layers/streetLevel/selection.test.mjs index e1bc976f69..db5304b8a0 100644 --- a/src/layers/streetLevel/selection.test.mjs +++ b/src/layers/streetLevel/selection.test.mjs @@ -424,3 +424,33 @@ test('the position marker is a passive pick; our items act', () => { h.restore(); } }); + +// Under another layer's card, our window can name a different item from the +// tap's touch contact. The card yields to that contact, an item of ours, so +// Street Level opens it instead of leaving the click dead. +test('under a card, the touch contact item is ours even when the window names another', (t) => { + const previous = globalThis.matchMedia; + globalThis.matchMedia = () => ({ matches: true }); + t.after(() => { + if (previous) globalThis.matchMedia = previous; + else delete globalThis.matchMedia; + }); + const h = harness({ + services: { + picking: pickRegistry, + overlayHit: () => ({ sourceId: 'earthquake-card', entryId: 'q' }), + }, + sceneExtras: { + pick: (_position, width = 3) => + width >= 9 ? { id: 'mly:img:window' } : null, + drillPick: () => [{ id: 'mly:img:contact' }], + }, + }); + try { + h.click(); + assert.deepEqual(h.opened, ['contact']); + assert.equal(h.groundClicks.length, 0); + } finally { + h.restore(); + } +});