mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(touch): give each tap to the layer that acts on it
On a coarse pointer the dispatcher can name a contact near the tap instead of the exact pick. Only flights, military, vessels, radio and Street Level act on such a contact, so they now register as expanded pick owners, and a quake card or label yields only to them. A FIRMS fire or CCTV camera reached only as a nearby contact no longer swallows a quake card, a quake label or a vessel's own card tap, and FIRMS and CCTV cards yield to a contact whose layer does act on it. Radio and Street Level also pick through their own windows. A station or Street Level item found only there, not as the touch contact, yields to another layer's card painted over it, and Street Level takes its own touch contact beyond its narrower window. Fire, CCTV and vessel cards now act over a passive owner's pick (a flight trail, the directions route), as the quake card does. The Context panel leaves a passive route, or a fire or camera reached only as a nearby contact, to the card painted over it.
This commit is contained in:
1 parent
4804097ca1
commit
830c980ca6
26 files changed
+1095
-69
No files matched your search
@@ -6,6 +6,7 @@ import { createPanoramaxProvider } from '../../layers/streetLevel/providers/pano
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import * as scenePick from '../../data/scenePick.js';
|
||||
import * as render from '../../renderGovernor.js';
|
||||
import { hitTestWorldOverlay } from '../../overlays/worldOverlay.js';
|
||||
|
||||
/** The browser Maps key the scene was started with (src/app/scene.js). */
|
||||
const googleApiKey = () => globalThis.window?.__GOOGLE_MAPS_API_KEY__ || null;
|
||||
@@ -35,6 +36,7 @@ export function createApplicationStreetLevel({
|
||||
}) {
|
||||
return createStreetLevelLayer({
|
||||
providers,
|
||||
services: { picking, scenePick, render },
|
||||
// Hit-testing lets a card painted over a near miss keep its click.
|
||||
services: { picking, scenePick, render, overlayHit: hitTestWorldOverlay },
|
||||
});
|
||||
}
|
||||
@@ -1012,7 +1012,7 @@ function makeCesiumEvent() {
|
||||
};
|
||||
}
|
||||
|
||||
function installWireHarness(picked, stateOverrides = {}) {
|
||||
function installWireHarness(picked, stateOverrides = {}, sceneExtras = {}) {
|
||||
const hadWindow = Object.hasOwn(globalThis, 'window');
|
||||
const hadDocument = Object.hasOwn(globalThis, 'document');
|
||||
const priorWindow = globalThis.window;
|
||||
@@ -1038,7 +1038,7 @@ function installWireHarness(picked, stateOverrides = {}) {
|
||||
},
|
||||
};
|
||||
const viewer = {
|
||||
scene: { pick: () => picked },
|
||||
scene: { pick: () => picked, ...sceneExtras },
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
// The camera port other layers follow through, with no pose to read; its
|
||||
@@ -1993,6 +1993,75 @@ test('vessel interaction wire: a sibling-owned pick wins without selection mutat
|
||||
}
|
||||
});
|
||||
|
||||
// A trail acts for nobody: the vessel's card painted over it still selects,
|
||||
// and a bare trail pick stays a no-op that keeps the selection.
|
||||
test('vessel interaction wire: a card over a trail selects; a bare trail is a no-op', () => {
|
||||
for (const carded of [true, false]) {
|
||||
const harness = installWireHarness(
|
||||
{ id: 'gev-trail:fl-a1b2c3:head' },
|
||||
{ selectedRecord: null },
|
||||
);
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(carded ? `vessel:${harness.record.mmsi}` : null),
|
||||
);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, carded ? 1 : 0, `card: ${carded}`);
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null,
|
||||
carded ? harness.record.mmsi : null,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap on the vessel's card finds a fire nearby through the shared
|
||||
// touch contact. The fire layer acts only on exact hits, so the card keeps the
|
||||
// tap; an exact fire pick under the card still belongs to the fire.
|
||||
test('vessel interaction wire: a coarse near miss of an exact-only item keeps the card tap', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = 'fire:near-miss';
|
||||
registerPickOwner('test-exact-fires', (pickedId) => pickedId === fire);
|
||||
t.after(() => unregisterPickOwner('test-exact-fires'));
|
||||
for (const exact of [false, true]) {
|
||||
const harness = installWireHarness(
|
||||
exact ? { id: fire } : null,
|
||||
{ selectedRecord: null },
|
||||
{ drillPick: () => [{ id: fire }] },
|
||||
);
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, exact ? 0 : 1, `exact fire: ${exact}`);
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null,
|
||||
exact ? null : harness.record.mmsi,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const card of ['live', 'stale', 'absent', 'covered']) {
|
||||
test(`vessel interaction wire: ${card} foreground card over registered cyclone`, () => {
|
||||
const id = 'cyclone:fixture:cone:0';
|
||||
|
||||
@@ -63,6 +63,7 @@ function harness({
|
||||
withDataSource = false,
|
||||
withGlobe = false,
|
||||
feed = null,
|
||||
drilled = null,
|
||||
} = {}) {
|
||||
const hadWindow = Object.hasOwn(globalThis, 'window');
|
||||
const priorWindow = globalThis.window;
|
||||
@@ -112,6 +113,7 @@ function harness({
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick,
|
||||
...(drilled ? { drillPick: () => drilled } : {}),
|
||||
canvas: { clientWidth: 1280, clientHeight: 800 },
|
||||
camera: cameraPosition ? { positionWC: cameraPosition } : undefined,
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
@@ -162,6 +164,9 @@ function harness({
|
||||
cover: (hit) => {
|
||||
topCard = hit;
|
||||
},
|
||||
setPicked: (next) => {
|
||||
picked = next;
|
||||
},
|
||||
cleanup() {
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = priorProjection;
|
||||
if (hadWindow) globalThis.window = priorWindow;
|
||||
@@ -461,6 +466,116 @@ for (const [layerId, ownedId, picked] of SIBLING_PICKS) {
|
||||
});
|
||||
}
|
||||
|
||||
// A passive owner's pick (a directions route, a flight trail) acts for nobody:
|
||||
// a fire card over it still takes the click, and with no card the pick is
|
||||
// still not empty space, so the selection stays.
|
||||
test('a fire card acts over a passive pick; the bare pick leaves the selection', () => {
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-route', (pickedId) => pickedId === 'route:line', {
|
||||
passive: true,
|
||||
});
|
||||
const carded = harness({
|
||||
fires: [fire],
|
||||
picked: { id: 'route:line' },
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
carded.click();
|
||||
assert.equal(carded.requests.length, 1, 'the card acts over the route');
|
||||
assert.ok(carded.layer.getSelectedInfo());
|
||||
} finally {
|
||||
carded.cleanup();
|
||||
}
|
||||
const bare = harness({ fires: [fire], picked: { id: 'route:line' } });
|
||||
try {
|
||||
bare.click();
|
||||
assert.equal(bare.requests.length, 0);
|
||||
assert.equal(
|
||||
bare.layer.getSelectedInfo(),
|
||||
null,
|
||||
'nothing to clear or pick',
|
||||
);
|
||||
} finally {
|
||||
bare.cleanup();
|
||||
unregisterPickOwner('test-route');
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap on a fire card finds an aircraft nearby through the shared
|
||||
// touch contact. The flights layer acts on that contact, so the card yields:
|
||||
// one action, not two.
|
||||
test('a fire card yields to a touch contact its layer acts on', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
t.after(() => unregisterPickOwner('test-planes'));
|
||||
const h = harness({
|
||||
fires: [fire],
|
||||
drilled: [{ id: 'plane:1' }],
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 0, 'the aircraft takes the tap');
|
||||
assert.equal(h.layer.getSelectedInfo(), null);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
// A touch contact whose layer acts only on exact hits does not take the tap
|
||||
// from our card; with no card, a coarse tap near an aircraft still clears.
|
||||
test('a fire card keeps a tap whose contact does not act; bare taps still clear', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-cameras', (pickedId) => pickedId === 'cam:1');
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterPickOwner('test-cameras');
|
||||
unregisterPickOwner('test-planes');
|
||||
});
|
||||
const carded = harness({
|
||||
fires: [fire],
|
||||
drilled: [{ id: 'cam:1' }],
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
carded.click();
|
||||
assert.equal(carded.requests.length, 1, 'the card acts');
|
||||
} finally {
|
||||
carded.cleanup();
|
||||
}
|
||||
const bare = harness({
|
||||
fires: [fire],
|
||||
picked: glowPick('firms-7'),
|
||||
drilled: [{ id: 'plane:1' }],
|
||||
});
|
||||
try {
|
||||
bare.click();
|
||||
assert.ok(bare.layer.getSelectedInfo(), 'a fire is selected');
|
||||
// Nothing exact now; the touch contact is an aircraft, with no card.
|
||||
bare.setPicked(null);
|
||||
bare.click();
|
||||
assert.equal(bare.layer.getSelectedInfo(), null, 'the bare tap clears');
|
||||
} finally {
|
||||
bare.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('a stale card id resolves to nothing instead of an arbitrary fire', () => {
|
||||
const h = harness({
|
||||
picked: { primitive: {}, content: {}, featureId: 0 },
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Which pick owners select nearby contacts. A coarse tap's shared contact
|
||||
* hit (`pickContact`) can land on a contact near an exact miss; only owners
|
||||
* whose click handlers act on such a hit, or on their own pick window,
|
||||
* register `expanded`, so a quake card or label yields to them and not to
|
||||
* exact-only owners (FIRMS, CCTV). Each case runs the layer's own
|
||||
* registration code (its enable or install step) with stand-in services.
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createLifecycle as createFlightLifecycle } from '../layers/flights/lifecycle.js';
|
||||
import { createLifecycle as createMilitaryLifecycle } from '../layers/military/lifecycle.js';
|
||||
import { createLifecycle as createVesselLifecycle } from '../layers/vessels/lifecycle.js';
|
||||
import { createInteraction as createRadioInteraction } from '../layers/radio/interaction.js';
|
||||
import { createSelection as createStreetSelection } from '../layers/streetLevel/selection.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { STREET_LEVEL_LAYER_ID } from '../layers/streetLevel/policy.js';
|
||||
import * as picking from './pickRegistry.js';
|
||||
|
||||
/**
|
||||
* A stand-in for any collaborator: every property is another stand-in and
|
||||
* every call returns one, except the keys `given` names. Not a thenable.
|
||||
*/
|
||||
function stub(given = {}) {
|
||||
return new Proxy(function stand() {}, {
|
||||
get(target, key) {
|
||||
if (key in given) return given[key];
|
||||
if (key === 'then' || typeof key === 'symbol') return undefined;
|
||||
return stub();
|
||||
},
|
||||
set(target, key, value) {
|
||||
given[key] = value;
|
||||
return true;
|
||||
},
|
||||
apply: () => stub(),
|
||||
});
|
||||
}
|
||||
|
||||
/** Picking services that record each registration's options. */
|
||||
function recordingPicking() {
|
||||
const registered = new Map();
|
||||
return {
|
||||
registered,
|
||||
services: {
|
||||
...picking,
|
||||
registerPickOwner(layerId, predicate, options) {
|
||||
registered.set(layerId, options ?? {});
|
||||
picking.registerPickOwner(layerId, predicate, options);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function withDocument(t) {
|
||||
const previous = globalThis.document;
|
||||
globalThis.document = {
|
||||
body: { classList: { contains: () => false } },
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
};
|
||||
t.after(() => {
|
||||
if (previous === undefined) delete globalThis.document;
|
||||
else globalThis.document = previous;
|
||||
});
|
||||
}
|
||||
|
||||
/** A quake card over `pickedId` reached as a nearby touch contact. */
|
||||
const actsOnNearbyHit = (pickedId) =>
|
||||
picking.isActedOnByOtherLayer('earthquakes', pickedId, { expanded: true });
|
||||
|
||||
for (const [name, layerId, create] of [
|
||||
['flights', 'flights', createFlightLifecycle],
|
||||
['military', 'military', createMilitaryLifecycle],
|
||||
]) {
|
||||
test(`${name} registers its aircraft as acting on nearby touch hits`, (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const flightState = stub({
|
||||
_icons: { show: false, has: (id) => id === `${name}-1` },
|
||||
records: { geoidReady: true },
|
||||
timeline: null,
|
||||
_trackedIcao: null,
|
||||
});
|
||||
const { methods: lifecycle } = create({
|
||||
flightState,
|
||||
services: stub({ picking: services }),
|
||||
parts: stub(),
|
||||
layer: stub(),
|
||||
resolveAsset: () => '',
|
||||
});
|
||||
t.after(() => picking.unregisterPickOwner(layerId));
|
||||
lifecycle.enable({});
|
||||
assert.equal(registered.get(layerId)?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit(`${name}-1`), true);
|
||||
// A click on the aircraft already tracked is ignored, so it is passive.
|
||||
flightState._trackedIcao = `${name}-1`;
|
||||
assert.equal(actsOnNearbyHit(`${name}-1`), false);
|
||||
});
|
||||
}
|
||||
|
||||
test('vessels register their icons as acting on nearby touch hits', (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const state = {
|
||||
feed: { enabled: true, sessionId: 1 },
|
||||
records: { byId: new Map([['vessel-1', {}]]) },
|
||||
viewer: {},
|
||||
};
|
||||
const created = createVesselLifecycle({
|
||||
vesselState: stub({ state, _geoidReady: true }),
|
||||
services: stub({ picking: services }),
|
||||
parts: stub(),
|
||||
});
|
||||
const lifecycle = created.methods ?? created;
|
||||
t.after(() => picking.unregisterPickOwner('ais-live-vessels'));
|
||||
lifecycle.enable({});
|
||||
assert.equal(registered.get('ais-live-vessels')?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('vessel-1'), true);
|
||||
});
|
||||
|
||||
test('radio registers its stations as acting on nearby touch hits', (t) => {
|
||||
const { registered, services } = recordingPicking();
|
||||
const viewer = { scene: { canvas: new EventTarget(), pick: () => null } };
|
||||
const input = fakeInput(viewer);
|
||||
const state = { _viewer: viewer, _clickSubscription: null };
|
||||
const interaction = createRadioInteraction({
|
||||
state,
|
||||
services: { picking: services, overlays: stub() },
|
||||
parts: stub(),
|
||||
});
|
||||
t.after(() => {
|
||||
interaction.removeInteraction();
|
||||
input.destroy();
|
||||
});
|
||||
interaction.installInteraction();
|
||||
assert.equal(registered.get('radio')?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('radio:kexp'), true);
|
||||
interaction.removeInteraction();
|
||||
assert.equal(actsOnNearbyHit('radio:kexp'), false);
|
||||
});
|
||||
|
||||
test('Street Level registers its picks as acting on nearby touch hits', (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const viewer = { scene: { canvas: new EventTarget(), pick: () => null } };
|
||||
const input = fakeInput(viewer);
|
||||
const state = { services: { picking: services }, clickSubscription: null };
|
||||
const selection = createStreetSelection({
|
||||
state,
|
||||
parts: stub({
|
||||
router: {
|
||||
ownsPick: (id) => id === 'mly:seq-1',
|
||||
resolve: (id) => (id === 'mly:seq-1' ? { id, instance: {} } : null),
|
||||
},
|
||||
}),
|
||||
});
|
||||
t.after(() => {
|
||||
state.clickSubscription?.();
|
||||
picking.unregisterPickOwner(STREET_LEVEL_LAYER_ID);
|
||||
input.destroy();
|
||||
});
|
||||
selection.install(viewer);
|
||||
assert.equal(registered.get(STREET_LEVEL_LAYER_ID)?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('mly:seq-1'), true);
|
||||
});
|
||||
@@ -33,6 +33,8 @@ const _owners = new Map();
|
||||
* @type {Map<string, true | ((pickedId: string) => boolean)>}
|
||||
*/
|
||||
const _passive = new Map();
|
||||
/** Owners whose click handlers also select nearby contacts. */
|
||||
const _expanded = new Set();
|
||||
/**
|
||||
* Layers whose shapes are background to any card painted over them: their
|
||||
* click handlers stand aside under a card, so the card's layer may act there.
|
||||
@@ -60,14 +62,22 @@ export function resolvePickId(hit) {
|
||||
* @param {string} layerId - Owning layer id (e.g. 'flights').
|
||||
* @param {(pickedId: string) => boolean} predicate - Returns true when the
|
||||
* picked primitive/entity id belongs to this layer.
|
||||
* @param {{passive?: boolean | ((pickedId: string) => boolean)}} [options]
|
||||
* @param {{passive?: boolean | ((pickedId: string) => boolean), expanded?: boolean}} [options]
|
||||
* `passive`: the layer never acts on a click on these picks (all of them,
|
||||
* or those the predicate names). See {@link isActedOnByOtherLayer}.
|
||||
* `expanded`: preserve precedence for handlers that select nearby contacts,
|
||||
* through the shared contact hit or their own pick window.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function registerPickOwner(layerId, predicate, { passive } = {}) {
|
||||
export function registerPickOwner(
|
||||
layerId,
|
||||
predicate,
|
||||
{ passive, expanded = false } = {},
|
||||
) {
|
||||
if (!layerId || typeof predicate !== 'function') return;
|
||||
_owners.set(layerId, predicate);
|
||||
if (expanded) _expanded.add(layerId);
|
||||
else _expanded.delete(layerId);
|
||||
if (passive === true || typeof passive === 'function')
|
||||
_passive.set(layerId, passive);
|
||||
else _passive.delete(layerId);
|
||||
@@ -80,6 +90,7 @@ export function registerPickOwner(layerId, predicate, { passive } = {}) {
|
||||
*/
|
||||
export function unregisterPickOwner(layerId) {
|
||||
_owners.delete(layerId);
|
||||
_expanded.delete(layerId);
|
||||
_passive.delete(layerId);
|
||||
}
|
||||
|
||||
@@ -125,12 +136,18 @@ export function isOwnedByOtherLayer(layerId, pickedId) {
|
||||
* painted over a passive pick (a flight trail) is still the card's click.
|
||||
* @param {string} layerId - The asking layer's id (excluded from the scan).
|
||||
* @param {string} pickedId - Picked primitive/entity id.
|
||||
* @param {{expanded?: boolean}} [options] A nearby rather than exact hit:
|
||||
* only owners whose handlers select nearby contacts take precedence.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isActedOnByOtherLayer(layerId, pickedId) {
|
||||
export function isActedOnByOtherLayer(
|
||||
layerId,
|
||||
pickedId,
|
||||
{ expanded = false } = {},
|
||||
) {
|
||||
if (!pickedId) return false;
|
||||
for (const [ownerId, predicate] of _owners) {
|
||||
if (ownerId === layerId) continue;
|
||||
if (ownerId === layerId || (expanded && !_expanded.has(ownerId))) continue;
|
||||
try {
|
||||
if (!predicate(pickedId)) continue;
|
||||
const passive = _passive.get(ownerId);
|
||||
|
||||
@@ -158,6 +158,40 @@ test('ownership: passive owners still own their picks but act on none of them',
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'route:line'), false);
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'route:step:3'), true);
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'plane:1'), true);
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
true,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
passive: true,
|
||||
});
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1');
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
unregisterPickOwner('test-plane');
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1');
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('test-plane', 'plane:1'),
|
||||
false,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { getContextStore, isContextRecordActive } from './contextStore.js';
|
||||
import { readEntityRecord } from './entityRecords.js';
|
||||
import { findPickOwner, resolvePickId } from './pickRegistry.js';
|
||||
import {
|
||||
findPickOwner,
|
||||
isActedOnByOtherLayer,
|
||||
resolvePickId,
|
||||
} from './pickRegistry.js';
|
||||
|
||||
/**
|
||||
* Resolve a pick (the contract's `Hit`, as `pickAt` in
|
||||
@@ -123,3 +127,25 @@ export function resolvePickedContext(picked, { dataManager = null } = {}) {
|
||||
altitudeM: finite(found?.altitudeM),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a world-overlay card or label under a click keeps it from the item
|
||||
* the click names, because that item's owner does not act on this hit: a
|
||||
* passive owner (a directions route) acts on none, and an owner that acts
|
||||
* only on exact hits (a fire, a camera) does not act on a coarse pointer's
|
||||
* nearby contact (`hit` is not the exact `topHit`). The card's layer takes
|
||||
* such a click (quake, fire, camera, vessel, news and wildlife cards act over
|
||||
* it; an inert card, such as a selected drone-zone card, does nothing), so
|
||||
* Context leaves the item; owners that act on it (an aircraft, a vessel, a
|
||||
* directions step) still name it.
|
||||
* @param {{hit?: object|null, topHit?: object|null}} click
|
||||
* @param {boolean} underCard Whether a world-overlay entry is under it.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function cardKeepsClick(click, underCard) {
|
||||
if (!underCard || !click?.hit) return false;
|
||||
const pickId = resolvePickId(click.hit);
|
||||
if (!pickId) return false;
|
||||
const expanded = pickId !== resolvePickId(click.topHit ?? null);
|
||||
return !isActedOnByOtherLayer('', pickId, { expanded });
|
||||
}
|
||||
@@ -12,7 +12,7 @@ globalThis.dispatchEvent ||= () => true;
|
||||
|
||||
const { registerEntityContext } = await import('./contextStore.js');
|
||||
const { registerPickOwner, unregisterPickOwner, findPickOwner } = await import('./pickRegistry.js');
|
||||
const { resolvePickedContext, pickedKindForLayer } = await import('./pickedContext.js');
|
||||
const { resolvePickedContext, pickedKindForLayer, cardKeepsClick } = await import('./pickedContext.js');
|
||||
|
||||
function manager({ enabled = new Set(['flights', 'local-datacenters']), modules = {} } = {}) {
|
||||
return {
|
||||
@@ -97,3 +97,53 @@ test('disabled layers, trails and empty picks never resolve', () => {
|
||||
assert.equal(resolvePickedContext(hit('unknown'), { dataManager: manager() }), null);
|
||||
assert.equal(pickedKindForLayer('ais-live-vessels'), 'vessel');
|
||||
});
|
||||
|
||||
test('a card keeps a click from items whose layer does not act on that hit', (t) => {
|
||||
registerPickOwner('test-fires', (id) => id === 'fire:1');
|
||||
registerPickOwner('test-planes', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: (id) => !id.startsWith('route:step:'),
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterPickOwner('test-fires');
|
||||
unregisterPickOwner('test-planes');
|
||||
unregisterPickOwner('test-route');
|
||||
});
|
||||
const fire = { set: 'fires:1', id: 'fire:1' };
|
||||
const plane = { set: 'planes:1', id: 'plane:1' };
|
||||
const exact = (hit) => ({ topHit: { ...hit }, hit });
|
||||
// A coarse tap: nothing exact, the contact found nearby.
|
||||
const near = (hit) => ({ topHit: null, hit });
|
||||
assert.equal(
|
||||
cardKeepsClick(near(fire), true),
|
||||
true,
|
||||
'fires act only on exact hits',
|
||||
);
|
||||
assert.equal(cardKeepsClick(near(plane), true), false, 'aircraft act nearby');
|
||||
assert.equal(
|
||||
cardKeepsClick(near(fire), false),
|
||||
false,
|
||||
'open map: Context names it',
|
||||
);
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(fire), true),
|
||||
false,
|
||||
"an exact fire is the fire's",
|
||||
);
|
||||
const line = { set: 'route:1', id: 'route:line' };
|
||||
const step = { set: 'route:1', id: 'route:step:2' };
|
||||
// Every card layer acts over a passive route, so the card keeps the click.
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(line), true),
|
||||
true,
|
||||
'a route acts for nobody',
|
||||
);
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(step), true),
|
||||
false,
|
||||
"a step is directions' own",
|
||||
);
|
||||
assert.equal(cardKeepsClick({ topHit: null, hit: null }, true), false);
|
||||
});
|
||||
@@ -28,6 +28,7 @@ export function createLifecycle({
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
isOwnedByOtherLayer,
|
||||
isActedOnByOtherLayer,
|
||||
isCardBackground,
|
||||
} = services.picking;
|
||||
const { onFocusTargetAppear } = services.focus;
|
||||
@@ -429,7 +430,26 @@ export function createLifecycle({
|
||||
typeof pickedId === 'string' &&
|
||||
!isOwnedByOtherLayer?.('cctv', pickedId) &&
|
||||
Boolean(isCardBackground?.(hit));
|
||||
if (pickedId !== null && !cardBackground) return;
|
||||
// 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);
|
||||
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 })
|
||||
)
|
||||
return;
|
||||
if (cardHit && cardHit.sourceId !== CCTV_OVERLAY_SOURCE_ID) return;
|
||||
if (cardId) {
|
||||
activateCctvCameraFromWorldClick(
|
||||
|
||||
@@ -84,7 +84,9 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
viewer.scene = {
|
||||
canvas: {},
|
||||
pick: () => (picked ? { id: picked } : undefined),
|
||||
drillPick: () => drilled.map((id) => ({ id })),
|
||||
};
|
||||
let drilled = [];
|
||||
const input = fakeInput(viewer);
|
||||
const ownCard = { sourceId: CCTV_OVERLAY_SOURCE_ID, entryId: 'cam-1' };
|
||||
const foreignCard = {
|
||||
@@ -141,6 +143,8 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
lifecycle.detachViewListeners();
|
||||
input.destroy();
|
||||
picking.unregisterPickOwner('area-control');
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
picking.unregisterCardBackground('area-fixture');
|
||||
});
|
||||
await lifecycle.methods.init(viewer);
|
||||
@@ -190,6 +194,37 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
{ ...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.
|
||||
const trail = { set: 'trails:1', id: 'gev-trail:fl-1:head', surface: false };
|
||||
picking.registerPickOwner('test-trails', (id) => id === trail.id, {
|
||||
passive: true,
|
||||
});
|
||||
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.
|
||||
const previousMatch = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
picking.registerPickOwner('test-planes', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
drilled = ['plane:1'];
|
||||
click(null, [ownCard], []);
|
||||
// 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.
|
||||
picking.registerPickOwner('test-exact', (id) => id === 'exact:1');
|
||||
drilled = ['exact:1'];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-exact');
|
||||
drilled = [];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
else delete globalThis.matchMedia;
|
||||
picking.registerPickOwner('area-control', (id) => id === drone.id);
|
||||
click(drone, [ownCard], []);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
|
||||
@@ -352,7 +352,11 @@ export function createEarthquakesLayer({
|
||||
const pickId = picking.resolvePickId(hit);
|
||||
const actedOn =
|
||||
picking.isActedOnByOtherLayer ?? picking.isOwnedByOtherLayer;
|
||||
if (pickId && actedOn(EARTHQUAKES_LAYER_ID, pickId)) return;
|
||||
// Exact-only handlers cannot act on a nearby touch hit. Compare ids,
|
||||
// since the dispatcher may expose distinct objects for the same pick.
|
||||
const expanded =
|
||||
'topHit' in click && picking.resolvePickId(click.topHit) !== pickId;
|
||||
if (pickId && actedOn(EARTHQUAKES_LAYER_ID, pickId, { expanded })) return;
|
||||
const cardHit = overlayHost.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
// Registers the shared `gev-trail:` owner as passive, as the app does.
|
||||
import '../../data/trailRenderer.js';
|
||||
import { createSelection as createFireSelection } from '../firms/selection.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
import { createDroneAirspaceLayer } from '../droneAirspace/index.js';
|
||||
import {
|
||||
@@ -36,7 +37,10 @@ const quake = (id, extra = {}) => ({
|
||||
});
|
||||
|
||||
/** A layer whose globe clicks, card hits and context store the test drives. */
|
||||
function harness(rows, { context = null, ripples = null } = {}) {
|
||||
function harness(
|
||||
rows,
|
||||
{ context = null, ripples = null, input: inputFactory = null } = {},
|
||||
) {
|
||||
let snapshot = rows;
|
||||
const handlers = [];
|
||||
const opened = [];
|
||||
@@ -50,41 +54,44 @@ function harness(rows, { context = null, ripples = null } = {}) {
|
||||
let foreignTop = null;
|
||||
const viewer = {};
|
||||
const { draw } = bindFakeDraw(viewer);
|
||||
const overlayHost = {
|
||||
setEntries(sourceId, entries) {
|
||||
if (sourceId === EARTHQUAKE_CARD_SOURCE_ID) cards.push(entries);
|
||||
if (sourceId === EARTHQUAKE_OVERLAY_SOURCE_ID) labels.push(entries);
|
||||
},
|
||||
setVisible: (sourceId, show) => visible.set(sourceId, show),
|
||||
clearSource() {},
|
||||
// As the real host does, only an interactive entry painted now is hit.
|
||||
hitTest(_x, _y, { sourceId } = {}) {
|
||||
// Unfiltered, as the host answers: another layer's entry on top
|
||||
// first, else this layer's own.
|
||||
if (!sourceId)
|
||||
return (
|
||||
foreignTop ??
|
||||
this.hitTest(_x, _y, { sourceId: EARTHQUAKE_CARD_SOURCE_ID }) ??
|
||||
this.hitTest(_x, _y, { sourceId: EARTHQUAKE_OVERLAY_SOURCE_ID })
|
||||
);
|
||||
const hit = overlayHits.get(sourceId);
|
||||
const painted =
|
||||
sourceId === EARTHQUAKE_CARD_SOURCE_ID ? cards.at(-1) : labels.at(-1);
|
||||
const entry = painted?.find((e) => e.id === hit?.entryId);
|
||||
return hit && entry?.interactive === true ? hit : null;
|
||||
},
|
||||
};
|
||||
const layer = createEarthquakesLayer({
|
||||
source: { getSnapshot: async () => snapshot },
|
||||
overlayHost: {
|
||||
setEntries(sourceId, entries) {
|
||||
if (sourceId === EARTHQUAKE_CARD_SOURCE_ID) cards.push(entries);
|
||||
if (sourceId === EARTHQUAKE_OVERLAY_SOURCE_ID) labels.push(entries);
|
||||
},
|
||||
setVisible: (sourceId, show) => visible.set(sourceId, show),
|
||||
clearSource() {},
|
||||
// As the real host does, only an interactive entry painted now is hit.
|
||||
hitTest(_x, _y, { sourceId } = {}) {
|
||||
// Unfiltered, as the host answers: another layer's entry on top
|
||||
// first, else this layer's own.
|
||||
if (!sourceId)
|
||||
return (
|
||||
foreignTop ??
|
||||
this.hitTest(_x, _y, { sourceId: EARTHQUAKE_CARD_SOURCE_ID }) ??
|
||||
this.hitTest(_x, _y, { sourceId: EARTHQUAKE_OVERLAY_SOURCE_ID })
|
||||
);
|
||||
const hit = overlayHits.get(sourceId);
|
||||
const painted =
|
||||
sourceId === EARTHQUAKE_CARD_SOURCE_ID ? cards.at(-1) : labels.at(-1);
|
||||
const entry = painted?.find((e) => e.id === hit?.entryId);
|
||||
return hit && entry?.interactive === true ? hit : null;
|
||||
},
|
||||
},
|
||||
input: () => ({
|
||||
onClick(callback) {
|
||||
const handler = { callback, destroyed: false };
|
||||
handlers.push(handler);
|
||||
return () => {
|
||||
handler.destroyed = true;
|
||||
};
|
||||
},
|
||||
}),
|
||||
overlayHost,
|
||||
input:
|
||||
inputFactory ??
|
||||
(() => ({
|
||||
onClick(callback) {
|
||||
const handler = { callback, destroyed: false };
|
||||
handlers.push(handler);
|
||||
return () => {
|
||||
handler.destroyed = true;
|
||||
};
|
||||
},
|
||||
})),
|
||||
picking,
|
||||
context,
|
||||
ripples,
|
||||
@@ -108,6 +115,8 @@ function harness(rows, { context = null, ripples = null } = {}) {
|
||||
visible,
|
||||
focused,
|
||||
handlers,
|
||||
overlayHost,
|
||||
overlayHits,
|
||||
discs,
|
||||
setRows(next) {
|
||||
snapshot = next;
|
||||
@@ -657,7 +666,9 @@ test('a touch-expanded sibling hit takes precedence over a quake label', async (
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
h.clickDisc('ak1');
|
||||
picking.registerPickOwner('test-plane', (id) => id === 'plane-9');
|
||||
picking.registerPickOwner('test-plane', (id) => id === 'plane-9', {
|
||||
expanded: true,
|
||||
});
|
||||
h.clickOverlayWith(EARTHQUAKE_OVERLAY_SOURCE_ID, 'ak2', null, {
|
||||
set: 'flights:1',
|
||||
id: 'plane-9',
|
||||
@@ -931,3 +942,78 @@ test('quake card and label act over a flight trail and a directions route', asyn
|
||||
h.layer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('coarse FIRMS near-misses leave quake overlays actionable; exact fire hits act once', async (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
let sceneHit = null;
|
||||
const fireHit = { set: 'firms:test', id: 'fire:test' };
|
||||
let input;
|
||||
const h = harness([quake('ak1')], {
|
||||
input(viewer) {
|
||||
viewer.scene = {
|
||||
pick: () => (sceneHit ? { id: sceneHit } : null),
|
||||
drillPick: () => [{ id: fireHit }],
|
||||
};
|
||||
input ??= fakeInput(viewer);
|
||||
return input.input;
|
||||
},
|
||||
});
|
||||
const fire = { lat: 60, lon: -153, frp: 5, acqMs: 1, sensor: 'test' };
|
||||
const fireFocus = [];
|
||||
const state = {
|
||||
_viewer: h.viewer,
|
||||
_icons: { id: fireHit.set },
|
||||
_pickIndexById: new Map([[fireHit.id, fire]]),
|
||||
_fireByCardId: new Map(),
|
||||
_contextIds: new Set(),
|
||||
};
|
||||
const selection = createFireSelection({
|
||||
layerState: state,
|
||||
services: {
|
||||
picking,
|
||||
context: {},
|
||||
focus: { requestWorldFocus: (x) => fireFocus.push(x) },
|
||||
},
|
||||
components: {
|
||||
cards: { rebuildAmbientLabels() {} },
|
||||
model: { firePosition: () => ({ x: 1, y: 2, z: 3 }) },
|
||||
},
|
||||
config: { id: 'firms', name: 'FIRMS', overlayHost: h.overlayHost },
|
||||
feed: {},
|
||||
});
|
||||
try {
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
selection.installClickHandler();
|
||||
picking.registerPickOwner('firms', (id) => state._pickIndexById.has(id));
|
||||
h.overlayHits.set(EARTHQUAKE_OVERLAY_SOURCE_ID, {
|
||||
sourceId: EARTHQUAKE_OVERLAY_SOURCE_ID,
|
||||
entryId: 'ak1',
|
||||
});
|
||||
input.click();
|
||||
assert.equal(h.focused.length, 1, 'label acts on the exact miss');
|
||||
assert.equal(fireFocus.length, 0, 'nearby fire does not act');
|
||||
h.overlayHits.clear();
|
||||
h.overlayHits.set(EARTHQUAKE_CARD_SOURCE_ID, {
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
entryId: 'earthquake-card:ak1',
|
||||
});
|
||||
input.click();
|
||||
assert.equal(h.opened.length, 1, 'selected card opens once');
|
||||
assert.equal(fireFocus.length, 0);
|
||||
sceneHit = fireHit;
|
||||
input.click();
|
||||
assert.equal(fireFocus.length, 1, 'exact fire hit acts');
|
||||
assert.equal(h.opened.length, 1, 'card yields to the exact fire');
|
||||
} finally {
|
||||
selection.removeClickHandler();
|
||||
picking.unregisterPickOwner('firms');
|
||||
h.layer.destroy();
|
||||
input?.destroy();
|
||||
}
|
||||
});
|
||||
@@ -13,7 +13,8 @@ export function createSelection({
|
||||
config,
|
||||
feed,
|
||||
}) {
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
const { resolvePickId, isOwnedByOtherLayer, isActedOnByOtherLayer } =
|
||||
services.picking;
|
||||
const { requestWorldFocus } = services.focus;
|
||||
const {
|
||||
selectEntityContext,
|
||||
@@ -42,14 +43,34 @@ export function createSelection({
|
||||
}
|
||||
// A pick that belongs to a sibling layer (e.g. an aircraft) is not
|
||||
// "empty space" — leave the selection alone and let that layer handle it.
|
||||
// A passive owner's pick (a flight trail, a directions route) acts for
|
||||
// nobody, so a card of ours painted over it still takes the click.
|
||||
let passivePick = false;
|
||||
if (picked) {
|
||||
const pickedId = resolvePickId(picked);
|
||||
if (pickedId && isOwnedByOtherLayer(id, pickedId)) return;
|
||||
if (pickedId && isOwnedByOtherLayer(id, pickedId)) {
|
||||
passivePick =
|
||||
Boolean(isActedOnByOtherLayer) &&
|
||||
!isActedOnByOtherLayer(id, pickedId);
|
||||
if (!passivePick) return;
|
||||
}
|
||||
}
|
||||
const cardHit = overlayHost.hitTest?.(
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
);
|
||||
if (passivePick && cardHit?.sourceId !== FIRMS_OVERLAY_SOURCE_ID) 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 (
|
||||
cardHit &&
|
||||
contactId &&
|
||||
contactId !== resolvePickId(picked ?? null) &&
|
||||
isActedOnByOtherLayer?.(id, contactId, { expanded: true })
|
||||
)
|
||||
return;
|
||||
if (cardHit) {
|
||||
if (cardHit.sourceId !== FIRMS_OVERLAY_SOURCE_ID) return;
|
||||
const carded = layerState._fireByCardId.get(cardHit.entryId);
|
||||
|
||||
@@ -134,6 +134,14 @@ export function createLifecycle({
|
||||
registerPickOwner(
|
||||
'flights',
|
||||
(pickedId) => flightState._icons?.has(pickedId) === true,
|
||||
{
|
||||
expanded: true,
|
||||
// A click on the aircraft already tracked is ignored: for that one
|
||||
// plane the layer acts on nothing, so a card over it keeps the tap.
|
||||
passive: (pickedId) =>
|
||||
Boolean(flightState._trackedIcao) &&
|
||||
pickedId === flightState._trackedIcao,
|
||||
},
|
||||
);
|
||||
const frame = findFrame(viewer);
|
||||
if (!flightState._preRenderRemove && frame) {
|
||||
|
||||
@@ -115,6 +115,14 @@ export function createLifecycle({
|
||||
registerPickOwner(
|
||||
'military',
|
||||
(pickedId) => flightState._icons?.has(pickedId) === true,
|
||||
{
|
||||
expanded: true,
|
||||
// A click on the aircraft already tracked is ignored: for that one
|
||||
// plane the layer acts on nothing, so a card over it keeps the tap.
|
||||
passive: (pickedId) =>
|
||||
Boolean(flightState._trackedIcao) &&
|
||||
pickedId === flightState._trackedIcao,
|
||||
},
|
||||
);
|
||||
// The flights layer suppresses its military duplicates while we render them
|
||||
setMilitaryLayerActive(true);
|
||||
|
||||
@@ -5,11 +5,7 @@ import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
|
||||
import { NEWS_KEY_PROVIDERS, createNewsLayer } from './index.js';
|
||||
import {
|
||||
findPickOwner,
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
} from '../../data/pickRegistry.js';
|
||||
import { findPickOwner } from '../../data/pickRegistry.js';
|
||||
// Registers the shared `gev-trail:` no-op owner, as the app does.
|
||||
import '../../data/trailRenderer.js';
|
||||
import { getSelectedEntityContext } from '../../data/contextStore.js';
|
||||
|
||||
@@ -48,11 +48,26 @@ export function createInteraction({
|
||||
RADIO_PICK_WINDOW_PX,
|
||||
)) {
|
||||
const stationId = stationFromPick(picked);
|
||||
if (stationId) return stationId;
|
||||
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;
|
||||
return stationId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Whether another layer's world-overlay card or label is under a click. */
|
||||
function foreignCardAt(event) {
|
||||
const top = services.overlays?.hitTestWorldOverlay?.(
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
);
|
||||
return Boolean(top) && top.sourceId !== RADIO_OVERLAY_SOURCE_ID;
|
||||
}
|
||||
|
||||
function radioPresentationAllowed() {
|
||||
if (!layerState._managerLifecyclePresentation) return layerState._enabled;
|
||||
return (
|
||||
@@ -80,7 +95,9 @@ export function createInteraction({
|
||||
|
||||
function installInteraction() {
|
||||
if (!layerState._viewer || layerState._clickSubscription) return;
|
||||
registerPickOwner('radio', (id) => id.startsWith(RADIO_PREFIX));
|
||||
registerPickOwner('radio', (id) => id.startsWith(RADIO_PREFIX), {
|
||||
expanded: true,
|
||||
});
|
||||
const viewer = layerState._viewer;
|
||||
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!radioPresentationAllowed()) return;
|
||||
|
||||
@@ -62,3 +62,42 @@ test('a direct hit needs no drill, and another layer’s contact keeps its click
|
||||
});
|
||||
assert.equal(pickedRadioStationAt(other), null);
|
||||
});
|
||||
|
||||
// A station found only through radio's wider window, not as the tap's own
|
||||
// pick or its touch contact, sits under another layer's card or label: that
|
||||
// layer acts and never sees this window, so radio leaves the click.
|
||||
test('a window-only station yields to a card painted over it', () => {
|
||||
let top = null;
|
||||
const radio = createInteraction({
|
||||
state: { _stationById: new Map([['kexp', {}]]) },
|
||||
services: {
|
||||
picking: {
|
||||
resolvePickId: (picked) => picked?.id ?? null,
|
||||
isOwnedByOtherLayer: () => false,
|
||||
registerPickOwner() {},
|
||||
unregisterPickOwner() {},
|
||||
},
|
||||
overlays: {
|
||||
setOverlaySourceVisible() {},
|
||||
hitTestWorldOverlay: () => top,
|
||||
},
|
||||
},
|
||||
parts: { rendering: { radioStationIdFromPick } },
|
||||
});
|
||||
const station = hit('radio:kexp');
|
||||
const near = (contact = null) => ({
|
||||
...clickEvent({ windowHits: [station] }),
|
||||
hit: contact,
|
||||
screenPosition: { x: 5, y: 5 },
|
||||
});
|
||||
assert.equal(radio.pickedRadioStationAt(near()), 'kexp', 'open map');
|
||||
top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
|
||||
assert.equal(radio.pickedRadioStationAt(near()), null, 'under a quake card');
|
||||
assert.equal(
|
||||
radio.pickedRadioStationAt(near(station)),
|
||||
'kexp',
|
||||
'the touch contact: the card yielded to the station',
|
||||
);
|
||||
top = { sourceId: 'radio', entryId: 'radio:kexp' };
|
||||
assert.equal(radio.pickedRadioStationAt(near()), 'kexp', 'our own card');
|
||||
});
|
||||
@@ -24,7 +24,23 @@ export function createSelection({ state, parts }) {
|
||||
function onClick(event) {
|
||||
if (!state.viewer || !state.enabled) return;
|
||||
const hit = event.windowHit(CLICK_PICK_WINDOW_PX, CLICK_PICK_WINDOW_PX);
|
||||
const route = parts.router.resolve(pickIdOf(hit));
|
||||
const windowId = pickIdOf(hit);
|
||||
// A coarse tap's touch contact (event.hit) reaches farther than this
|
||||
// window; a card or label over it yields to our item there, so it is ours.
|
||||
const contact = event.hit;
|
||||
const contactId =
|
||||
contact && !contact.surface
|
||||
? pickIdOf({ drawHit: contact.set ? contact : null, id: event.id })
|
||||
: null;
|
||||
let route = parts.router.resolve(windowId);
|
||||
// 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.
|
||||
if (route && windowId !== contactId) {
|
||||
const at = event.screenPosition;
|
||||
if (state.services.overlayHit?.(at?.x, at?.y)) return;
|
||||
}
|
||||
if (!route && contactId) route = parts.router.resolve(contactId);
|
||||
// Not ours: the ground handler decides whether it is the map itself.
|
||||
if (!route) {
|
||||
parts.openAtGround?.({ surface: hit.surface, ground: groundOf(event) });
|
||||
@@ -71,7 +87,12 @@ export function createSelection({ state, parts }) {
|
||||
if (state.clickSubscription) return;
|
||||
state.clickSubscription = inputFor(viewer).onClick(onClick);
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick);
|
||||
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick, {
|
||||
expanded: true,
|
||||
// The core's position marker is ours but selects nothing: a card over
|
||||
// it keeps the tap.
|
||||
passive: (id) => !parts.router.resolve(id)?.instance,
|
||||
});
|
||||
}
|
||||
|
||||
function uninstall() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Cesium from 'cesium';
|
||||
import { createSelection } from './selection.js';
|
||||
import { createPickRouter } from './pickRouter.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
import * as pickRegistry from '../../data/pickRegistry.js';
|
||||
|
||||
/** The selection installed on a stand-in viewer, with what its clicks reach. */
|
||||
function harness({
|
||||
@@ -289,3 +290,137 @@ test('a click on a provider line hands it the ground under the click, measured o
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// An image found only through Street Level's own window (not the exact pick)
|
||||
// under another layer's card or label is that card's click: its layer never
|
||||
// sees this window.
|
||||
test('an item found only in our window yields to a card painted over it', () => {
|
||||
let top = null;
|
||||
const h = harness({
|
||||
services: { overlayHit: () => top },
|
||||
sceneExtras: {
|
||||
pick: (_position, width = 3) =>
|
||||
width >= 9 ? { id: 'mly:img:near' } : null,
|
||||
},
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.deepEqual(h.opened, ['near'], 'open map: the window finds it');
|
||||
top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
|
||||
h.click();
|
||||
assert.deepEqual(h.opened, ['near'], 'under a card: the card keeps it');
|
||||
assert.equal(h.groundClicks.length, 0);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap's touch contact reaches farther than this window. A quake card
|
||||
// or label over that contact yields to it, so Street Level takes it here.
|
||||
test('a coarse touch contact beyond our window is ours to open', (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: () => null,
|
||||
drillPick: () => [{ id: 'mly:img:contact' }],
|
||||
},
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.deepEqual(h.opened, ['contact']);
|
||||
assert.equal(h.groundClicks.length, 0);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// The exact hit or the touch contact is ours under a card too: a quake card
|
||||
// or label yields to a Street Level owner's pick, so yielding back would
|
||||
// leave the click dead. Line parts compare by the sequence they pick as.
|
||||
test('an exact or contact hit on our line part acts under a card', (t) => {
|
||||
const part = {
|
||||
set: 'street-level:mapillary-coverage:1',
|
||||
id: 'mly:seq:abc#2',
|
||||
meta: { pick: 'mly:seq:abc' },
|
||||
};
|
||||
const card = () => ({ sourceId: 'earthquake-card', entryId: 'q' });
|
||||
const exact = harness({ services: { overlayHit: card } });
|
||||
try {
|
||||
exact.scene.under = part;
|
||||
exact.click();
|
||||
assert.deepEqual(exact.sequences.selects, ['abc'], 'mouse, exact part');
|
||||
} finally {
|
||||
exact.restore();
|
||||
}
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const contact = harness({
|
||||
services: { picking: pickRegistry, overlayHit: card },
|
||||
sceneExtras: {
|
||||
pick: (_position, width = 3) => (width >= 9 ? { id: part } : null),
|
||||
drillPick: () => [{ id: part }],
|
||||
},
|
||||
});
|
||||
try {
|
||||
contact.click();
|
||||
assert.deepEqual(contact.sequences.selects, ['abc'], 'coarse contact');
|
||||
} finally {
|
||||
contact.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// Our window catching another layer's item says nothing about our own touch
|
||||
// contact beyond it: that contact is still ours under a card.
|
||||
test('a contact of ours acts even when our window finds another item', (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: { set: 'flights:1', id: 'flight:9' } } : null,
|
||||
drillPick: () => [{ id: 'mly:img:contact' }],
|
||||
},
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.deepEqual(h.opened, ['contact']);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// The core's position marker is ours but selects nothing, so it is a passive
|
||||
// pick: a card painted over it keeps the tap. Our images and lines act.
|
||||
test('the position marker is a passive pick; our items act', () => {
|
||||
const h = harness({ services: { picking: pickRegistry } });
|
||||
try {
|
||||
const acted = (id) =>
|
||||
pickRegistry.isActedOnByOtherLayer('test-card', id, { expanded: true });
|
||||
assert.equal(pickRegistry.findPickOwner('sl:pos'), 'street-level');
|
||||
assert.equal(acted('sl:pos'), false, 'the marker acts for nobody');
|
||||
assert.equal(acted('mly:img:abc'), true, 'an image opens');
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
@@ -192,8 +192,10 @@ export function createLifecycle({
|
||||
});
|
||||
}
|
||||
// Pick-ownership (H2): a vessel icon's pick id is its row id, the record's id.
|
||||
registerPickOwner('ais-live-vessels', (pickedId) =>
|
||||
state.records.byId.has(pickedId),
|
||||
registerPickOwner(
|
||||
'ais-live-vessels',
|
||||
(pickedId) => state.records.byId.has(pickedId),
|
||||
{ expanded: true },
|
||||
);
|
||||
// Vessels are asked for by view, so ask again when the view moves away.
|
||||
removeViewListener();
|
||||
|
||||
@@ -10,7 +10,8 @@ export function createSelection({
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { isOwnedByOtherLayer } = services.picking;
|
||||
const { isOwnedByOtherLayer, isActedOnByOtherLayer, resolvePickId } =
|
||||
services.picking;
|
||||
const { requestWorldFocus } = services.worldFocus;
|
||||
const {
|
||||
selectEntityContext,
|
||||
@@ -47,19 +48,46 @@ export function createSelection({
|
||||
// `gev-trail:*` pick is also a no-op. Every other non-vessel pick — sibling
|
||||
// unowned scene picks dismiss the current vessel inspection.
|
||||
if (ownRecordPick && (!pickedId || !record)) return;
|
||||
if (pickedId && !record && String(pickedId).startsWith('gev-trail:'))
|
||||
return;
|
||||
/** Whether this layer's own card is painted under the click. */
|
||||
const ownCardUnder = () =>
|
||||
vesselState._vesselOverlayHost.hitTest?.(
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
)?.sourceId === VESSEL_OVERLAY_SOURCE_ID;
|
||||
// A passive owner's pick (a trail, a directions route) acts for nobody:
|
||||
// a card of ours painted over it keeps the click; otherwise a no-op.
|
||||
const passivePick =
|
||||
Boolean(pickedId) &&
|
||||
!record &&
|
||||
(String(pickedId).startsWith('gev-trail:') ||
|
||||
(Boolean(isActedOnByOtherLayer) &&
|
||||
isOwnedByOtherLayer('ais-live-vessels', pickedId) &&
|
||||
!isActedOnByOtherLayer('ais-live-vessels', pickedId)));
|
||||
if (passivePick && !ownCardUnder()) return;
|
||||
|
||||
// A sibling layer already owns this click. Preserve the current vessel
|
||||
// selection and do not compete with its camera command.
|
||||
const siblingOwned =
|
||||
pickedId && isOwnedByOtherLayer('ais-live-vessels', pickedId);
|
||||
!passivePick &&
|
||||
pickedId &&
|
||||
isOwnedByOtherLayer('ais-live-vessels', pickedId);
|
||||
// Cyclone geometry is ambient context behind painted cards. Its handler
|
||||
// yields to the same foreground AIS hit. Keep moving-contact precedence
|
||||
// unchanged: those handlers may issue their own camera command.
|
||||
const cycloneBackground =
|
||||
siblingOwned && !isOwnedByOtherLayer('weather-cyclones', pickedId);
|
||||
if (siblingOwned && !cycloneBackground) return;
|
||||
if (siblingOwned && !cycloneBackground) {
|
||||
// A coarse tap's nearby contact (not the exact pick) whose layer acts
|
||||
// only on exact hits (a fire, a camera) does not take a tap on this
|
||||
// layer's own card: that card keeps it.
|
||||
const nearMissOfExactOnly =
|
||||
isActedOnByOtherLayer &&
|
||||
resolvePickId?.(event.topHit ?? null) !== pickedId &&
|
||||
!isActedOnByOtherLayer('ais-live-vessels', pickedId, {
|
||||
expanded: true,
|
||||
});
|
||||
if (!nearMissOfExactOnly || !ownCardUnder()) return;
|
||||
}
|
||||
|
||||
// Cards are painted on a pointer-events:none canvas, so the scene pick is
|
||||
// usually terrain behind the card. Resolve against the host's current
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { cardKeepsClick, resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { followedOf, onFollowChanged } from '../data/followed.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
@@ -315,6 +315,12 @@ export function installEntityContext({
|
||||
dataManager: getDataManager(),
|
||||
});
|
||||
if (identity) {
|
||||
// A card or label painted over an item its layer does not act on here
|
||||
// (a quake card beside a fire, or over a route) is the card's click.
|
||||
const underCard = Boolean(
|
||||
overlayHit?.(event.screenPosition?.x, event.screenPosition?.y),
|
||||
);
|
||||
if (cardKeepsClick(event, underCard)) return;
|
||||
// These layers start following on their own click; following again
|
||||
// from here would fight them (the flights layer reads a second track
|
||||
// of the same plane as a click on empty map and lets go).
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createPinia } from 'pinia';
|
||||
import { installEntityContext } from './entityContextBridge.js';
|
||||
import { useEntityCardStore } from './stores/entityCard.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import {
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
} from '../data/pickRegistry.js';
|
||||
|
||||
// A coarse tap that misses everything exactly finds a fire within the shared
|
||||
// touch window. On open map Context names it; under a quake card or label the
|
||||
// card takes the tap, since the fire layer acts only on exact hits; an exact
|
||||
// hit on the fire is the fire's, under a card or not.
|
||||
test('Context leaves a near-missed exact-only item to a card painted over it', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = { set: 'test-fires:1', id: 'fire:1' };
|
||||
registerPickOwner('test-fires', (id) => id === fire.id);
|
||||
t.after(() => unregisterPickOwner('test-fires'));
|
||||
let exact = false;
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => (exact ? { id: fire } : null),
|
||||
drillPick: () => [{ id: fire }],
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
getDataManager: () => ({
|
||||
isEnabled: () => true,
|
||||
layers: new Map(),
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
input.destroy();
|
||||
});
|
||||
const store = useEntityCardStore(pinia);
|
||||
const named = [];
|
||||
store.select = (identity) => named.push(identity.id);
|
||||
const tap = () => {
|
||||
named.length = 0;
|
||||
input.click();
|
||||
return [...named];
|
||||
};
|
||||
assert.deepEqual(tap(), ['fire:1'], 'open map: Context names the fire');
|
||||
cardOnTop = true;
|
||||
assert.deepEqual(tap(), [], 'under a card: the card keeps the tap');
|
||||
exact = true;
|
||||
assert.deepEqual(tap(), ['fire:1'], 'an exact hit is the fire’s');
|
||||
});
|
||||
|
||||
// Every card layer acts over a passive owner's pick (a directions route), so
|
||||
// Context leaves an exact route hit under a card to that card, and names it on
|
||||
// open map as before.
|
||||
test('Context leaves an exact passive route under a card to the card', (t) => {
|
||||
const route = { set: 'test-route:1', id: 'route:line' };
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: true,
|
||||
});
|
||||
t.after(() => unregisterPickOwner('test-route'));
|
||||
const viewer = { scene: { pick: () => ({ id: route }) } };
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
getDataManager: () => ({
|
||||
isEnabled: () => true,
|
||||
layers: new Map(),
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
input.destroy();
|
||||
});
|
||||
const named = [];
|
||||
useEntityCardStore(pinia).select = (identity) => named.push(identity.id);
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'open map: Context names the route');
|
||||
cardOnTop = true;
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'under a card: the card keeps it');
|
||||
});
|
||||
Reference in new issue
Block a user