From 959698cff94bc08530f6dc0b6f4aeea5a84a02a3 Mon Sep 17 00:00:00 2001 From: manjunath22466 Date: Mon, 16 Nov 2026 21:13:42 +0530 Subject: [PATCH] fix(drone-airspace, perimeters): yield area clicks to cards painted on top Drone airspace and fire perimeters select a zone or incident from any shape hit, so a quake card or magnitude label painted over one made both layers act on a single click: the quake opened its USGS page or flew to the quake while the area was selected too. Fire and vessel cards over an area did the same. The areas now stand aside when another layer's card or label is the topmost overlay entry, the rule the quake handler already follows for cards painted over its discs. Deselection and every other path are unchanged. Items of layers that never act on clicks no longer matter: the quake card and labels keep working over air-quality stations, traffic lines and OSM places. --- docs/CURRENT-STATE.md | 12 +- src/layers/droneAirspace/index.js | 9 ++ src/layers/droneAirspace/ownership.test.mjs | 37 +++++ src/layers/earthquakes/selection.test.mjs | 169 ++++++++++++++++++++ src/layers/perimeters/index.js | 9 ++ src/layers/perimeters/ownership.test.mjs | 37 +++++ 6 files changed, 272 insertions(+), 1 deletion(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 07f2e8f891..f68d179b8b 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1868,7 +1868,17 @@ like drone airspace and fire perimeters: sibling layers read a disc as empty space, so their cards, near-miss taps and deselection work over a quake as before. When another layer's card or label is painted over a disc (a fire card on a large quake), the quake handler yields to it rather than selecting the -quake beneath. +quake beneath. The same rule holds the other way: drone airspace and fire +perimeters do not select a zone or incident from a shape hit while another +layer's card or label is the topmost overlay entry, so a quake card or +magnitude label over one of them acts once, as the quake's. Items of layers +that never act on clicks (air-quality stations, traffic lines, OSM places) do +not block the quake card or labels. A bare area click with nothing painted on +top still selects the area and clears the quake selection. These rules hold in any +listener order because world-overlay hit rectangles are what is painted on +screen until the next paint: an overlay change (a click subscriber publishing +its selection card) no longer clears them mid-click, and a paint that draws +nothing clears them (`src/overlays/worldOverlay.js`). Air quality (`./layers/air-quality`) draws its station discs as one renderer draw set of ground-clamped fills and reads the view through the camera port; it diff --git a/src/layers/droneAirspace/index.js b/src/layers/droneAirspace/index.js index 8bb8b72423..2e64bafd37 100644 --- a/src/layers/droneAirspace/index.js +++ b/src/layers/droneAirspace/index.js @@ -139,6 +139,15 @@ export function createDroneAirspaceLayer({ const picked = event.topHit; const zoneId = picked ? pickedZoneId(event.drawHit) : null; if (zoneId) { + // Another layer's card or label painted over the zone (a quake's + // card or magnitude label, a fire card) is that layer's click: under + // it the zone is background, as it is to siblings, so it stays as is. + const top = overlayHost.hitTest?.( + event.screenPosition?.x, + event.screenPosition?.y, + {}, + ); + if (top && top.sourceId !== DRONE_AIRSPACE_OVERLAY_SOURCE_ID) return; _selectedId = zoneId; publishSelectedCard(); return; diff --git a/src/layers/droneAirspace/ownership.test.mjs b/src/layers/droneAirspace/ownership.test.mjs index 3dbb16a583..b6e4cbdcb2 100644 --- a/src/layers/droneAirspace/ownership.test.mjs +++ b/src/layers/droneAirspace/ownership.test.mjs @@ -143,6 +143,43 @@ test('clicking a zone publishes its card; empty space clears it', async () => { assert.equal(h.overlay.entries.get('drone-airspace')?.length ?? 0, 0); }); +// Another layer's card or label painted over the area (a quake's card or +// magnitude label) is that layer's click: the area under it stands aside. +test("another layer's overlay on top keeps a click off the area", async () => { + let pickResult = null; + let foreignOnTop = false; + const h = harness( + { getSnapshot: async () => [row] }, + { + pick: () => pickResult, + // Unfiltered: the topmost entry of any source. + cardHit: (_x, _y, options) => + foreignOnTop && !options?.sourceId + ? { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' } + : null, + }, + ); + await h.layer.update(h.viewer); + pickResult = zonePick('drone-airspace:310:0'); + foreignOnTop = true; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal(h.overlay.entries.get('drone-airspace')?.length ?? 0, 0); + // With nothing painted over it, the same click selects the area. + foreignOnTop = false; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal( + h.overlay.entries.get('drone-airspace')[0].id, + 'drone-airspace-card:310', + ); + // An overlay on top never clears an existing selection either. + foreignOnTop = true; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal( + h.overlay.entries.get('drone-airspace')[0].id, + 'drone-airspace-card:310', + ); +}); + test('late refresh cannot publish after disable or destroy', async () => { for (const action of ['disable', 'destroy']) { let resolve, signal; diff --git a/src/layers/earthquakes/selection.test.mjs b/src/layers/earthquakes/selection.test.mjs index 4a5e70412a..ad8765b05d 100644 --- a/src/layers/earthquakes/selection.test.mjs +++ b/src/layers/earthquakes/selection.test.mjs @@ -2,6 +2,8 @@ import assert from 'node:assert/strict'; import test from 'node:test'; import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs'; import * as picking from '../../data/pickRegistry.js'; +import { fakeInput } from '../../input/testDoubles.mjs'; +import { createDroneAirspaceLayer } from '../droneAirspace/index.js'; import { EARTHQUAKE_CARD_SOURCE_ID, EARTHQUAKE_OVERLAY_SOURCE_ID, @@ -709,3 +711,170 @@ test("another layer's object under the quake card takes the click", async () => function overlayHitCard(h, entryId, hit) { h.clickOverlayWith(EARTHQUAKE_CARD_SOURCE_ID, entryId, hit); } + +for (const kind of ['card', 'label']) { + for (const areaFirst of [false, true]) { + test(`quake ${kind} over an unowned area takes the click once (${areaFirst ? 'area' : 'quake'} handler first)`, async () => { + let sceneHit = null; + let painted = null; + const viewer = { + scene: { pick: () => (sceneHit ? { id: sceneHit } : null) }, + }; + const { draw, unbind } = bindFakeDraw(viewer); + const input = fakeInput(viewer); + const entries = new Map(); + const opened = []; + const focused = []; + // As the real host does, hits are what was last painted: a card a + // subscriber publishes during a click changes nothing for the others + // until the next paint, so the outcome cannot depend on their order. + let screen = new Map(); + const paint = () => { + screen = new Map(entries); + }; + const host = { + setEntries: (source, rows) => entries.set(source, rows), + setVisible() {}, + clearSource: (source) => entries.delete(source), + hitTest(_x, _y, { sourceId } = {}) { + if (!painted || (sourceId && sourceId !== painted.sourceId)) + return null; + const entry = screen + .get(painted.sourceId) + ?.find((e) => e.id === painted.entryId); + return entry?.interactive ? { ...painted, entry } : null; + }, + }; + const click = () => { + paint(); + input.click(); + }; + const q = createEarthquakesLayer({ + source: { getSnapshot: async () => [quake('ak1')] }, + overlayHost: host, + input: () => input.input, + picking, + openExternal: (url) => opened.push(url), + focus: { requestWorldFocus: (detail) => focused.push(detail) }, + }); + const area = createDroneAirspaceLayer({ + source: { + getSnapshot: async () => [ + { + stableId: '310', + name: 'Fixture area', + typeCode: 'P', + type: 'Prohibited', + lowerAltitude: 'SFC', + upperAltitude: '18000', + polygons: [ + [ + [ + [-153.4, 59.9], + [-153.2, 59.9], + [-153.2, 60.1], + [-153.4, 59.9], + ], + ], + ], + }, + ], + }, + overlayHost: host, + inputFor: () => input.input, + picking, + }); + const layers = areaFirst ? [area, q] : [q, area]; + try { + for (const layer of layers) { + layer.init(viewer); + layer.enable(viewer); + await layer.update(viewer); + } + const ownHit = { + set: draw.find('earthquakes:').spec.id, + id: 'earthquake:ak1', + }; + const areaSet = [...draw.sets.values()].find( + (set) => + set.spec.id.startsWith('drone-airspace:') && + set.spec.id.endsWith(':fills'), + ); + const areaHit = { set: areaSet.spec.id, id: 'drone-airspace:310:0' }; + assert.equal(picking.findPickOwner(areaHit.id), null); + sceneHit = ownHit; + click(); + assert.equal( + entries.get('earthquake-card')[0].id, + 'earthquake-card:ak1', + ); + assert.equal(entries.get('drone-airspace')?.length ?? 0, 0); + painted = { + sourceId: + kind === 'card' + ? EARTHQUAKE_CARD_SOURCE_ID + : EARTHQUAKE_OVERLAY_SOURCE_ID, + entryId: kind === 'card' ? 'earthquake-card:ak1' : 'ak1', + }; + sceneHit = areaHit; + click(); + // The quake's card or label painted on top takes the click; the + // zone under it is background and stands aside: one action. + assert.equal( + entries.get('drone-airspace')?.length ?? 0, + 0, + 'the area under the overlay is not selected', + ); + assert.equal( + entries.get('earthquake-card')[0].id, + 'earthquake-card:ak1', + 'the quake card stays', + ); + assert.equal(opened.length, kind === 'card' ? 1 : 0); + assert.equal(focused.length, kind === 'label' ? 1 : 0); + // The same painted action works over its own disc and over open ground. + for (const hit of [ownHit, null]) { + sceneHit = hit; + click(); + } + assert.equal(opened.length, kind === 'card' ? 3 : 0); + assert.equal(focused.length, kind === 'label' ? 3 : 0); + // With no overlay the area is selected and the quake deselects. + painted = null; + sceneHit = areaHit; + click(); + assert.equal(entries.get('drone-airspace')?.length, 1); + assert.equal(entries.get('earthquake-card')?.length ?? 0, 0); + } finally { + for (const layer of layers) layer.destroy(); + input.destroy(); + unbind(); + } + }); + } +} + +// Layers that never act on clicks still draw pickable items (air quality +// stations, traffic heat lines, OSM places). They are not a click target, so +// the quake card and labels painted over them keep working. +test('quake card and label work over pickable items no layer acts on', async () => { + const h = harness([quake('ak1'), quake('ak2', { mag: 4 })]); + try { + h.layer.enable(h.viewer); + await h.layer.update(h.viewer); + h.clickDisc('ak1'); + const decorative = [ + { set: 'air-quality-markers:1', id: 'aq:station-1' }, + { set: 'traffic:1:heat', id: 'traffic:segment-9' }, + { set: 'osm-places:1:points', id: 'osm:node-3' }, + ]; + for (const hit of decorative) { + h.clickOverlayWith(EARTHQUAKE_CARD_SOURCE_ID, 'earthquake-card:ak1', hit); + } + assert.equal(h.opened.length, decorative.length, 'the card opens USGS'); + h.clickOverlayWith(EARTHQUAKE_OVERLAY_SOURCE_ID, 'ak2', decorative[1]); + assert.equal(h.focused.at(-1)?.id, 'earthquake:ak2', 'the label flies'); + } finally { + h.layer.destroy(); + } +}); diff --git a/src/layers/perimeters/index.js b/src/layers/perimeters/index.js index 3a5a180c48..017e7ab46c 100644 --- a/src/layers/perimeters/index.js +++ b/src/layers/perimeters/index.js @@ -230,6 +230,15 @@ export function createFirePerimetersLayer({ const picked = event.topHit; const incidentId = picked ? pickedIncidentId(event.drawHit) : null; if (incidentId) { + // Another layer's card or label painted over the perimeter (a + // quake's card or magnitude label, a fire card) is that layer's + // click: under it the perimeter is background, so it stays as is. + const top = overlayHost.hitTest?.( + event.screenPosition?.x, + event.screenPosition?.y, + {}, + ); + if (top && top.sourceId !== PERIMETER_OVERLAY_SOURCE_ID) return; abortLinkVerification(); _selectedId = incidentId; publishSelectedCard(); diff --git a/src/layers/perimeters/ownership.test.mjs b/src/layers/perimeters/ownership.test.mjs index 61cfde2bbf..9f11d5b177 100644 --- a/src/layers/perimeters/ownership.test.mjs +++ b/src/layers/perimeters/ownership.test.mjs @@ -243,6 +243,43 @@ test('clicking a perimeter publishes its incident card; empty space clears it', assert.equal(h.overlay.entries.get('fire-perimeters')?.length ?? 0, 0); }); +// Another layer's card or label painted over the area (a quake's card or +// magnitude label) is that layer's click: the area under it stands aside. +test("another layer's overlay on top keeps a click off the area", async () => { + let pickResult = null; + let foreignOnTop = false; + const h = harness( + { getSnapshot: async () => [row] }, + { + pick: () => pickResult, + // Unfiltered: the topmost entry of any source. + cardHit: (_x, _y, options) => + foreignOnTop && !options?.sourceId + ? { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' } + : null, + }, + ); + await h.layer.update(h.viewer); + pickResult = perimeterPick('fire-perimeter:2026-NMGNF-000123:0'); + foreignOnTop = true; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal(h.overlay.entries.get('fire-perimeters')?.length ?? 0, 0); + // With nothing painted over it, the same click selects the area. + foreignOnTop = false; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal( + h.overlay.entries.get('fire-perimeters')[0].id, + 'fire-perimeter-card:2026-NMGNF-000123', + ); + // An overlay on top never clears an existing selection either. + foreignOnTop = true; + h.clicks.handler({ position: { x: 10, y: 10 } }); + assert.equal( + h.overlay.entries.get('fire-perimeters')[0].id, + 'fire-perimeter-card:2026-NMGNF-000123', + ); +}); + test('disable removes the click handler, pick ownership, and any card', async () => { const h = harness( { getSnapshot: async () => [row] },