mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(click): the card or label on top takes the click in every layer
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
This commit is contained in:
1 parent
7312280817
commit
bb3bf9858b
87 files changed
+1398
-1775
No files matched your search
@@ -5,7 +5,6 @@ import { viewshedColors, cameraHue } from '../../data/cctvViewshed.js';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
|
||||
import {
|
||||
GROUND_PRIOR_INIT_WAIT_MS,
|
||||
CALIBRATION_RANGE_FLOOR_M,
|
||||
@@ -24,14 +23,8 @@ export function createLifecycle({
|
||||
source,
|
||||
}) {
|
||||
const { activateCctvCameraFromWorldClick } = services.activation;
|
||||
const {
|
||||
resolvePickId,
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
isOwnedByOtherLayer,
|
||||
isActedOnByOtherLayer,
|
||||
isCardBackground,
|
||||
} = services.picking;
|
||||
const { resolvePickId, registerPickOwner, unregisterPickOwner, clickCard } =
|
||||
services.picking;
|
||||
const { onFocusTargetAppear } = services.focus;
|
||||
const { releaseContinuousRender } = services.render;
|
||||
|
||||
@@ -398,6 +391,20 @@ export function createLifecycle({
|
||||
(event) => {
|
||||
if (!layerState._enabled) return;
|
||||
const picked = event.topHit;
|
||||
// The card or label painted on top takes the click, read once per
|
||||
// click so every layer agrees: a live card of ours acts whatever
|
||||
// is drawn under it; another layer's is that layer's click.
|
||||
const top = clickCard?.(event) ?? null;
|
||||
if (top && top.sourceId !== CCTV_OVERLAY_SOURCE_ID) return;
|
||||
if (top) {
|
||||
// A card of ours that is going away is still not the scene.
|
||||
if (layerState._recordById.has(top.entryId))
|
||||
activateCctvCameraFromWorldClick(
|
||||
top.entryId,
|
||||
parts.selection.setActiveCamera,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const cameraId = parts.selection.extractPickedCameraId(
|
||||
event.drawHit ?? null,
|
||||
);
|
||||
@@ -408,60 +415,11 @@ export function createLifecycle({
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Cards use the last-painted top hit, never an obscured card from
|
||||
// our own source. Actual camera icons above keep their normal route.
|
||||
const cardHit = layerState._cctvOverlayHost.hitTest(
|
||||
event.screenPosition.x,
|
||||
event.screenPosition.y,
|
||||
{},
|
||||
);
|
||||
const cardId =
|
||||
cardHit?.sourceId === CCTV_OVERLAY_SOURCE_ID &&
|
||||
layerState._recordById.has(cardHit.entryId)
|
||||
? cardHit.entryId
|
||||
: null;
|
||||
const pickedId = resolvePickId(picked);
|
||||
const hit = event.drawHit;
|
||||
// A live top CCTV card acts over shapes whose layers stand aside
|
||||
// for a painted card (drone zones, fire perimeters, quake discs,
|
||||
// cables, launch markers), as each registers them. Unknown
|
||||
// identified objects and registered owners remain barriers.
|
||||
const cardBackground =
|
||||
cardId &&
|
||||
typeof pickedId === 'string' &&
|
||||
!isOwnedByOtherLayer?.('cctv', pickedId) &&
|
||||
Boolean(isCardBackground?.(hit));
|
||||
// A passive owner's pick (a flight trail, a directions route) acts
|
||||
// for nobody, so a live top CCTV card over it keeps the click.
|
||||
const passiveUnderCard =
|
||||
cardId &&
|
||||
typeof pickedId === 'string' &&
|
||||
Boolean(isActedOnByOtherLayer) &&
|
||||
isOwnedByOtherLayer?.('cctv', pickedId) &&
|
||||
!isActedOnByOtherLayer('cctv', pickedId, { click: event });
|
||||
if (pickedId !== null && !cardBackground && !passiveUnderCard) return;
|
||||
// A coarse tap's touch contact (not the exact pick) that its layer
|
||||
// acts on (an aircraft, a vessel, a radio station) is that layer's
|
||||
// click, even under a card of ours.
|
||||
const contactId = resolvePickId(event.hit ?? null);
|
||||
if (
|
||||
cardId &&
|
||||
contactId &&
|
||||
contactId !== pickedId &&
|
||||
isActedOnByOtherLayer?.('cctv', contactId, {
|
||||
expanded: true,
|
||||
click: event,
|
||||
})
|
||||
)
|
||||
return;
|
||||
if (cardHit && cardHit.sourceId !== CCTV_OVERLAY_SOURCE_ID) return;
|
||||
if (cardId) {
|
||||
activateCctvCameraFromWorldClick(
|
||||
cardId,
|
||||
parts.selection.setActiveCamera,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Any identified scene object owns this click even if its layer
|
||||
// does not register a shared pick predicate. This keeps selectable
|
||||
// siblings ahead of the CCTV selection while ID-less globe, terrain
|
||||
// and tile surfaces remain eligible for empty-space deselection.
|
||||
if (resolvePickId(picked) !== null) return;
|
||||
if (
|
||||
parts.selection.cctvEmptyClickDeselects(picked, {
|
||||
activeCameraId: layerState._activeCameraId,
|
||||
@@ -510,26 +468,19 @@ export function createLifecycle({
|
||||
layerState._lastUpdate = Date.now();
|
||||
// Pick-ownership (H2): camera icons use the camera id directly;
|
||||
// coverage polyline entities use `cctv-<cameraId>-<role>` entity ids.
|
||||
registerPickOwner(
|
||||
'cctv',
|
||||
(pickedId) => {
|
||||
if (layerState._recordById.has(pickedId)) return true;
|
||||
if (
|
||||
typeof pickedId === 'string' &&
|
||||
pickedId.startsWith(GIZMO_ID_PREFIX)
|
||||
)
|
||||
return true;
|
||||
const coverage =
|
||||
/^cctv-(.+)-(?:ray-tl|ray-tr|ray-br|ray-bl|cap|plane|plane-label)$/.exec(
|
||||
pickedId,
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
},
|
||||
// The world click handler takes only clean clicks (see
|
||||
// `bindCctvWorldClickGesture`), so a card over a camera keeps any
|
||||
// other tap.
|
||||
{ declinesClick: (click) => !isTrackingClickGesture(click?.gesture) },
|
||||
);
|
||||
registerPickOwner('cctv', (pickedId) => {
|
||||
if (layerState._recordById.has(pickedId)) return true;
|
||||
if (
|
||||
typeof pickedId === 'string' &&
|
||||
pickedId.startsWith(GIZMO_ID_PREFIX)
|
||||
)
|
||||
return true;
|
||||
const coverage =
|
||||
/^cctv-(.+)-(?:ray-tl|ray-tr|ray-br|ray-bl|cap|plane|plane-label)$/.exec(
|
||||
pickedId,
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
});
|
||||
if (!layerState._activeCameraId && layerState._records.length) {
|
||||
layerState._activeCameraId = parts.navigation.openingCameraId();
|
||||
layerState._autoHopSuspended = false;
|
||||
|
||||
@@ -77,7 +77,7 @@ test('the view listeners follow the camera port and let go on teardown', () => {
|
||||
assert.equal(state._viewListenerCamera, null);
|
||||
});
|
||||
|
||||
test('world clicks respect the painted top card and registered card backgrounds', async (t) => {
|
||||
test('the card painted on top takes world clicks, whatever is drawn under it', async (t) => {
|
||||
const noop = () => {};
|
||||
const { viewer } = viewerWithCamera();
|
||||
let picked = null;
|
||||
@@ -88,10 +88,11 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
};
|
||||
let drilled = [];
|
||||
const input = fakeInput(viewer);
|
||||
// An aircraft layer that runs before ours and starts tracking the plane
|
||||
// it was clicked on, which makes that plane passive mid-click.
|
||||
// An aircraft layer that runs before ours and tracks the plane it was
|
||||
// clicked on, standing aside under another layer's card.
|
||||
let tracked = null;
|
||||
input.input.onClick((event) => {
|
||||
if (picking.isUnderOtherCard(event)) return;
|
||||
if (event.hit?.id === 'plane:9') tracked = 'plane:9';
|
||||
});
|
||||
const ownCard = { sourceId: CCTV_OVERLAY_SOURCE_ID, entryId: 'cam-1' };
|
||||
@@ -101,6 +102,8 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
};
|
||||
let painted = [];
|
||||
const actions = [];
|
||||
// The card on top at a click, as the host answers the pick registry.
|
||||
picking.setClickCardHitTest(() => painted[0] ?? null);
|
||||
const state = {
|
||||
_cctvOverlayHost: {
|
||||
hitTest: (_x, _y, options = {}) =>
|
||||
@@ -148,12 +151,12 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
state._clickSubscription?.();
|
||||
lifecycle.detachViewListeners();
|
||||
input.destroy();
|
||||
picking.setClickCardHitTest(null);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.unregisterPickOwner('test-exact');
|
||||
picking.unregisterCardBackground('area-fixture');
|
||||
});
|
||||
await lifecycle.methods.init(viewer);
|
||||
state._enabled = true;
|
||||
@@ -184,36 +187,32 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
surface: false,
|
||||
};
|
||||
const backgrounds = [drone, perimeter, quake, cable, launch];
|
||||
// Each of those layers registers its own shapes this way (their tests
|
||||
// check the real predicates); CCTV only asks the registry.
|
||||
picking.registerCardBackground('area-fixture', (hit) =>
|
||||
backgrounds.some((b) => b.set === hit.set && b.id === hit.id),
|
||||
);
|
||||
for (const area of backgrounds) {
|
||||
click(area, [ownCard], ['cam-1']);
|
||||
click(area, [], []);
|
||||
click(area, [foreignCard, ownCard], []);
|
||||
}
|
||||
// The live top card acts over anything drawn under it; with no card an
|
||||
// identified object is not empty map.
|
||||
for (const hit of [
|
||||
{ set: 'flights:1', id: 'aircraft', surface: false },
|
||||
{ set: '', id: 'unregistered-local-entity', surface: false },
|
||||
{ set: '', id: '', surface: false },
|
||||
{ ...drone, set: 'unrelated:1:fills' },
|
||||
{ ...drone, id: 'unregistered-local-entity' },
|
||||
])
|
||||
click(hit, [ownCard], []);
|
||||
// A passive owner's pick (a trail, a route) acts for nobody: the live top
|
||||
// card keeps the click, and with no card the pick is not empty map.
|
||||
]) {
|
||||
click(hit, [ownCard], ['cam-1']);
|
||||
click(hit, [], []);
|
||||
}
|
||||
// A trail under the live top card: the card keeps the click, and with no
|
||||
// card the owned pick is not empty map.
|
||||
const trail = { set: 'trails:1', id: 'gev-trail:fl-1:head', surface: false };
|
||||
picking.registerPickOwner('test-trails', (id) => id === trail.id, {
|
||||
passive: true,
|
||||
});
|
||||
picking.registerPickOwner('test-trails', (id) => id === trail.id);
|
||||
click(trail, [ownCard], ['cam-1']);
|
||||
click(trail, [], []);
|
||||
click(trail, [foreignCard, ownCard], []);
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
// A coarse tap whose touch contact is an aircraft (a layer that acts on
|
||||
// nearby contacts) is the aircraft's, even under a live CCTV card.
|
||||
// nearby contacts) under a live CCTV card is the card's.
|
||||
const previousMatch = globalThis.matchMedia;
|
||||
const restoreMatch = () => {
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
@@ -223,11 +222,9 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
// failing assertion cannot leave the coarse pointer for later tests.
|
||||
t.after(restoreMatch);
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
picking.registerPickOwner('test-planes', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
picking.registerPickOwner('test-planes', (id) => id === 'plane:1');
|
||||
drilled = ['plane:1'];
|
||||
click(null, [ownCard], []);
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
// With no card, the bare tap near the aircraft still deselects.
|
||||
click(null, [], ['clear']);
|
||||
// A contact whose layer acts only on exact hits leaves the card its tap.
|
||||
@@ -239,49 +236,29 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
restoreMatch();
|
||||
// The live card reads the owners that acted when the click resolved, so it
|
||||
// yields to the aircraft even though tracking made it passive meanwhile.
|
||||
picking.registerPickOwner('test-tracking', (id) => id === 'plane:9', {
|
||||
expanded: true,
|
||||
passive: (id) => id === tracked,
|
||||
});
|
||||
click({ set: 'flights:1', id: 'plane:9', surface: false }, [ownCard], []);
|
||||
assert.equal(tracked, 'plane:9', 'the aircraft started tracking');
|
||||
// The live card over an aircraft takes the click; the aircraft layer,
|
||||
// run first, stands aside and does not track.
|
||||
picking.registerPickOwner('test-tracking', (id) => id === 'plane:9');
|
||||
click(
|
||||
{ set: 'flights:1', id: 'plane:9', surface: false },
|
||||
[ownCard],
|
||||
['cam-1'],
|
||||
);
|
||||
assert.equal(tracked, null, 'the aircraft did not track');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.registerPickOwner('area-control', (id) => id === drone.id);
|
||||
click(drone, [ownCard], []);
|
||||
click(drone, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
click(null, [foreignCard, ownCard], []);
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
click(null, [], ['clear']);
|
||||
click(drone, [{ ...ownCard, entryId: 'stale-camera' }], []);
|
||||
click(
|
||||
{ set: 'cctv:fixture', id: 'cam-1' },
|
||||
[foreignCard, ownCard],
|
||||
['cam-1'],
|
||||
);
|
||||
// CCTV takes only clean clicks, so for a long press or a drag its cameras
|
||||
// act for nobody: a card painted over one keeps that tap.
|
||||
// Enable's own work is beside the point here: only its registration.
|
||||
Object.assign(parts.cards, {
|
||||
refreshAmbientCards: noop,
|
||||
startCardFrameLoop: noop,
|
||||
});
|
||||
parts.frames = { refreshProjectionImage: noop };
|
||||
Object.assign(parts.geometryQueue, { startGeometryLoadQueue: noop });
|
||||
parts.navigation = { openingCameraId: () => 'cam-1' };
|
||||
Object.assign(parts.projection, {
|
||||
ensureProjectionRuntime: noop,
|
||||
startProjectionLoop: noop,
|
||||
});
|
||||
state._cctvOverlayHost.setVisible ??= noop;
|
||||
lifecycle.methods.enable();
|
||||
t.after(() => picking.unregisterPickOwner('cctv'));
|
||||
const acted = (gesture) =>
|
||||
picking.isActedOnByOtherLayer('earthquakes', 'cam-1', {
|
||||
click: { gesture },
|
||||
});
|
||||
assert.equal(acted({ travelPx: 0, durationMs: 80 }), true, 'a clean click');
|
||||
assert.equal(acted({ travelPx: 0, durationMs: 900 }), false, 'a long press');
|
||||
assert.equal(acted({ travelPx: 20, durationMs: 80 }), false, 'a drag');
|
||||
// A card of ours that is going away is still not the scene under it: no
|
||||
// camera beneath it activates, and nothing clears.
|
||||
const staleCard = { ...ownCard, entryId: 'stale-camera' };
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [staleCard], []);
|
||||
click(null, [staleCard], []);
|
||||
// A camera icon under another layer's card is that card's click.
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [foreignCard, ownCard], []);
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [], ['cam-1']);
|
||||
});
|
||||
Reference in new issue
Block a user