fix(picking): arbitrate card clicks over passive and background shapes

Flight trails register their ids so every layer reads a trail click as a
no-op, and the directions route claims its line and markers though it acts
only on its maneuver steps. The quake card and magnitude labels yielded to
any registered owner, so over a trail or a route they did nothing. Pick
owners can now name the picks they never act on (registerPickOwner(...,
{ passive })); isActedOnByOtherLayer leaves those out while
isOwnedByOtherLayer is unchanged, so they are still not empty space.

Submarine cables and rocket launches acted on any scene pick, so a card or
label over a cable or a launch marker made both layers act. Both now stand
aside when a world-overlay entry is under the click, as drone airspace and
fire perimeters do through the top-entry check. Each of these layers, and
the quake discs, registers its shapes with registerCardBackground. CCTV
asks isCardBackground instead of matching other layers' set and id formats,
so a live top CCTV card acts once over any of them, while unknown
identified objects and registered owners still block it.
This commit is contained in:
manjunath22466 committed 2026-11-17 01:33:06 +05:30
1 parent 836daf82b3
commit 133d022b29
23 files changed
+825 -78

No files matched your search

+3
View File
@@ -8,6 +8,7 @@ import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
export function createSubmarineCableLayer({
source,
overlayHost,
picking = null,
inputFor = defaultInputFor,
mapStackEventTarget = null,
sweepClock = defaultSweepClock,
@@ -23,6 +24,8 @@ export function createSubmarineCableLayer({
parts,
source,
inputFor,
overlayHost,
picking,
mapStackEventTarget,
};
parts.rendering = createRendering(context);
+27 -2
View File
@@ -1,15 +1,40 @@
import { toRadians } from '../../geo/vector.js';
import { cameraOf } from '../../render/rendererOf.js';
export function createInteraction({ state, parts, inputFor }) {
const CARD_BACKGROUND_ID = 'submarine-cables';
export function createInteraction({
state,
parts,
inputFor,
overlayHost,
picking,
}) {
function beginInteraction(viewer) {
if (state._clickSubscription) return;
state._clickSubscription = inputFor(viewer).onClick((event) => {
// Our cables stand aside for a card painted over them (below), so that
// card's layer may act on the click; without a hit-test they cannot.
if (overlayHost?.hitTest)
picking?.registerCardBackground?.(
CARD_BACKGROUND_ID,
(hit) => state._enabled && Boolean(resolvePickRecord(hit)?.reference),
);
const unsubscribe = inputFor(viewer).onClick((event) => {
if (!state._enabled) return;
// Cable labels are not interactive, so any overlay entry hit here is
// another layer's card or label painted over the cable: its click.
if (
overlayHost?.hitTest?.(event.screenPosition?.x, event.screenPosition?.y)
)
return;
const record = resolvePickRecord(event.drawHit);
if (!record?.reference) return;
flyToReference(viewer, record.reference);
});
state._clickSubscription = () => {
unsubscribe();
picking?.unregisterCardBackground?.(CARD_BACKGROUND_ID);
};
}
/**
@@ -0,0 +1,89 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createInteraction } from './interaction.js';
import * as picking from '../../data/pickRegistry.js';
/** The cable click handler, with its click and overlay seams faked. */
function harness({ overlayTop = null } = {}) {
let onClick = null;
const picked = [];
let top = overlayTop;
const interaction = createInteraction({
state: { _enabled: true, _clickSubscription: null },
parts: {
rendering: {
pickInfo: (hit) => {
picked.push(hit);
return null;
},
},
},
inputFor: () => ({
onClick: (fn) => {
onClick = fn;
return () => (onClick = null);
},
}),
overlayHost: { hitTest: () => top },
});
interaction.beginInteraction({});
return {
picked,
setTop: (next) => {
top = next;
},
click: () =>
onClick({
screenPosition: { x: 5, y: 5 },
drawHit: { set: 'c', id: 'x' },
}),
};
}
// Cable labels are not interactive: an overlay entry under the pointer is
// another layer's card or label painted over the cable (a quake card), and
// that layer takes the click, so the cable does not also fly the camera.
test('a card painted over a cable keeps its click; with none the cable reads the pick', () => {
const h = harness({
overlayTop: { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' },
});
h.click();
assert.equal(h.picked.length, 0, 'the cable stands aside');
h.setTop(null);
h.click();
assert.equal(
h.picked.length,
1,
'with no card on top, the cable reads its pick',
);
});
// So a card on top (a live CCTV card) may act over the cable instead.
test('while it takes clicks, a drawn cable registers as card background', () => {
const state = { _enabled: true, _clickSubscription: null };
const interaction = createInteraction({
state,
parts: {
rendering: {
pickInfo: (hit) =>
hit?.set === 'cables:1' ? { reference: { lon: 1, lat: 2 } } : null,
},
},
inputFor: () => ({ onClick: () => () => {} }),
overlayHost: { hitTest: () => null },
picking,
});
interaction.beginInteraction({});
const cable = { set: 'cables:1', id: 'cable:0' };
try {
assert.equal(picking.isCardBackground(cable), true);
assert.equal(picking.isCardBackground({ set: 'other:1', id: 'x' }), false);
state._enabled = false;
assert.equal(picking.isCardBackground(cable), false);
state._enabled = true;
state._clickSubscription();
assert.equal(picking.isCardBackground(cable), false);
} finally {
state._clickSubscription?.();
}
});