Scope pick ownership and selection dispatch to each scene

Create pick registries and selection dispatchers for each scene attachment,
publish them through scene.services, and release their predicates and input
subscriptions before parking the renderer. Resolve layer ownership with the
attached engine so identical layer IDs in simultaneous scenes cannot overwrite
or remove one another. Re-register retained ALPR and cyclone picks on attachment,
and resolve voice pointer picks against the engine that supplied the pick.

Preserve Cesium's selection, sibling ownership, inert trails, touch expansion,
drag and long-press rules on both engines. Extract the unchanged gesture
predicates so portable picking does not acquire a native input dependency.
Exercise scene isolation, teardown and reattachment on fake and headless Cesium
engines, retaining the existing layer assertions.

No coupling count falls or grows. Cesium and Navara renderer lines remain 0 and
189; external Cesium imports 3; viewer lines 910; Navara kind checks 2; engine
sniff calls 0; extension reads 3; ground passes 1; SDK loads 3; screen-handler
files 4; engine-name lines 33.
This commit is contained in:
German Khokhlov committed 2026-11-07 16:27:43 +04:00
1 parent 52c6f68bd5
commit 4252ed0798
53 files changed
+712 -277

No files matched your search

+4 -2
View File
@@ -32,7 +32,9 @@ import aisLiveVesselsLayer from './aisLiveVessels.js';
import { registerEntityContext, selectEntityContext } from './contextStore.js';
import { WORLD_FOCUS_REQUEST_EVENT } from '../worldFocus.js';
import { ensureGeoidReady, geoidHeight } from './geoid.js';
import { registerPickOwner, unregisterPickOwner } from './pickRegistry.js';
import { pickRegistryFor } from './pickRegistry.js';
const wireEngine = {};
const { registerPickOwner, unregisterPickOwner } = pickRegistryFor(wireEngine);
import { applyVesselOverlayPolicy } from './vesselLabels.js';
import { layerFeedState } from './manager.js';
import {
@@ -959,7 +961,7 @@ function installWireHarness(picked, stateOverrides = {}) {
trackedEntityChanged,
};
const renderer = ({ billboardCollection }) =>
vesselViewerRenderer({ viewer: followViewer, billboardCollection });
({ ...vesselViewerRenderer({ viewer: followViewer, billboardCollection }), engine: wireEngine });
_setVesselStateForTest({
records: [record],
selectedRecord: record,
+2 -2
View File
@@ -383,12 +383,12 @@ const SIBLING_PICKS = [
for (const [layerId, ownedId, picked] of SIBLING_PICKS) {
test(`a ${layerId} pick shaped ${JSON.stringify(picked)} wins over a card hit`, () => {
const fire = makeFire();
registerPickOwner(layerId, (pickedId) => pickedId === ownedId);
const h = harness({
fires: [fire],
picked,
cardHit: `fire:${fireDetectionKey(fire)}`,
});
registerPickOwner(layerId, (pickedId) => pickedId === ownedId, h.engine);
try {
h.click();
assert.equal(
@@ -398,7 +398,7 @@ for (const [layerId, ownedId, picked] of SIBLING_PICKS) {
);
} finally {
h.cleanup();
unregisterPickOwner(layerId);
unregisterPickOwner(layerId, h.engine);
}
});
}
+143 -89
View File
@@ -11,11 +11,9 @@
* that belong to someone else and leave them alone.
*/
import { sceneServicesFor } from './sceneServices.js';
import { isSurfacePick } from './scenePick.js';
/** @type {Map<string, (pickedId: string) => boolean>} layerId -> ownership predicate */
const _owners = new Map();
/**
* Resolves a scene.pick() result to a String pick id for the ownership scan.
*
@@ -46,99 +44,155 @@ export function resolvePickId(picked) {
return typeof id === 'string' || typeof id === 'number' ? String(id) : null;
}
/**
* Registers a pick-ownership predicate for a layer.
* @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.
* @returns {void}
*/
export function registerPickOwner(layerId, predicate) {
if (!layerId || typeof predicate !== 'function') return;
_owners.set(layerId, predicate);
}
/** Own the pick predicates for one scene. */
export function createPickRegistry() {
const _owners = new Map();
let destroyed = false;
/**
* Removes a layer's ownership predicate (call on disable/destroy).
* @param {string} layerId - Owning layer id.
* @returns {void}
*/
export function unregisterPickOwner(layerId) {
_owners.delete(layerId);
}
/**
* The registered layer that owns a picked id, or null.
* @param {string} pickedId - Canonical pick id from {@link resolvePickId}.
* @returns {string|null} Owning layer id.
*/
export function findPickOwner(pickedId) {
if (!pickedId) return null;
for (const [ownerId, predicate] of _owners) {
try {
if (predicate(pickedId)) return ownerId;
} catch {
// a broken predicate must never break picking
}
/**
* Registers a pick-ownership predicate for a layer.
* @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.
* @returns {void}
*/
function registerPickOwner(layerId, predicate) {
if (destroyed || !layerId || typeof predicate !== 'function') return;
_owners.set(layerId, predicate);
}
return null;
}
/**
* True when some OTHER registered layer owns the picked id.
* @param {string} layerId - The asking layer's id (excluded from the scan).
* @param {string} pickedId - Picked primitive/entity id.
* @returns {boolean}
*/
export function isOwnedByOtherLayer(layerId, pickedId) {
if (!pickedId) return false;
for (const [ownerId, predicate] of _owners) {
if (ownerId === layerId) continue;
try {
if (predicate(pickedId)) return true;
} catch {
// a broken predicate must never break click handling
}
/**
* Removes a layer's ownership predicate (call on disable/destroy).
* @param {string} layerId - Owning layer id.
* @returns {void}
*/
function unregisterPickOwner(layerId) {
_owners.delete(layerId);
}
return false;
/**
* The registered layer that owns a picked id, or null.
* @param {string} pickedId - Canonical pick id from {@link resolvePickId}.
* @returns {string|null} Owning layer id.
*/
function findPickOwner(pickedId) {
if (!pickedId) return null;
for (const [ownerId, predicate] of _owners) {
try {
if (predicate(pickedId)) return ownerId;
} catch {
// a broken predicate must never break picking
}
}
return null;
}
/**
* True when some OTHER registered layer owns the picked id.
* @param {string} layerId - The asking layer's id (excluded from the scan).
* @param {string} pickedId - Picked primitive/entity id.
* @returns {boolean}
*/
function isOwnedByOtherLayer(layerId, pickedId) {
if (!pickedId) return false;
for (const [ownerId, predicate] of _owners) {
if (ownerId === layerId) continue;
try {
if (predicate(pickedId)) return true;
} catch {
// a broken predicate must never break click handling
}
}
return false;
}
/**
* Resolve a moving-contact click without letting map tiles hide a nearby touch
* target. Exact picks always win; only a coarse primary pointer may expand a
* surface miss. Every consumer uses the same ordered, bounded scene hits, so sibling layers
* do not each choose their own contact under one tap.
* Unowned non-surface objects remain barriers, not permission to pick through.
*
* @param {object} scene Cesium scene with pick and optional drillPick.
* @param {{x: number, y: number}} position Screen position in CSS pixels.
* @returns {object|null|undefined} Original pick or the first registered touch hit.
*/
function pickContact(scene, position) {
return nearbyContact(
scene.pick(position),
position,
scene.drillPick?.bind(scene),
);
}
function nearbyContact(picked, position, drillPick) {
if (
!globalThis.matchMedia?.('(pointer: coarse)').matches ||
findPickOwner(resolvePickId(picked)) ||
!isSurfacePick(picked) ||
typeof drillPick !== 'function'
)
return picked;
let hits;
try {
hits = drillPick(position, 8, 14, 14) || [];
} catch {
return picked;
}
for (const hit of hits.slice(0, 8)) {
if (findPickOwner(resolvePickId(hit))) return hit;
if (!isSurfacePick(hit)) break;
}
return picked;
}
registerPickOwner('trails', (id) => String(id).startsWith('gev-trail:'));
return {
resolvePickId,
registerPickOwner,
unregisterPickOwner,
findPickOwner,
isOwnedByOtherLayer,
pickContact,
nearbyContact,
destroy() {
destroyed = true;
_owners.clear();
},
};
}
/**
* Resolve a moving-contact click without letting map tiles hide a nearby touch
* target. Exact picks always win; only a coarse primary pointer may expand a
* surface miss. Every consumer uses the same ordered, bounded scene hits, so sibling layers
* do not each choose their own contact under one tap.
* Unowned non-surface objects remain barriers, not permission to pick through.
*
* @param {object} scene Cesium scene with pick and optional drillPick.
* @param {{x: number, y: number}} position Screen position in CSS pixels.
* @returns {object|null|undefined} Original pick or the first registered touch hit.
*/
export function pickContact(scene, position) {
return nearbyContact(
scene.pick(position),
position,
scene.drillPick?.bind(scene),
/** Pick ownership of the scene attached to this engine. */
export function pickRegistryFor(engine) {
return sceneServicesFor(engine)?.picking ?? null;
}
export function registerPickOwner(layerId, predicate, engine) {
return pickRegistryFor(engine)?.registerPickOwner(layerId, predicate);
}
export function unregisterPickOwner(layerId, engine) {
return pickRegistryFor(engine)?.unregisterPickOwner(layerId);
}
export function findPickOwner(pickedId, engine) {
return pickRegistryFor(engine)?.findPickOwner(pickedId) ?? null;
}
export function isOwnedByOtherLayer(layerId, pickedId, engine) {
return (
pickRegistryFor(engine)?.isOwnedByOtherLayer(layerId, pickedId) ?? false
);
}
export function nearbyContact(picked, position, drillPick) {
if (
!globalThis.matchMedia?.('(pointer: coarse)').matches ||
findPickOwner(resolvePickId(picked)) ||
!isSurfacePick(picked) ||
typeof drillPick !== 'function'
)
return picked;
let hits;
try {
hits = drillPick(position, 8, 14, 14) || [];
} catch {
return picked;
}
for (const hit of hits.slice(0, 8)) {
if (findPickOwner(resolvePickId(hit))) return hit;
if (!isSurfacePick(hit)) break;
}
return picked;
export function pickContact(scene, position, engine) {
return pickRegistryFor(engine)?.pickContact(scene, position) ?? null;
}
export function nearbyContact(picked, position, drillPick, engine) {
return (
pickRegistryFor(engine)?.nearbyContact(picked, position, drillPick) ??
picked
);
}
+2 -7
View File
@@ -11,13 +11,8 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
registerPickOwner,
unregisterPickOwner,
isOwnedByOtherLayer,
resolvePickId,
pickContact,
} from './pickRegistry.js';
import { createPickRegistry, resolvePickId } from './pickRegistry.js';
const { registerPickOwner, unregisterPickOwner, isOwnedByOtherLayer, pickContact } = createPickRegistry();
// ---------------------------------------------------------------------------
// resolvePickId — canonical String coercion for every layer's pick shape
+6 -2
View File
@@ -97,16 +97,20 @@ function descriptorLabel(found, fallback) {
* @param {object|null} picked Result of `scene.pick()`.
* @param {object} [options]
* @param {object} [options.dataManager] Layer lifecycle (enabled state, modules).
* @param {object} [options.engine] Engine of the scene that supplied the pick.
* @returns {{layerId: string, id: string, label: string, kind: string, lat: number|null, lon: number|null, altitudeM?: number|null}|null}
*/
export function resolvePickedContext(picked, { dataManager = null } = {}) {
export function resolvePickedContext(
picked,
{ dataManager = null, engine = dataManager?.engine } = {},
) {
if (!picked) return null;
const record = contextCarrierRecord(picked, dataManager);
if (record) return fromRecord(record);
const pickId = resolvePickId(picked);
if (!pickId) return null;
const layerId = findPickOwner(pickId);
const layerId = findPickOwner(pickId, engine);
if (!layerId || IGNORED_OWNERS.has(layerId)) return null;
if (dataManager?.isEnabled && !dataManager.isEnabled(layerId)) return null;
const layer = dataManager?.layers?.get?.(layerId);
+24 -1
View File
@@ -11,11 +11,14 @@ globalThis.CustomEvent ||= class CustomEvent {
globalThis.dispatchEvent ||= () => true;
const { registerEntityContext } = await import('./contextStore.js');
const { registerPickOwner, unregisterPickOwner, findPickOwner } = await import('./pickRegistry.js');
const engine = {};
const { pickRegistryFor } = await import('./pickRegistry.js');
const { registerPickOwner, unregisterPickOwner, findPickOwner } = pickRegistryFor(engine);
const { resolvePickedContext, pickedKindForLayer } = await import('./pickedContext.js');
function manager({ enabled = new Set(['flights', 'local-datacenters']), modules = {} } = {}) {
return {
engine,
isEnabled: (id) => enabled.has(id),
layers: new Map(Object.entries(modules).map(([id, module]) => [id, { name: id, module }])),
};
@@ -73,3 +76,23 @@ test('disabled layers, trails and empty picks never resolve', () => {
assert.equal(resolvePickedContext({ id: 'unknown' }, { dataManager: manager() }), null);
assert.equal(pickedKindForLayer('ais-live-vessels'), 'vessel');
});
test('an explicit pointer engine resolves only that scene, without a manager', () => {
const first = {};
const second = {};
const a = pickRegistryFor(first);
const b = pickRegistryFor(second);
a.registerPickOwner('flights', (id) => id === 'shared');
b.registerPickOwner('satellites', (id) => id === 'shared');
try {
const picked = { id: 'shared' };
assert.equal(resolvePickedContext(picked, { engine: first }).layerId, 'flights');
assert.equal(resolvePickedContext(picked, { engine: second }).layerId, 'satellites');
a.destroy();
assert.equal(resolvePickedContext(picked, { engine: first }), null);
assert.equal(resolvePickedContext(picked, { engine: second }).layerId, 'satellites');
} finally {
a.destroy();
b.destroy();
}
});
+32
View File
@@ -0,0 +1,32 @@
import { createPickRegistry } from './pickRegistry.js';
import { createSelectionDispatcher } from './selectionDispatcher.js';
// Portable layers may attach directly to an engine, outside the application.
// Their lookup reaches the same services the app publishes on its scene.
const scenes = new WeakMap();
/** Create the services for one attachment, including reuse of a parked engine. */
export function createSceneServices(engine, options = {}) {
scenes.get(engine)?.destroy();
const picking = createPickRegistry();
const selection = createSelectionDispatcher(engine, { ...options, picking });
let destroyed = false;
const services = {
picking,
selection,
destroy() {
if (destroyed) return;
destroyed = true;
selection.destroy();
picking.destroy();
},
};
scenes.set(engine, services);
return services;
}
/** A detached scene stays inert until an explicit new attachment replaces it. */
export function sceneServicesFor(engine) {
if (!engine) return null;
return scenes.get(engine) ?? createSceneServices(engine);
}
+137
View File
@@ -0,0 +1,137 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { GROUND_HARNESSES } from '../testSupport/groundDisplayEngines.mjs';
import { createSceneServices, sceneServicesFor } from './sceneServices.js';
import { pickRegistryFor } from './pickRegistry.js';
import { selectionDispatcherFor } from './selectionDispatcher.js';
import { createAlprCamerasLayer } from '../layers/alpr/index.js';
import * as picking from './pickRegistry.js';
for (const makeHarness of GROUND_HARNESSES) {
test(`${makeHarness.name}: an enabled ALPR layer transfers pick ownership on reattachment`, (t) => {
const first = makeHarness();
const second = makeHarness();
const a = createSceneServices(first.engine);
const b = createSceneServices(second.engine);
const noop = () => {};
const layer = createAlprCamerasLayer({
source: { fetch: () => assert.fail('Reattachment must not fetch') },
services: { picking, render: { governorRequestRender: noop } },
rendererFactory({ state }) {
state.recordById.set('camera', {});
return {
init: noop,
setVisible: noop,
renderRecords: noop,
hideOnMapCredit: noop,
clearSelection: noop,
clearRendered: noop,
destroy: noop,
};
},
});
t.after(() => {
layer.destroy();
a.destroy();
b.destroy();
first.destroy();
second.destroy();
});
layer.init(null, { engine: first.engine });
layer.enable();
assert.equal(a.picking.findPickOwner('camera'), 'alpr-cameras');
assert.equal(b.picking.findPickOwner('camera'), null);
layer.detachRenderer();
assert.equal(a.picking.findPickOwner('camera'), null);
layer.attachRenderer(null, { engine: second.engine });
assert.equal(b.picking.findPickOwner('camera'), 'alpr-cameras');
layer.disable();
assert.equal(b.picking.findPickOwner('camera'), null);
});
test(`${makeHarness.name}: simultaneous scenes isolate ownership and clicks`, (t) => {
const first = makeHarness();
const second = makeHarness();
const scenes = [first, second].map(({ engine }) => ({
engine,
services: createSceneServices(engine, { keyTarget: new EventTarget() }),
}));
t.after(() => {
for (const scene of scenes) scene.services.destroy();
first.destroy();
second.destroy();
});
const calls = [[], []];
scenes.forEach(({ engine, services }, i) => {
assert.equal(pickRegistryFor(engine), services.picking);
assert.equal(selectionDispatcherFor(engine), services.selection);
services.selection.register('flights', {
owns: (id) => id === `flight-${i}`,
onSelect: (id) => calls[i].push(id),
onEmptyClick: () => calls[i].push('empty'),
});
});
const [a, b] = scenes.map((scene) => scene.services);
assert.equal(a.picking.findPickOwner('flight-0'), 'flights');
assert.equal(b.picking.findPickOwner('flight-0'), null);
a.picking.registerPickOwner('cctv', (id) => id === 'camera');
assert.equal(a.picking.isOwnedByOtherLayer('flights', 'camera'), true);
assert.equal(b.picking.isOwnedByOtherLayer('flights', 'camera'), false);
first.click({ id: 'flight-0' });
second.click({ id: 'flight-1' });
first.click({ id: 'camera' });
second.click({ id: 'camera' });
assert.deepEqual(calls, [['flight-0'], ['flight-1', 'empty']]);
a.picking.unregisterPickOwner('flights');
assert.equal(b.picking.findPickOwner('flight-1'), 'flights');
});
test(`${makeHarness.name}: scene teardown and parked reattachment leave siblings live`, (t) => {
const first = makeHarness();
const second = makeHarness();
const keys = [new EventTarget(), new EventTarget()];
const a = createSceneServices(first.engine, { keyTarget: keys[0] });
const b = createSceneServices(second.engine, { keyTarget: keys[1] });
let next;
t.after(() => {
a.destroy();
b.destroy();
next?.destroy();
first.destroy();
second.destroy();
});
const calls = [];
const owner = (name) => ({
owns: (id) => id === 'shared-id',
onSelect: () => calls.push(name),
onEscape: () => calls.push(`${name}-escape`),
});
const lateRemove = a.selection.register('flights', owner('first'));
b.selection.register('flights', owner('second'));
assert.equal(first.listeners(), 4);
assert.equal(second.listeners(), 4);
a.destroy();
a.destroy();
assert.equal(first.listeners(), 0);
assert.equal(second.listeners(), 4);
assert.equal(sceneServicesFor(first.engine), a);
a.picking.registerPickOwner('late', () => true);
a.selection.register('late', owner('late'));
assert.equal(a.picking.findPickOwner('shared-id'), null);
first.click({ id: 'shared-id' });
second.click({ id: 'shared-id' });
for (const target of keys)
target.dispatchEvent(
Object.assign(new Event('keydown'), { key: 'Escape' }),
);
assert.deepEqual(calls, ['second', 'second-escape']);
next = createSceneServices(first.engine, { keyTarget: keys[0] });
next.selection.register('flights', owner('next'));
lateRemove();
a.destroy();
assert.equal(next.picking.findPickOwner('shared-id'), 'flights');
first.click({ id: 'shared-id' });
assert.deepEqual(calls, ['second', 'second-escape', 'next']);
assert.equal(b.picking.findPickOwner('shared-id'), 'flights');
});
}
+12 -22
View File
@@ -1,4 +1,4 @@
import { nearbyContact } from './pickRegistry.js';
import { sceneServicesFor } from './sceneServices.js';
// One selection dispatcher for the layers that draw through the globe
// engine: one click subscription with picks
// (engine.input.on('click', …, { pick: true, drill: 8 })), the press
@@ -27,16 +27,11 @@ import { nearbyContact } from './pickRegistry.js';
// layer.
import { isPointerFree as pointerFree } from './inputOwnership.js';
import {
findPickOwner,
registerPickOwner,
resolvePickId,
unregisterPickOwner,
} from './pickRegistry.js';
import { pickRegistryFor, resolvePickId } from './pickRegistry.js';
import {
isTrackingClickGesture,
isTrackingSelectionGesture,
} from './trackingClickGesture.js';
} from './trackingGesture.js';
const SELECTION_DRILL = 8;
@@ -47,11 +42,18 @@ const SELECTION_DRILL = 8;
export function createSelectionDispatcher(
engine,
{
picking = pickRegistryFor(engine),
keyTarget = globalThis.document,
now = () => performance.now(),
isPointerFree = pointerFree,
} = {},
) {
const {
findPickOwner,
registerPickOwner,
unregisterPickOwner,
nearbyContact,
} = picking;
const owners = new Map();
let removers = [];
let destroyed = false;
@@ -254,21 +256,9 @@ export function createSelectionDispatcher(
};
}
const dispatchers = new WeakMap();
/**
* The application's one dispatcher for `engine`, created on first use (the
* layers that moved onto the engine share it).
* @param {import('../globe/contract.js').GlobeEngine} engine
*/
/** The selection dispatcher owned by the engine's attached scene. */
export function selectionDispatcherFor(engine) {
if (!engine) return null;
let dispatcher = dispatchers.get(engine);
if (!dispatcher) {
dispatcher = createSelectionDispatcher(engine);
dispatchers.set(engine, dispatcher);
}
return dispatcher;
return sceneServicesFor(engine)?.selection ?? null;
}
function safely(run) {
+18 -16
View File
@@ -78,8 +78,8 @@ test('a click on an owned object selects it; empty space deselects everyone', ()
});
test("another layer's pick is not empty space, owned through the shared registry", () => {
const { dispatcher, click } = setup({ 10: [{ id: 'cctv-1' }] });
registerPickOwner('cctv', (id) => id.startsWith('cctv'));
const { engine, dispatcher, click } = setup({ 10: [{ id: 'cctv-1' }] });
registerPickOwner('cctv', (id) => id.startsWith('cctv'), engine);
try {
const flights = recorder();
dispatcher.register('flights', {
@@ -87,19 +87,21 @@ test("another layer's pick is not empty space, owned through the shared registry
...flights.handlers,
});
assert.equal(
isOwnedByOtherLayer('cctv', 'x'),
isOwnedByOtherLayer('cctv', 'x', engine),
true,
'registered for legacy handlers',
);
click(10);
assert.deepEqual(flights.calls, []);
} finally {
unregisterPickOwner('cctv');
unregisterPickOwner('cctv', engine);
}
});
test('a pick no layer owns is empty space, as for the old handlers', () => {
const { dispatcher, click } = setup({ 10: [{ id: 'unclaimed-entity' }] });
const { engine, dispatcher, click } = setup({
10: [{ id: 'unclaimed-entity' }],
});
const flights = recorder();
dispatcher.register('flights', {
owns: (id) => id === 'x',
@@ -115,7 +117,7 @@ test('a pick no layer owns is empty space, as for the old handlers', () => {
});
test('trails do not take clicks: the object under a trail is selected', () => {
const { dispatcher, click } = setup({
const { engine, dispatcher, click } = setup({
10: [{ id: 'trail-ae01ce', owner: 'flights-trail' }, { id: 'ae01ce' }],
});
const flights = recorder();
@@ -129,10 +131,10 @@ test('trails do not take clicks: the object under a trail is selected', () => {
});
test("a drill-through owner finds its object under another layer's", () => {
const { dispatcher, click } = setup({
const { engine, dispatcher, click } = setup({
10: [{ id: 'cctv-1' }, { id: 'adsb:abc' }],
});
registerPickOwner('cctv', (id) => id.startsWith('cctv'));
registerPickOwner('cctv', (id) => id.startsWith('cctv'), engine);
try {
const local = recorder();
dispatcher.register('local-adsb', {
@@ -143,12 +145,12 @@ test("a drill-through owner finds its object under another layer's", () => {
click(10);
assert.deepEqual(local.calls, [['select', 'adsb:abc', undefined]]);
} finally {
unregisterPickOwner('cctv');
unregisterPickOwner('cctv', engine);
}
});
test('a drag selects nothing and deselects nothing; a long press still selects', () => {
const { dispatcher, click } = setup({ 10: [{ id: 'ae01ce' }] });
const { engine, dispatcher, click } = setup({ 10: [{ id: 'ae01ce' }] });
const flights = recorder();
dispatcher.register('flights', {
owns: (id) => id === 'ae01ce',
@@ -189,7 +191,7 @@ test('unregister and destroy remove the subscriptions', () => {
dispatcher.destroy();
click(10);
assert.deepEqual(flights.calls, []);
assert.equal(isOwnedByOtherLayer('other', 'a'), false);
assert.equal(isOwnedByOtherLayer('other', 'a', engine), false);
assert.ok(engine.fake.callsOf('input.on').length >= 1);
});
@@ -208,7 +210,7 @@ test('the application has one dispatcher per engine', () => {
test('a look-under owner (local ADS-B) keeps its own click rule beside the others', () => {
// x: what lies under each column, top first.
const { dispatcher, click } = setup({
const { engine, dispatcher, click } = setup({
10: [{ id: 'local-adsb:a' }], // its own marker
20: [{ primitive: { tileset: true } }, { id: 'local-adsb:a' }], // under a tile
30: [{ id: 'gev-trail:local-adsb-head-1' }, { id: 'local-adsb:b' }], // under a trail
@@ -217,8 +219,8 @@ test('a look-under owner (local ADS-B) keeps its own click rule beside the other
60: [{ id: 'cctv-1' }, { id: 'local-adsb:a' }], // a registry owner's on top
70: [], // empty map
});
registerPickOwner('trails', (id) => id.startsWith('gev-trail:'));
registerPickOwner('cctv', (id) => id.startsWith('cctv'));
registerPickOwner('trails', (id) => id.startsWith('gev-trail:'), engine);
registerPickOwner('cctv', (id) => id.startsWith('cctv'), engine);
try {
const local = recorder();
const flights = recorder();
@@ -252,8 +254,8 @@ test('a look-under owner (local ADS-B) keeps its own click rule beside the other
['empty', 0],
]);
} finally {
unregisterPickOwner('trails');
unregisterPickOwner('cctv');
unregisterPickOwner('trails', engine);
unregisterPickOwner('cctv', engine);
}
});
+6 -32
View File
@@ -1,38 +1,12 @@
import { trackingEventTypes } from '../globe/cesium/screenEvents.js';
import { isPointerFree } from './inputOwnership.js';
export const MAX_TRACKING_CLICK_TRAVEL_PX = 6;
export const MAX_TRACKING_CLICK_DURATION_MS = 400;
/**
* Decide whether a completed press stayed spatially click-like. Duration is
* deliberately ignored so a stationary long press may still select a contact;
* callers apply the full click classifier before destructive deselection.
* @param {{travelPx?: number}} gesture - Accumulated pointer path.
* @returns {boolean} True when travel stays within the click limit.
*/
export function isTrackingSelectionGesture(gesture = {}) {
const travelPx = Number.isFinite(gesture.travelPx)
? Math.max(0, gesture.travelPx)
: Number.POSITIVE_INFINITY;
return travelPx <= MAX_TRACKING_CLICK_TRAVEL_PX;
}
/**
* Decide whether a completed press is a clean click suitable for deselection
* or another action that requires both short duration and low travel.
* @param {{travelPx?: number, durationMs?: number}} gesture - Accumulated path and press time.
* @returns {boolean} True when the gesture stays within both click limits.
*/
export function isTrackingClickGesture(gesture = {}) {
const durationMs = Number.isFinite(gesture.durationMs)
? Math.max(0, gesture.durationMs)
: Number.POSITIVE_INFINITY;
return (
isTrackingSelectionGesture(gesture) &&
durationMs <= MAX_TRACKING_CLICK_DURATION_MS
);
}
export {
MAX_TRACKING_CLICK_TRAVEL_PX,
MAX_TRACKING_CLICK_DURATION_MS,
isTrackingSelectionGesture,
isTrackingClickGesture,
} from './trackingGesture.js';
/**
* Bind LEFT_DOWN/MOUSE_MOVE/LEFT_UP accounting ahead of a scene click.
+32
View File
@@ -0,0 +1,32 @@
export const MAX_TRACKING_CLICK_TRAVEL_PX = 6;
export const MAX_TRACKING_CLICK_DURATION_MS = 400;
/**
* Decide whether a completed press stayed spatially click-like. Duration is
* deliberately ignored so a stationary long press may still select a contact;
* callers apply the full click classifier before destructive deselection.
* @param {{travelPx?: number}} gesture - Accumulated pointer path.
* @returns {boolean} True when travel stays within the click limit.
*/
export function isTrackingSelectionGesture(gesture = {}) {
const travelPx = Number.isFinite(gesture.travelPx)
? Math.max(0, gesture.travelPx)
: Number.POSITIVE_INFINITY;
return travelPx <= MAX_TRACKING_CLICK_TRAVEL_PX;
}
/**
* Decide whether a completed press is a clean click suitable for deselection
* or another action that requires both short duration and low travel.
* @param {{travelPx?: number, durationMs?: number}} gesture - Accumulated path and press time.
* @returns {boolean} True when the gesture stays within both click limits.
*/
export function isTrackingClickGesture(gesture = {}) {
const durationMs = Number.isFinite(gesture.durationMs)
? Math.max(0, gesture.durationMs)
: Number.POSITIVE_INFINITY;
return (
isTrackingSelectionGesture(gesture) &&
durationMs <= MAX_TRACKING_CLICK_DURATION_MS
);
}