mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Take pointer input through one dispatcher per scene
Every layer and tool bound its own ScreenSpaceEventHandler and picked the same click again: with the usual layers on, one click ran about 26 scene.pick and 2 drillPick passes (120-215 ms in NYC with 18 layers). Pointer input now comes in through src/input/dispatcher.js, one handler per scene. A click is picked lazily and at most once per kind of query, and every subscriber reads the same ClickEvent (pick, hit, id, ownerId, gesture, drill, ground). The same click now costs 3 picks and 2 drills, 17-70 ms. - Ambient onClick subscribers run only while no tool holds the pointer, checked once per event; tools subscribe with their lease. Moves and releases always reach ambient subscribers, so hover and drags end cleanly. - Camera input and the viewer's stock select/track clicks are ref-counted holds (suspendCamera, suppressStockClicks). The dispatcher owns the controller's enableInputs, so a Cesium flight that ends no longer turns input back on under a drag or the cockpit. - The draw tool, imagery box, CCTV gizmo, cockpit, directions and every selecting layer use it; bindTrackingClickGesture is gone (the gesture is on the event). A source scan forbids new handlers, enableInputs writes and stock-click removal outside the dispatcher. - The sensor-style pick correction transit had now applies to every layer. - Radio's 8-pick near-miss ring is one 17x17 windowed drill. - A missed pick passed to pickContact is no longer picked again, and a touch tap's contact search shares the click's drill. - A gizmo drag whose release Cesium never reported ends on the next press instead of leaving the camera held. The dispatcher is exported as ./input with the pointer-lease functions, and documented in docs/APPLICATION.md.
This commit is contained in:
1 parent
83ec9473b6
commit
02d492a079
97 files changed
+2506
-1307
No files matched your search
@@ -63,7 +63,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
moveEndRemove: null,
|
||||
postRenderRemove: null,
|
||||
lastAnchorSampleAt: 0,
|
||||
clickHandler: null,
|
||||
clickSubscription: null,
|
||||
debounceTimer: null,
|
||||
/** Snapped box of the last successful query; a view still inside it reuses its records. */
|
||||
lastQueryBox: null,
|
||||
@@ -343,8 +343,8 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.moveEndRemove = null;
|
||||
state.postRenderRemove?.();
|
||||
state.postRenderRemove = null;
|
||||
state.clickHandler?.destroy();
|
||||
state.clickHandler = null;
|
||||
state.clickSubscription?.();
|
||||
state.clickSubscription = null;
|
||||
clearRendered();
|
||||
if (state.dataSource && viewer)
|
||||
viewer.dataSources.remove(state.dataSource, true);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
MAX_VIEWPORT_DEGREES,
|
||||
@@ -624,18 +624,14 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
}
|
||||
|
||||
function installInteraction(viewer) {
|
||||
if (state.clickHandler) return;
|
||||
state.clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
state.clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (state.clickSubscription) return;
|
||||
state.clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!state.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
// The painted overlay answers first; the scene is picked only if not.
|
||||
const pickedId = event.pick?.id?.id;
|
||||
const id =
|
||||
overlay.pick(click.position) ||
|
||||
(typeof picked?.id?.id === 'string' ? picked.id.id : null);
|
||||
overlay.pick(event.screenPosition) ||
|
||||
(typeof pickedId === 'string' ? pickedId : null);
|
||||
if (
|
||||
id &&
|
||||
state.recordById.has(id) &&
|
||||
@@ -643,7 +639,7 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
)
|
||||
selectRecord(id);
|
||||
else if (state.selectedId) clearSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
return {
|
||||
initOverlay: () => overlay.init(),
|
||||
|
||||
@@ -44,7 +44,7 @@ export function createLifecycle({
|
||||
layerState._inFlightInfo = new Map();
|
||||
layerState._inFlightStatus = new Map();
|
||||
layerState._stationRenderMap = new Map();
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription = null;
|
||||
layerState._selectedKey = null;
|
||||
layerState._selectedEntity = null;
|
||||
layerState._count = 0;
|
||||
@@ -117,10 +117,8 @@ export function createLifecycle({
|
||||
false,
|
||||
);
|
||||
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
document.removeEventListener('keydown', parts.selection._onKeyDown);
|
||||
unregisterPickOwner('bikeshare');
|
||||
|
||||
@@ -150,10 +148,8 @@ export function createLifecycle({
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
|
||||
false,
|
||||
);
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
document.removeEventListener('keydown', parts.selection._onKeyDown);
|
||||
unregisterPickOwner('bikeshare');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
|
||||
@@ -155,15 +155,10 @@ export function createSelection({
|
||||
*/
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (layerState._clickHandler) return;
|
||||
if (layerState._clickSubscription) return;
|
||||
|
||||
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
const picked = event.pick;
|
||||
|
||||
if (picked) {
|
||||
// Clicking selected entity itself — ignore (don't deselect).
|
||||
@@ -190,7 +185,7 @@ export function createSelection({
|
||||
|
||||
// Clicked empty space — deselect.
|
||||
if (layerState._selectedKey) _clearSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ export function createState({ services }) {
|
||||
|
||||
layerState._stationRenderMap = new Map();
|
||||
|
||||
/** @type {Cesium.ScreenSpaceEventHandler|null} Click handler for station selection. */
|
||||
/** @type {(() => void)|null} Unsubscribes the station-selection click. */
|
||||
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription = null;
|
||||
|
||||
/** @type {string|null} Key of the currently selected station, or null. */
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as Cesium from 'cesium';
|
||||
import { viewshedColors, cameraHue } from '../../data/cctvViewshed.js';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
GROUND_PRIOR_INIT_WAIT_MS,
|
||||
CALIBRATION_RANGE_FLOOR_M,
|
||||
@@ -382,14 +383,12 @@ export function createLifecycle({
|
||||
}
|
||||
parts.rendering.refreshHorizonCulling();
|
||||
|
||||
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
layerState._viewer.scene.canvas,
|
||||
);
|
||||
parts.selection.bindCctvWorldClickGesture(
|
||||
layerState._clickHandler,
|
||||
(click) => {
|
||||
const input = inputFor(layerState._viewer);
|
||||
const unsubscribeClick = parts.selection.bindCctvWorldClickGesture(
|
||||
input,
|
||||
(event) => {
|
||||
if (!layerState._enabled) return;
|
||||
const picked = layerState._viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const cameraId = parts.selection.extractPickedCameraId(picked);
|
||||
if (cameraId) {
|
||||
activateCctvCameraFromWorldClick(
|
||||
@@ -410,8 +409,8 @@ export function createLifecycle({
|
||||
// its camera exactly like a click on the icon. Cesium click positions
|
||||
// and the recorded rects are both CSS px — direct comparison.
|
||||
const cardId = layerState._cctvOverlayHost.hitTest(
|
||||
click.position.x,
|
||||
click.position.y,
|
||||
event.screenPosition.x,
|
||||
event.screenPosition.y,
|
||||
{ sourceId: CCTV_OVERLAY_SOURCE_ID },
|
||||
)?.entryId;
|
||||
if (cardId && layerState._recordById.has(cardId)) {
|
||||
@@ -430,14 +429,15 @@ export function createLifecycle({
|
||||
parts.selection.deactivateActiveCamera();
|
||||
}
|
||||
},
|
||||
{
|
||||
// Item B: hover summons a card on a cardless camera icon. The gesture
|
||||
// classifier owns MOUSE_MOVE too, so chain hover work through its seam
|
||||
// instead of replacing the travel accumulator's handler.
|
||||
onMouseMove: (movement) =>
|
||||
parts.hover.handleHoverMove(movement?.endPosition),
|
||||
},
|
||||
);
|
||||
// Item B: hover summons a card on a cardless camera icon.
|
||||
const unsubscribeHover = input.onPointer('move', (movement) =>
|
||||
parts.hover.handleHoverMove(movement?.endPosition),
|
||||
);
|
||||
layerState._clickSubscription = () => {
|
||||
unsubscribeClick();
|
||||
unsubscribeHover();
|
||||
};
|
||||
|
||||
await parts.health.syncHealthState(true);
|
||||
// Health ranks crowded cells: thin again now that it has arrived (a
|
||||
@@ -584,13 +584,8 @@ export function createLifecycle({
|
||||
}
|
||||
layerState._calibrationMode = false;
|
||||
releaseContinuousRender('cctv-adjust');
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
if (teardownViewer?.scene?.screenSpaceCameraController) {
|
||||
teardownViewer.scene.screenSpaceCameraController.enableInputs = true;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
parts.projection.stopProjectionLoop();
|
||||
parts.geometryQueue.stopGeometryLoadQueue();
|
||||
parts.cards.teardownAmbientCards();
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
bindTrackingClickGesture,
|
||||
isTrackingClickGesture,
|
||||
} from '../../data/trackingClickGesture.js';
|
||||
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { cctvPicks } from './pickState.js';
|
||||
|
||||
@@ -35,24 +32,19 @@ export function createSelection({
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind CCTV activation to clean taps while preserving the layer's hover-move
|
||||
* callback on the shared Cesium handler. Drag-like and long-press gestures do
|
||||
* Bind CCTV activation to clean taps. Drag-like and long-press gestures do
|
||||
* not reach camera activation or focus dispatch.
|
||||
* @param {Cesium.ScreenSpaceEventHandler|Object} handler - Input handler.
|
||||
* @param {(click: Object) => void} onClick - Accepted CCTV click callback.
|
||||
* @param {Object} [options] - Gesture test seams and optional onMouseMove hook.
|
||||
* @returns {void}
|
||||
* @param {import('../../input/dispatcher.js').InputDispatcher} input
|
||||
* @param {(event: import('../../input/dispatcher.js').ClickEvent) => void} onClick
|
||||
* Accepted CCTV click callback.
|
||||
* @returns {() => void} Unsubscribe.
|
||||
*/
|
||||
|
||||
function bindCctvWorldClickGesture(handler, onClick, options = {}) {
|
||||
bindTrackingClickGesture(
|
||||
handler,
|
||||
(click, gesture) => {
|
||||
if (!isTrackingClickGesture(gesture)) return;
|
||||
onClick(click);
|
||||
},
|
||||
options,
|
||||
);
|
||||
function bindCctvWorldClickGesture(input, onClick) {
|
||||
return input.onClick((event) => {
|
||||
if (!isTrackingClickGesture(event.gesture)) return;
|
||||
onClick(event);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ export function createState({ services }) {
|
||||
|
||||
layerState._lastViewContext = '';
|
||||
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription = null;
|
||||
|
||||
layerState._count = 0;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { hitTestWorldOverlay } from '../../overlays/worldOverlay.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
@@ -82,7 +82,7 @@ export function createCyclonesLayer({
|
||||
selectedId = null,
|
||||
selectionIntent = 'auto',
|
||||
navigationGeneration = 0,
|
||||
clickHandler = null,
|
||||
selectionOwner = null,
|
||||
removeClickCapture = null;
|
||||
let enabled = false,
|
||||
loading = false,
|
||||
@@ -106,14 +106,9 @@ export function createCyclonesLayer({
|
||||
(typeof cesium.Cesium3DTileset === 'function' &&
|
||||
picked.primitive instanceof cesium.Cesium3DTileset)));
|
||||
function installSelection() {
|
||||
if (
|
||||
clickHandler ||
|
||||
!viewer?.scene?.canvas ||
|
||||
typeof cesium.ScreenSpaceEventHandler !== 'function'
|
||||
)
|
||||
return;
|
||||
const owner = new cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
clickHandler = owner;
|
||||
if (selectionOwner || !viewer?.scene?.canvas) return;
|
||||
const owner = {};
|
||||
selectionOwner = owner;
|
||||
// Snapshot before sibling bubble listeners can rebuild the overlay hit
|
||||
// rectangles. A vessel selection does that synchronously in the same click.
|
||||
const canvas = viewer.scene.canvas;
|
||||
@@ -154,28 +149,24 @@ export function createCyclonesLayer({
|
||||
canvas.removeEventListener?.(type, resetCapture, { capture: true });
|
||||
capturedHit = null;
|
||||
};
|
||||
owner.setInputAction((click) => {
|
||||
const unsubscribe = inputFor(viewer).onClick((event) => {
|
||||
const nativeHit = capturedHit;
|
||||
capturedHit = null;
|
||||
// Ambient selection yields to draw tools and Director; it never claims
|
||||
// the pointer, camera, or tracking state.
|
||||
if (
|
||||
!enabled ||
|
||||
destroyed ||
|
||||
clickHandler !== owner ||
|
||||
!isPointerFree() ||
|
||||
!click?.position
|
||||
)
|
||||
// Ambient selection yields to draw tools and Director (the dispatcher
|
||||
// skips a held pointer); it never claims the pointer, camera, or
|
||||
// tracking state.
|
||||
const position = event.screenPosition;
|
||||
if (!enabled || destroyed || selectionOwner !== owner || !position)
|
||||
return;
|
||||
// AIS cards paint above the globe on a pointer-events:none canvas. The
|
||||
// vessel handler resolves this same topmost hit before cyclone geometry.
|
||||
const captureMatches =
|
||||
nativeHit &&
|
||||
Math.abs(nativeHit.x - click.position.x) < 1 &&
|
||||
Math.abs(nativeHit.y - click.position.y) < 1;
|
||||
Math.abs(nativeHit.x - position.x) < 1 &&
|
||||
Math.abs(nativeHit.y - position.y) < 1;
|
||||
const hit = captureMatches
|
||||
? nativeHit
|
||||
: overlayHit(click.position.x, click.position.y);
|
||||
: overlayHit(position.x, position.y);
|
||||
if (hit.sourceId === VESSEL_OVERLAY_SOURCE_ID) return;
|
||||
// Storm cards and lead-hour labels paint on the same canvas; a click on
|
||||
// one selects its storm. An id from a superseded advisory changes nothing.
|
||||
@@ -184,18 +175,19 @@ export function createCyclonesLayer({
|
||||
if (id) layer.setParams({ stormId: id });
|
||||
return;
|
||||
}
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const id = rendering?.pickStorm(picked);
|
||||
if (id) layer.setParams({ stormId: id });
|
||||
else if (isSurfacePick(picked)) layer.setParams({ clear: true });
|
||||
}, cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
owner.unsubscribe = unsubscribe;
|
||||
}
|
||||
function removeSelection() {
|
||||
const owner = clickHandler;
|
||||
clickHandler = null;
|
||||
const owner = selectionOwner;
|
||||
selectionOwner = null;
|
||||
removeClickCapture?.();
|
||||
removeClickCapture = null;
|
||||
if (owner && !owner.isDestroyed?.()) owner.destroy();
|
||||
owner?.unsubscribe?.();
|
||||
}
|
||||
const layer = {
|
||||
id: 'weather-cyclones',
|
||||
@@ -520,7 +512,7 @@ export function createCyclonesLayer({
|
||||
enabled,
|
||||
loading,
|
||||
requestPending: !!request,
|
||||
selectionActive: clickHandler !== null,
|
||||
selectionActive: selectionOwner !== null,
|
||||
selectedId,
|
||||
selectionIntent,
|
||||
timerActive: false,
|
||||
|
||||
@@ -7,6 +7,35 @@ import {
|
||||
isPointerFree,
|
||||
} from '../../data/inputOwnership.js';
|
||||
import { isOwnedByOtherLayer } from '../../data/pickRegistry.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
|
||||
/** Record each click subscription the layer makes, as the old handler fakes did. */
|
||||
function recordHandlers(viewer, handlers) {
|
||||
const fake = fakeInput(viewer);
|
||||
const subscribe = fake.input.onClick;
|
||||
fake.input.onClick = (fn) => {
|
||||
const handler = {
|
||||
destroyed: false,
|
||||
// A live subscription hears clicks through the dispatcher; a removed
|
||||
// one is called directly, as a queued callback would be.
|
||||
click: (click) =>
|
||||
handler.destroyed
|
||||
? fn({
|
||||
screenPosition: click.position,
|
||||
get pick() {
|
||||
return viewer.scene.pick(click.position);
|
||||
},
|
||||
})
|
||||
: fake.click(click.position),
|
||||
};
|
||||
handlers.push(handler);
|
||||
const off = subscribe(fn);
|
||||
return () => {
|
||||
handler.destroyed = true;
|
||||
off();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const time = '2026-09-16T03:00:00.000Z';
|
||||
const storm = (id = 'ep152026') => ({
|
||||
@@ -64,23 +93,6 @@ test('map selection yields to pointer owners and owns only its enabled handler',
|
||||
};
|
||||
const cesium = {
|
||||
ScreenSpaceEventType: { LEFT_CLICK: 'left' },
|
||||
ScreenSpaceEventHandler: class {
|
||||
constructor(canvas) {
|
||||
assert.ok(canvas);
|
||||
handlers.push(this);
|
||||
this.destroyed = false;
|
||||
}
|
||||
setInputAction(callback, type) {
|
||||
assert.equal(type, 'left');
|
||||
this.click = callback;
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
isDestroyed() {
|
||||
return this.destroyed;
|
||||
}
|
||||
},
|
||||
};
|
||||
const layer = createCyclonesLayer({
|
||||
feed: { getSnapshot: async () => snapshot([storm(), storm('ep162026')]) },
|
||||
@@ -108,6 +120,7 @@ test('map selection yields to pointer owners and owns only its enabled handler',
|
||||
},
|
||||
},
|
||||
};
|
||||
recordHandlers(viewer, handlers);
|
||||
layer.init(viewer);
|
||||
layer.setRowControlsListener(() => notices++);
|
||||
assert.equal(handlers.length, 0, 'disabled module installs no handler');
|
||||
@@ -270,15 +283,6 @@ test('a click on a storm card or lead-hour label selects that storm without pick
|
||||
feed: { getSnapshot: async () => snapshot([storm(), storm('ep162026')]) },
|
||||
cesium: {
|
||||
ScreenSpaceEventType: { LEFT_CLICK: 'left' },
|
||||
ScreenSpaceEventHandler: class {
|
||||
constructor() {
|
||||
handlers.push(this);
|
||||
}
|
||||
setInputAction(callback) {
|
||||
this.click = callback;
|
||||
}
|
||||
destroy() {}
|
||||
},
|
||||
},
|
||||
overlayHost: 'host',
|
||||
createRendering: ({ overlayHost }) => {
|
||||
@@ -297,7 +301,7 @@ test('a click on a storm card or lead-hour label selects that storm without pick
|
||||
});
|
||||
const canvas = new EventTarget();
|
||||
canvas.getBoundingClientRect = () => ({ left: 0, top: 0 });
|
||||
layer.init({
|
||||
const viewer = {
|
||||
scene: {
|
||||
canvas,
|
||||
pick() {
|
||||
@@ -305,7 +309,9 @@ test('a click on a storm card or lead-hour label selects that storm without pick
|
||||
return { content: {} };
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
recordHandlers(viewer, handlers);
|
||||
layer.init(viewer);
|
||||
assert.equal(hostArgument, 'host', 'the overlay host reaches the renderer');
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
translateKnown,
|
||||
} from '../../i18n/index.js';
|
||||
import { pointerOwnerName } from '../../data/pointerOwnerNames.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
formatQuantity,
|
||||
quantitySeparator,
|
||||
@@ -897,7 +898,7 @@ export function createDirectionsLayer({ services, source }) {
|
||||
let _routeEntity = null;
|
||||
let _stepPoints = null;
|
||||
let _selectedStep = null;
|
||||
let _clickHandler = null;
|
||||
let _clickSubscription = null;
|
||||
let _renderHeld = false;
|
||||
let _rowControlsListener = null;
|
||||
let _dataManager = null;
|
||||
@@ -1212,12 +1213,12 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Give the pointer back, but only once the click that consumed it has finished
|
||||
* being dispatched.
|
||||
*
|
||||
* Every layer binds its own handler to the same canvas, and they all run
|
||||
* inside ONE browser event. Releasing the claim the instant this layer places
|
||||
* an endpoint hands the rest of that same click to every ambient handler
|
||||
* registered after this one — placing A on top of a bikeshare station also
|
||||
* deselected the station. A timer, not a microtask: a microtask checkpoint
|
||||
* runs between two DOM listeners, which is exactly the gap this closes.
|
||||
* The input dispatcher decides who hears a click before any subscriber runs,
|
||||
* but DOM listeners on the canvas (evidence cards) still run later inside
|
||||
* the SAME browser event. Releasing the claim the instant this layer places
|
||||
* an endpoint would hand that same click to them. A timer, not a microtask:
|
||||
* a microtask checkpoint runs between two DOM listeners, which is exactly the
|
||||
* gap this closes.
|
||||
*/
|
||||
function releaseClaimAfterDispatch() {
|
||||
if (_pointerClaim === null || _releaseTimer) return;
|
||||
@@ -1243,8 +1244,8 @@ export function createDirectionsLayer({ services, source }) {
|
||||
* Place one endpoint at a picked ground point and reroute when both are set.
|
||||
*
|
||||
* The globe click handler is the only caller in the running app; it is
|
||||
* exported because a ScreenSpaceEventHandler needs a real canvas, and the
|
||||
* ownership timing this function decides is exactly what has to be tested.
|
||||
* exported so the ownership timing this function decides can be tested on
|
||||
* its own.
|
||||
* @param {'a'|'b'} which Which endpoint to place.
|
||||
* @param {{lat: number, lon: number}} point Ground point in degrees.
|
||||
* @returns {boolean} Whether the endpoint was placed.
|
||||
@@ -1521,25 +1522,28 @@ export function createDirectionsLayer({ services, source }) {
|
||||
}
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (_clickHandler) return;
|
||||
_clickHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
_clickHandler.setInputAction((click) => {
|
||||
if (!_enabled) return;
|
||||
// Placement acts only while this layer actually HOLDS the pointer, and the
|
||||
// maneuver-dot selection below is an ambient handler like any other: it
|
||||
// yields the moment a tool (this one included) owns the click.
|
||||
// The lease, not the owner name: a superseded instance of this layer must
|
||||
// not act on a click its replacement owns.
|
||||
if (_armed && services.input.isLeaseCurrent(_pointerClaim)) {
|
||||
const point = pickGround(click.position);
|
||||
if (_clickSubscription) return;
|
||||
const input = inputFor(viewer);
|
||||
// Placement acts only while this layer actually HOLDS the pointer. The
|
||||
// lease, not the owner name: a superseded instance of this layer must not
|
||||
// act on a click its replacement owns.
|
||||
const offPlace = input.onPointer(
|
||||
'click',
|
||||
(event) => {
|
||||
if (!_enabled || !_armed) return;
|
||||
const point = pickGround(event.position);
|
||||
if (!point) return;
|
||||
placeDirectionsEndpoint(_armed, point);
|
||||
return;
|
||||
}
|
||||
if (!services.input.isPointerFree()) return;
|
||||
},
|
||||
{ lease: () => _pointerClaim },
|
||||
);
|
||||
// The maneuver-dot selection is an ambient handler like any other: it
|
||||
// yields the moment a tool (this one included) owns the click.
|
||||
const offSelect = input.onClick((event) => {
|
||||
if (!_enabled) return;
|
||||
let picked = null;
|
||||
try {
|
||||
picked = viewer.scene.pick(click.position);
|
||||
picked = event.pick;
|
||||
} catch {
|
||||
picked = null;
|
||||
}
|
||||
@@ -1549,16 +1553,18 @@ export function createDirectionsLayer({ services, source }) {
|
||||
return;
|
||||
}
|
||||
if (_selectedStep !== null) _clearStepSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
_clickSubscription = () => {
|
||||
offPlace();
|
||||
offSelect();
|
||||
};
|
||||
if (typeof document !== 'undefined')
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
}
|
||||
|
||||
function _removeClickHandler() {
|
||||
if (_clickHandler) {
|
||||
_clickHandler.destroy();
|
||||
_clickHandler = null;
|
||||
}
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
// Teardown can outlive the document (page unload, and every headless test).
|
||||
if (typeof document !== 'undefined')
|
||||
document.removeEventListener('keydown', _onKeyDown);
|
||||
@@ -1739,9 +1745,8 @@ export function createDirectionsLayer({ services, source }) {
|
||||
|
||||
/**
|
||||
* Place one endpoint at a picked ground point. The globe click handler is
|
||||
* the only caller in the running app; it is on the instance because a
|
||||
* ScreenSpaceEventHandler needs a real canvas, and the ownership timing
|
||||
* this decides is exactly what has to be tested.
|
||||
* the only caller in the running app; it is on the instance so the
|
||||
* ownership timing this decides can be tested on its own.
|
||||
*/
|
||||
placeEndpoint: placeDirectionsEndpoint,
|
||||
|
||||
|
||||
@@ -186,7 +186,6 @@ export function createQueries({
|
||||
});
|
||||
components.cards.rebuildAmbientLabels();
|
||||
components.selection.installClickHandler();
|
||||
return layerState._clickHandler;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ import {
|
||||
FIRMS_OVERLAY_SOURCE_ID,
|
||||
fireDetectionKey,
|
||||
} from '../../data/firmsLabels.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { CONTEXT_TOP_N } from './policy.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
@@ -22,7 +21,7 @@ export function createSelection({
|
||||
getContextStore,
|
||||
registerEntityContext,
|
||||
} = services.context;
|
||||
const { id, name, overlayHost, screenSpaceEventHandlerFactory } = config;
|
||||
const { id, name, overlayHost } = config;
|
||||
|
||||
/**
|
||||
* Install the LEFT_CLICK handler for fire selection (enable-time only,
|
||||
@@ -32,14 +31,10 @@ export function createSelection({
|
||||
*/
|
||||
|
||||
function installClickHandler() {
|
||||
if (layerState._clickHandler || !layerState._viewer) return;
|
||||
layerState._clickHandler = screenSpaceEventHandlerFactory(
|
||||
layerState._viewer,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const picked = layerState._viewer.scene.pick(click.position);
|
||||
if (layerState._clickSubscription || !layerState._viewer) return;
|
||||
const input = inputFor(layerState._viewer);
|
||||
layerState._clickSubscription = input.onClick((event) => {
|
||||
const picked = event.pick;
|
||||
const fire = pickedFire(picked);
|
||||
if (fire) {
|
||||
selectAndFocusFire(fire);
|
||||
@@ -52,8 +47,8 @@ export function createSelection({
|
||||
if (pickedId && isOwnedByOtherLayer(id, pickedId)) return;
|
||||
}
|
||||
const cardHit = overlayHost.hitTest?.(
|
||||
click.position?.x,
|
||||
click.position?.y,
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
{
|
||||
sourceId: FIRMS_OVERLAY_SOURCE_ID,
|
||||
},
|
||||
@@ -64,14 +59,12 @@ export function createSelection({
|
||||
return;
|
||||
}
|
||||
clearFireSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
|
||||
function removeClickHandler() {
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
}
|
||||
|
||||
/** Select one stable detection and request one UI-owned camera transfer. */
|
||||
|
||||
@@ -67,7 +67,7 @@ export function createFirmsState({ services, config }) {
|
||||
|
||||
layerState._contextIds = new Set();
|
||||
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription = null;
|
||||
|
||||
layerState._moveEndRemover = null;
|
||||
|
||||
|
||||
@@ -199,10 +199,8 @@ export function createLifecycle({
|
||||
parts.tracking._destroyTrail();
|
||||
// Remove click handler + keydown listener while disabled to avoid
|
||||
// intercepting input when the layer is off
|
||||
if (flightState._clickHandler) {
|
||||
flightState._clickHandler.destroy();
|
||||
flightState._clickHandler = null;
|
||||
}
|
||||
flightState._clickSubscription?.();
|
||||
flightState._clickSubscription = null;
|
||||
if (flightState._trackedEntityChangedRemove) {
|
||||
flightState._trackedEntityChangedRemove();
|
||||
flightState._trackedEntityChangedRemove = null;
|
||||
@@ -237,10 +235,8 @@ export function createLifecycle({
|
||||
parts.tracking._clearTracking();
|
||||
parts.tracking._destroyTrail();
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
if (flightState._clickHandler) {
|
||||
flightState._clickHandler.destroy();
|
||||
flightState._clickHandler = null;
|
||||
}
|
||||
flightState._clickSubscription?.();
|
||||
flightState._clickSubscription = null;
|
||||
if (flightState._trackedEntityChangedRemove) {
|
||||
flightState._trackedEntityChangedRemove();
|
||||
flightState._trackedEntityChangedRemove = null;
|
||||
|
||||
@@ -168,9 +168,9 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._trackedModelLoading = false;
|
||||
|
||||
/** @type {Cesium.ScreenSpaceEventHandler|null} Click handler on the scene canvas */
|
||||
/** @type {(() => void)|null} Unsubscribes the scene click. */
|
||||
|
||||
flightState._clickHandler = null;
|
||||
flightState._clickSubscription = null;
|
||||
|
||||
/** @type {Cesium.Viewer|null} Cached viewer reference */
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ import { aircraftIcon, TRACKED_ICON_PX } from '../../data/aircraftIcons.js';
|
||||
import { routePlausible } from '../../data/routePlausible.js';
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
import {
|
||||
bindTrackingClickGesture,
|
||||
isTrackingSelectionGesture,
|
||||
isTrackingClickGesture,
|
||||
} from '../../data/trackingClickGesture.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
TRACKED_MODEL_MAX_LOAD_FAILS,
|
||||
TRACKED_MODEL_RETRY_BACKOFF_MS,
|
||||
@@ -50,7 +50,7 @@ export function createTracking({
|
||||
const { isMilitaryLayerActive, isMilitaryIcao } = services.militaryRegistry;
|
||||
const { trackedLabelModelFromText, refreshTrackedReadout } = services.readout;
|
||||
const { applyTrackedCameraFrame } = services.camera;
|
||||
const { resolvePickId, isOwnedByOtherLayer, pickContact } = services.picking;
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
const flightsLayer = layer;
|
||||
|
||||
function _emitAwarenessEvent(type, detail) {
|
||||
@@ -1140,7 +1140,7 @@ export function createTracking({
|
||||
*/
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (flightState._clickHandler) return; // already installed
|
||||
if (flightState._clickSubscription) return; // already installed
|
||||
|
||||
// Cross-layer untrack: if ANOTHER layer (military, vessels, …) grabs the follow-camera, drop our
|
||||
// tracking so its model/entity/update-loop don't orphan — without touching viewer.trackedEntity
|
||||
@@ -1164,10 +1164,8 @@ export function createTracking({
|
||||
});
|
||||
}
|
||||
|
||||
flightState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
bindTrackingClickGesture(flightState._clickHandler, (click, gesture) => {
|
||||
flightState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
const gesture = event.gesture;
|
||||
// Camera drags never select or deselect, even if they finish over a plane.
|
||||
// Duration alone is allowed through so a stationary long press can still
|
||||
// select/switch contacts; the destructive empty-space branch below applies
|
||||
@@ -1177,9 +1175,7 @@ export function createTracking({
|
||||
// first-person reference. A globe click must not fall through to the
|
||||
// normal empty-space deselection path; cockpit has explicit exit controls.
|
||||
if (document.body.classList.contains('cockpit-mode')) return;
|
||||
const picked = pickContact
|
||||
? pickContact(viewer.scene, click.position)
|
||||
: viewer.scene.pick(click.position);
|
||||
const picked = event.hit;
|
||||
|
||||
if (picked) {
|
||||
// Clicking the tracked entity itself — ignore (don't deselect)
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
import { createHorizonCull } from '../streetLevel/view.js';
|
||||
import { readGhostMapsKml } from './kml.js';
|
||||
import { fieldLabel, parseDescriptionFields, wrapCardText } from './records.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
export * from './catalog.js';
|
||||
export * from './records.js';
|
||||
export { readGhostMapsKml } from './kml.js';
|
||||
@@ -132,9 +133,8 @@ function anchorOf(geometry) {
|
||||
export function createGhostMapsLayer({
|
||||
source,
|
||||
overlayHost = null,
|
||||
screenSpaceEventHandlerFactory = null,
|
||||
inputFor = defaultInputFor,
|
||||
picking = null,
|
||||
pointer = null,
|
||||
openExternal = null,
|
||||
storage = defaultStorage(),
|
||||
} = {}) {
|
||||
@@ -147,7 +147,7 @@ export function createGhostMapsLayer({
|
||||
let _unsubscribe = null;
|
||||
let _stream = 'closed';
|
||||
let _queue = Promise.resolve();
|
||||
let _clickHandler = null;
|
||||
let _clickSubscription = null;
|
||||
let _rowListener = null;
|
||||
let _selectedKey = null;
|
||||
let _selectedCardId = null;
|
||||
@@ -172,8 +172,7 @@ export function createGhostMapsLayer({
|
||||
},
|
||||
onChange: render,
|
||||
});
|
||||
const canSelect = () =>
|
||||
overlayHost && screenSpaceEventHandlerFactory && picking;
|
||||
const canSelect = () => overlayHost && inputFor && picking;
|
||||
|
||||
function wanted(product) {
|
||||
return _selection ? _selection.has(product.id) : product.defaultOn;
|
||||
@@ -496,25 +495,23 @@ export function createGhostMapsLayer({
|
||||
}
|
||||
|
||||
function installClickHandler() {
|
||||
if (!canSelect() || _clickHandler || !_viewer) return;
|
||||
if (!canSelect() || _clickSubscription || !_viewer) return;
|
||||
picking.registerPickOwner?.(
|
||||
GHOSTMAPS_LAYER_ID,
|
||||
(pickedId) =>
|
||||
typeof pickedId === 'string' && pickedId.startsWith(PICK_PREFIX),
|
||||
);
|
||||
_clickHandler = screenSpaceEventHandlerFactory(_viewer);
|
||||
_clickHandler.setInputAction((click) => {
|
||||
if (pointer && !pointer.isPointerFree()) return;
|
||||
_clickSubscription = inputFor(_viewer).onClick((event) => {
|
||||
const cardHit = overlayHost.hitTest?.(
|
||||
click.position?.x,
|
||||
click.position?.y,
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
{ sourceId: GHOSTMAPS_OVERLAY_SOURCE_ID },
|
||||
);
|
||||
if (cardHit && cardHit.entryId === _selectedCardId) {
|
||||
if (_selectedLink && openExternal) openExternal(_selectedLink);
|
||||
return;
|
||||
}
|
||||
const picked = _viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const key = picked ? pickedKey(picked) : null;
|
||||
if (key) {
|
||||
_selectedKey = key;
|
||||
@@ -531,12 +528,12 @@ export function createGhostMapsLayer({
|
||||
clearSelection();
|
||||
render();
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
|
||||
function removeClickHandler() {
|
||||
_clickHandler?.destroy();
|
||||
_clickHandler = null;
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
picking?.unregisterPickOwner?.(GHOSTMAPS_LAYER_ID);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ export function createLifecycle({
|
||||
layerState.moveEndRemove?.();
|
||||
layerState.changedRemove?.();
|
||||
parts.selection.destroy?.();
|
||||
layerState.clickHandler?.destroy();
|
||||
layerState.clickHandler = null;
|
||||
layerState.clickSubscription?.();
|
||||
layerState.clickSubscription = null;
|
||||
parts.namedMarkers?.destroy();
|
||||
parts.rendering.clearRendered();
|
||||
if (layerState.dataSource && viewer)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { LAYER_ID } from './policy.js';
|
||||
import { installationMarkers } from './markerState.js';
|
||||
|
||||
@@ -39,7 +38,7 @@ export function createSelection({
|
||||
}
|
||||
|
||||
function installInteraction(viewer) {
|
||||
if (layerState.clickHandler) return;
|
||||
if (layerState.clickSubscription) return;
|
||||
const events = [
|
||||
'gev:entity-selected',
|
||||
'gev:entity-selection-cleared',
|
||||
@@ -51,14 +50,9 @@ export function createSelection({
|
||||
for (const event of events)
|
||||
globalThis.window?.removeEventListener?.(event, syncContextSelection);
|
||||
};
|
||||
layerState.clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState.clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
layerState.clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!layerState.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const target = picked?.id;
|
||||
const id =
|
||||
target?.installationId ||
|
||||
@@ -74,7 +68,7 @@ export function createSelection({
|
||||
clearSelectedEntityContextForLayer(LAYER_ID);
|
||||
parts.rendering.renderRecords();
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
return {
|
||||
selectRecord,
|
||||
|
||||
@@ -88,7 +88,7 @@ function harness(t) {
|
||||
selection.installInteraction(state.viewer);
|
||||
t.after(() => {
|
||||
selection.destroy();
|
||||
state.clickHandler.destroy();
|
||||
state.clickSubscription();
|
||||
parts.namedMarkers.destroy();
|
||||
parts.rendering.clearRendered();
|
||||
if (previousWindow === undefined) delete globalThis.window;
|
||||
|
||||
@@ -29,7 +29,7 @@ export function createState({ services }) {
|
||||
retryAt: 0,
|
||||
failureReason: null,
|
||||
moveEndRemove: null,
|
||||
clickHandler: null,
|
||||
clickSubscription: null,
|
||||
timer: null,
|
||||
googleSearchRequested: false,
|
||||
/** Contacts subject position; when set, it replaces the camera viewport. */
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createIngestion } from './ingestion.js';
|
||||
import { createControls } from './controls.js';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
import { layerFeedState } from '../../data/feedState.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
@@ -297,17 +298,12 @@ test('destroy followed by actual init starts a clean instance with owned handler
|
||||
assert.equal(value.enabled, false);
|
||||
assert.equal(f.viewer.dataSources.length, 1);
|
||||
assert.equal(f.viewer.scene.preRender.numberOfListeners, 1);
|
||||
const click = f.state._clickHandler;
|
||||
const move = f.state._moveHandler;
|
||||
assert.ok(click instanceof Cesium.ScreenSpaceEventHandler);
|
||||
assert.ok(move instanceof Cesium.ScreenSpaceEventHandler);
|
||||
assert.equal(
|
||||
typeof click.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK),
|
||||
'function',
|
||||
);
|
||||
const input = inputFor(f.viewer);
|
||||
const before = input.subscriberCount();
|
||||
assert.equal(typeof f.state._inputSubscription, 'function');
|
||||
await f.destroy();
|
||||
assert.equal(click.isDestroyed(), true);
|
||||
assert.equal(move.isDestroyed(), true);
|
||||
assert.equal(f.state._inputSubscription, null);
|
||||
assert.equal(input.subscriberCount(), before - 2, 'click and hover');
|
||||
assert.equal(f.viewer.dataSources.length, 0);
|
||||
assert.equal(f.viewer.scene.preRender.numberOfListeners, 0);
|
||||
} finally {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
const HOVER_PICK_INTERVAL_MS = 120;
|
||||
|
||||
@@ -135,15 +136,11 @@ export function createLifecycle({
|
||||
layerState._lastError = null;
|
||||
layerState._orbitMatches = 0;
|
||||
parts.overlays.clearMissionOverlaySources();
|
||||
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((movement) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const input = inputFor(viewer);
|
||||
const unsubscribeClick = input.onClick((event) => {
|
||||
if (!layerState._enabled || !layerState._dataSource?.show) return;
|
||||
const entity = viewer.scene
|
||||
.drillPick(movement.position, 12)
|
||||
const entity = event
|
||||
.drill(12)
|
||||
.map((picked) => picked?.id)
|
||||
.find((candidate) => parts.selection.entityLaunchId(candidate));
|
||||
const launchId = parts.selection.entityLaunchId(entity);
|
||||
@@ -152,19 +149,17 @@ export function createLifecycle({
|
||||
parts.selection.focusMission(
|
||||
layerState._launches.find((launch) => launch.id === launchId),
|
||||
);
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
layerState._moveHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
});
|
||||
hover = createLaunchHover({
|
||||
viewer,
|
||||
enabled: () => layerState._enabled && layerState._dataSource?.show,
|
||||
entityLaunchId: parts.selection.entityLaunchId,
|
||||
});
|
||||
layerState._moveHandler.setInputAction(
|
||||
hover.move,
|
||||
Cesium.ScreenSpaceEventType.MOUSE_MOVE,
|
||||
);
|
||||
const unsubscribeHover = input.onPointer('move', hover.move);
|
||||
layerState._inputSubscription = () => {
|
||||
unsubscribeClick();
|
||||
unsubscribeHover();
|
||||
};
|
||||
// Apply horizon visibility before Cesium traverses and picks the scene.
|
||||
// A postRender write is one frame late and can remain visibly stale when
|
||||
// request-on-demand rendering stops after a globe camera move.
|
||||
@@ -246,10 +241,8 @@ export function createLifecycle({
|
||||
parts.replay.stopMissionReplay();
|
||||
parts.selection.stopMissionZoomAnchor();
|
||||
parts.ingestion.clearPostTleRetry();
|
||||
if (layerState._clickHandler) layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
if (layerState._moveHandler) layerState._moveHandler.destroy();
|
||||
layerState._moveHandler = null;
|
||||
layerState._inputSubscription?.();
|
||||
layerState._inputSubscription = null;
|
||||
if (layerState._declutterHandler) layerState._declutterHandler();
|
||||
layerState._declutterHandler = null;
|
||||
parts.launchPad.destroyLaunchPadZonePrimitive();
|
||||
|
||||
@@ -23,9 +23,7 @@ export function createState({ services }) {
|
||||
|
||||
state._orbitMatches = 0;
|
||||
|
||||
state._clickHandler = null;
|
||||
|
||||
state._moveHandler = null;
|
||||
state._inputSubscription = null;
|
||||
|
||||
state._viewer = null;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
screenProjectedRotation,
|
||||
stabilizeScreenRotation,
|
||||
} from '../../data/iconOrientation.js';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { pickRenderAltitudeM } from '../../data/renderAltitude.js';
|
||||
import { routePlausible } from '../../data/routePlausible.js';
|
||||
import {
|
||||
@@ -95,8 +95,6 @@ const DEFAULT_DISPLAY = Object.freeze({
|
||||
* @param {(url: string) => string} [options.resolveAsset] Model URL resolver.
|
||||
* @param {(options: object) => Promise<object>} [options.loadModel] Model
|
||||
* loader, injectable for tests.
|
||||
* @param {(canvas: HTMLCanvasElement) => object} [options.createInputHandler]
|
||||
* Click-handler factory, injectable for tests.
|
||||
* @returns {object} Data-layer module.
|
||||
*/
|
||||
export function createLocalAdsbLayer({
|
||||
@@ -106,7 +104,6 @@ export function createLocalAdsbLayer({
|
||||
now = Date.now,
|
||||
resolveAsset = (url) => url,
|
||||
loadModel,
|
||||
createInputHandler = (canvas) => new Cesium.ScreenSpaceEventHandler(canvas),
|
||||
}) {
|
||||
if (typeof receiver?.getState !== 'function')
|
||||
throw new TypeError('Local ADS-B requires a receiver session');
|
||||
@@ -135,7 +132,7 @@ export function createLocalAdsbLayer({
|
||||
let unsubscribeFeeds = null;
|
||||
let tickTimer = null;
|
||||
let syncTimer = null;
|
||||
let clickHandler = null;
|
||||
let clickSubscription = null;
|
||||
let removePreRender = null;
|
||||
let renderHeld = false;
|
||||
let selectedId = null;
|
||||
@@ -599,7 +596,7 @@ export function createLocalAdsbLayer({
|
||||
}
|
||||
|
||||
/**
|
||||
* What a click at `position` means for this layer: a local aircraft id,
|
||||
* What a click means for this layer: a local aircraft id,
|
||||
* `'other'` when a sibling layer's contact is under the pointer, `'trail'`
|
||||
* for a trail line, or null for empty map.
|
||||
*
|
||||
@@ -607,15 +604,14 @@ export function createLocalAdsbLayer({
|
||||
* photoreal tile, a ring) or a trail line drawn over or through a local
|
||||
* aircraft does not hide it: the click looks underneath for the aircraft.
|
||||
*/
|
||||
function clickTarget(position) {
|
||||
const scene = viewer.scene;
|
||||
const top = pickedId(scene.pick(position));
|
||||
function clickTarget(event) {
|
||||
const top = pickedId(event.pick);
|
||||
if (top && markers.has(top)) return top;
|
||||
const trail = Boolean(top) && String(top).startsWith(TRAIL_PICK_PREFIX);
|
||||
if (ownedElsewhere(top) && !trail) return 'other';
|
||||
let hits = [];
|
||||
try {
|
||||
hits = scene.drillPick?.(position, CLICK_DRILL_LIMIT) || [];
|
||||
hits = event.drill(CLICK_DRILL_LIMIT);
|
||||
} catch {
|
||||
hits = [];
|
||||
}
|
||||
@@ -630,12 +626,10 @@ export function createLocalAdsbLayer({
|
||||
}
|
||||
|
||||
function installInteraction() {
|
||||
if (clickHandler || !viewer?.scene?.canvas) return;
|
||||
clickHandler = createInputHandler(viewer.scene.canvas);
|
||||
clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree() || !enabled) return;
|
||||
const target = clickTarget(click.position);
|
||||
if (clickSubscription || !viewer?.scene?.canvas) return;
|
||||
clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!enabled) return;
|
||||
const target = clickTarget(event);
|
||||
// Clicking a local aircraft always (re)selects it and republishes its
|
||||
// card, including the one already selected: its card may have been
|
||||
// displaced, and a click on a marker must never read as "deselect".
|
||||
@@ -649,12 +643,12 @@ export function createLocalAdsbLayer({
|
||||
// leaving a sibling layer's new selection intact.
|
||||
clearSelection();
|
||||
governorRequestRender('local-adsb-selection');
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
|
||||
function releaseInteraction() {
|
||||
clickHandler?.destroy();
|
||||
clickHandler = null;
|
||||
clickSubscription?.();
|
||||
clickSubscription = null;
|
||||
}
|
||||
|
||||
function installFrame() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
localAdsbStatus,
|
||||
} from './index.js';
|
||||
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
|
||||
function fakeReceiver(initial = {}) {
|
||||
const state = {
|
||||
@@ -199,9 +200,6 @@ async function enabledLayer(receiver, clock, feeds = null, options = {}) {
|
||||
services: { ...services, ...options.services },
|
||||
now: () => clock.now,
|
||||
loadModel: options.loadModel,
|
||||
...(options.createInputHandler
|
||||
? { createInputHandler: options.createInputHandler }
|
||||
: {}),
|
||||
});
|
||||
layer.init(viewer);
|
||||
await layer.enable();
|
||||
@@ -1070,20 +1068,13 @@ function clickHarness() {
|
||||
return scene.drillResult;
|
||||
},
|
||||
};
|
||||
const handler = { actions: new Map() };
|
||||
const viewer = { ...base.viewer, scene };
|
||||
const input = fakeInput(viewer);
|
||||
return {
|
||||
scene,
|
||||
viewer: { ...base, viewer: { ...base.viewer, scene } },
|
||||
createInputHandler: () => ({
|
||||
setInputAction(action, type) {
|
||||
handler.actions.set(type, action);
|
||||
},
|
||||
destroy() {},
|
||||
}),
|
||||
viewer: { ...base, viewer },
|
||||
click() {
|
||||
handler.actions.get(Cesium.ScreenSpaceEventType.LEFT_CLICK)({
|
||||
position: new Cesium.Cartesian2(10, 10),
|
||||
});
|
||||
input.click(new Cesium.Cartesian2(10, 10));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1094,7 +1085,6 @@ test('clicking the selected aircraft keeps it selected and republishes its card'
|
||||
const harness = clickHarness();
|
||||
const { layer, calls } = await enabledLayer(receiver, clock, null, {
|
||||
viewer: harness.viewer,
|
||||
createInputHandler: harness.createInputHandler,
|
||||
});
|
||||
t.after(() => layer.destroy());
|
||||
receiver.set({ aircraft: [record()] });
|
||||
@@ -1119,7 +1109,6 @@ test('a click on a local aircraft under an unowned or trail pick still selects i
|
||||
const { resolvePickId } = await import('../../data/pickRegistry.js');
|
||||
const { layer, calls } = await enabledLayer(receiver, clock, null, {
|
||||
viewer: harness.viewer,
|
||||
createInputHandler: harness.createInputHandler,
|
||||
services: {
|
||||
picking: {
|
||||
registerPickOwner: (id, predicate) => owners.set(id, predicate),
|
||||
|
||||
@@ -178,10 +178,8 @@ export function createLifecycle({
|
||||
parts.tracking._destroyTrail();
|
||||
// Remove click handler + keydown listener while disabled to avoid
|
||||
// intercepting input when the layer is off
|
||||
if (flightState._clickHandler) {
|
||||
flightState._clickHandler.destroy();
|
||||
flightState._clickHandler = null;
|
||||
}
|
||||
flightState._clickSubscription?.();
|
||||
flightState._clickSubscription = null;
|
||||
if (flightState._trackedEntityChangedRemove) {
|
||||
flightState._trackedEntityChangedRemove();
|
||||
flightState._trackedEntityChangedRemove = null;
|
||||
@@ -216,10 +214,8 @@ export function createLifecycle({
|
||||
parts.tracking._clearTracking();
|
||||
parts.tracking._destroyTrail();
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
if (flightState._clickHandler) {
|
||||
flightState._clickHandler.destroy();
|
||||
flightState._clickHandler = null;
|
||||
}
|
||||
flightState._clickSubscription?.();
|
||||
flightState._clickSubscription = null;
|
||||
if (flightState._trackedEntityChangedRemove) {
|
||||
flightState._trackedEntityChangedRemove();
|
||||
flightState._trackedEntityChangedRemove = null;
|
||||
|
||||
@@ -140,9 +140,9 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._trackedModelLoading = false;
|
||||
|
||||
/** @type {Cesium.ScreenSpaceEventHandler|null} Click handler for selecting aircraft */
|
||||
/** @type {(() => void)|null} Unsubscribes the aircraft-selection click. */
|
||||
|
||||
flightState._clickHandler = null;
|
||||
flightState._clickSubscription = null;
|
||||
|
||||
/** @type {Cesium.Viewer|null} Cached viewer reference */
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
import { trailHeadStart } from '../../data/modelVisualAnchor.js';
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
import {
|
||||
bindTrackingClickGesture,
|
||||
isTrackingSelectionGesture,
|
||||
isTrackingClickGesture,
|
||||
} from '../../data/trackingClickGesture.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
TRACKED_MODEL_MAX_LOAD_FAILS,
|
||||
TRACKED_MODEL_RETRY_BACKOFF_MS,
|
||||
@@ -49,7 +49,7 @@ export function createTracking({
|
||||
const { ensureGeoidReady, geoidHeight } = services.geoid;
|
||||
const { clearFocusTarget } = services.focus;
|
||||
const { applyTrackedCameraFrame } = services.camera;
|
||||
const { resolvePickId, isOwnedByOtherLayer, pickContact } = services.picking;
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
|
||||
function _emitAwarenessEvent(type, detail) {
|
||||
if (
|
||||
@@ -1047,7 +1047,7 @@ export function createTracking({
|
||||
*/
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (flightState._clickHandler) return; // already installed
|
||||
if (flightState._clickSubscription) return; // already installed
|
||||
|
||||
// Cross-layer untrack (mirror of flights): if another layer grabs the follow-camera, drop our
|
||||
// tracking without touching viewer.trackedEntity (the new owner controls it).
|
||||
@@ -1069,10 +1069,8 @@ export function createTracking({
|
||||
});
|
||||
}
|
||||
|
||||
flightState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
bindTrackingClickGesture(flightState._clickHandler, (click, gesture) => {
|
||||
flightState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
const gesture = event.gesture;
|
||||
// Camera drags never select or deselect, even if they finish over a plane.
|
||||
// Duration alone is allowed through so a stationary long press can still
|
||||
// select/switch contacts; the destructive empty-space branch below applies
|
||||
@@ -1082,9 +1080,7 @@ export function createTracking({
|
||||
// first-person reference. Empty globe clicks are inert until the user
|
||||
// exits with C, Escape, or the dedicated button.
|
||||
if (document.body.classList.contains('cockpit-mode')) return;
|
||||
const picked = pickContact
|
||||
? pickContact(viewer.scene, click.position)
|
||||
: viewer.scene.pick(click.position);
|
||||
const picked = event.hit;
|
||||
|
||||
if (picked) {
|
||||
// Clicking the tracked entity itself -- ignore (don't deselect)
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
isCurrentPublication,
|
||||
} from './inciweb.js';
|
||||
import { msg, t } from '../../i18n/index.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
export { normalizeFirePerimeterSnapshot } from './records.js';
|
||||
export { createWfigsPerimeterSource } from './source.js';
|
||||
export * from './cards.js';
|
||||
@@ -39,9 +40,8 @@ const INCIWEB_INDEX_TTL_MS = 6 * 3600000;
|
||||
export function createFirePerimetersLayer({
|
||||
source,
|
||||
overlayHost = null,
|
||||
screenSpaceEventHandlerFactory = null,
|
||||
inputFor = defaultInputFor,
|
||||
picking = null,
|
||||
pointer = null,
|
||||
inciwebSource = null,
|
||||
inciwebPublications = null,
|
||||
openExternal = null,
|
||||
@@ -59,7 +59,7 @@ export function createFirePerimetersLayer({
|
||||
let _stale = false;
|
||||
let _lastError = null;
|
||||
let _enabled = false;
|
||||
let _clickHandler = null;
|
||||
let _clickSubscription = null;
|
||||
let _selectedId = null;
|
||||
let _selectedLink = null;
|
||||
let _selectedCardId = null;
|
||||
@@ -76,8 +76,7 @@ export function createFirePerimetersLayer({
|
||||
_linkRequest = null;
|
||||
}
|
||||
|
||||
const canSelect = () =>
|
||||
overlayHost && screenSpaceEventHandlerFactory && picking;
|
||||
const canSelect = () => overlayHost && inputFor && picking;
|
||||
|
||||
/**
|
||||
* Refresh the InciWeb catalog off the render path: a hanging or failed
|
||||
@@ -185,27 +184,25 @@ export function createFirePerimetersLayer({
|
||||
}
|
||||
|
||||
function installClickHandler() {
|
||||
if (!canSelect() || _clickHandler || !_viewer) return;
|
||||
if (!canSelect() || _clickSubscription || !_viewer) return;
|
||||
// Deliberately NOT registered in the pick-ownership registry: sibling
|
||||
// layers yield to owned picks before their own overlay-card hit-tests,
|
||||
// so claiming these large ground polygons would make FIRMS/vessel/CCTV
|
||||
// cards inert anywhere over a perimeter. Unowned, our picks read as
|
||||
// "empty space" to siblings — the pre-existing behavior for the globe.
|
||||
_clickHandler = screenSpaceEventHandlerFactory(_viewer);
|
||||
_clickHandler.setInputAction((click) => {
|
||||
if (pointer && !pointer.isPointerFree()) return;
|
||||
_clickSubscription = inputFor(_viewer).onClick((event) => {
|
||||
// A click on the incident card itself opens its InciWeb page (when the
|
||||
// incident has one) and never disturbs the selection.
|
||||
const cardHit = overlayHost.hitTest?.(
|
||||
click.position?.x,
|
||||
click.position?.y,
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
{ sourceId: PERIMETER_OVERLAY_SOURCE_ID },
|
||||
);
|
||||
if (cardHit && cardHit.entryId === _selectedCardId) {
|
||||
if (_selectedLink && openExternal) openExternal(_selectedLink);
|
||||
return;
|
||||
}
|
||||
const picked = _viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
const incidentId = picked ? pickedIncidentId(picked) : null;
|
||||
if (incidentId) {
|
||||
abortLinkVerification();
|
||||
@@ -224,14 +221,12 @@ export function createFirePerimetersLayer({
|
||||
_selectedId = null;
|
||||
publishSelectedCard();
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
|
||||
function removeClickHandler() {
|
||||
if (_clickHandler) {
|
||||
_clickHandler.destroy();
|
||||
_clickHandler = null;
|
||||
}
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createFirePerimetersLayer } from './index.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
|
||||
function harness(
|
||||
source,
|
||||
@@ -16,7 +17,6 @@ function harness(
|
||||
) {
|
||||
const sources = [];
|
||||
const overlay = { entries: new Map(), visible: null };
|
||||
const clicks = { handler: null, destroyed: 0 };
|
||||
const owners = new Map();
|
||||
const opened = [];
|
||||
const viewer = {
|
||||
@@ -30,6 +30,13 @@ function harness(
|
||||
},
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
const clicks = {
|
||||
handler: (click) => input.click(click.position),
|
||||
get destroyed() {
|
||||
return input.input.subscriberCount() === 0 ? 1 : 0;
|
||||
},
|
||||
};
|
||||
const layer = createFirePerimetersLayer({
|
||||
source,
|
||||
overlayHost: {
|
||||
@@ -44,15 +51,7 @@ function harness(
|
||||
},
|
||||
hitTest: (x, y, options) => cardHit(x, y, options),
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => ({
|
||||
setInputAction(callback) {
|
||||
clicks.handler = callback;
|
||||
},
|
||||
destroy() {
|
||||
clicks.destroyed += 1;
|
||||
clicks.handler = null;
|
||||
},
|
||||
}),
|
||||
inputFor: () => input.input,
|
||||
picking: {
|
||||
resolvePickId: (picked) => picked?.id ?? null,
|
||||
isOwnedByOtherLayer: (layerId, pickedId) =>
|
||||
@@ -60,7 +59,6 @@ function harness(
|
||||
registerPickOwner: (layerId, predicate) => owners.set(layerId, predicate),
|
||||
unregisterPickOwner: (layerId) => owners.delete(layerId),
|
||||
},
|
||||
pointer: { isPointerFree: () => true },
|
||||
inciwebSource: inciwebIndex
|
||||
? { getIndex: async () => inciwebIndex }
|
||||
: { getIndex: async () => [] },
|
||||
@@ -331,7 +329,7 @@ test('a stale or unverifiable publication yields no link', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('a hanging InciWeb index fetch never blocks the perimeter refresh', async () => {
|
||||
test('a hanging InciWeb index fetch never blocks the perimeter refresh', async (t) => {
|
||||
const h = harness({ getSnapshot: async () => [row] }, { inciwebIndex: null });
|
||||
// Replace the index source with one that never resolves.
|
||||
h.layer.destroy(h.viewer);
|
||||
@@ -345,6 +343,8 @@ test('a hanging InciWeb index fetch never blocks the perimeter refresh', async (
|
||||
remove: (v) => sources.splice(sources.indexOf(v), 1),
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
t.after(() => input.destroy());
|
||||
const layer = createFirePerimetersLayer({
|
||||
source: { getSnapshot: async () => [row] },
|
||||
overlayHost: {
|
||||
@@ -377,7 +377,7 @@ test('a hanging InciWeb index fetch never blocks the perimeter refresh', async (
|
||||
layer.destroy(viewer);
|
||||
});
|
||||
|
||||
test('an InciWeb outage never breaks the perimeter refresh', async () => {
|
||||
test('an InciWeb outage never breaks the perimeter refresh', async (t) => {
|
||||
const h = harness({ getSnapshot: async () => [row] });
|
||||
const failing = createFirePerimetersLayer({
|
||||
source: { getSnapshot: async () => [row] },
|
||||
@@ -409,6 +409,8 @@ test('an InciWeb outage never breaks the perimeter refresh', async () => {
|
||||
scene: { pick: () => null },
|
||||
dataSources: { add() {}, remove() {} },
|
||||
};
|
||||
const failingInput = fakeInput(viewer);
|
||||
t.after(() => failingInput.destroy());
|
||||
failing.init(viewer);
|
||||
failing.enable(viewer);
|
||||
assert.equal(await failing.update(viewer), true);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
RADIO_PREFIX,
|
||||
RADIO_PICK_OFFSETS,
|
||||
RADIO_PICK_WINDOW_PX,
|
||||
RADIO_OVERLAY_SOURCE_ID,
|
||||
HORIZON_TICK_MS,
|
||||
} from './policy.js';
|
||||
@@ -46,9 +45,15 @@ export function createInteraction({
|
||||
return null;
|
||||
}
|
||||
|
||||
function pickedRadioStationAt(position) {
|
||||
const scene = layerState._viewer?.scene;
|
||||
if (!scene || !position) return null;
|
||||
/**
|
||||
* The station under a click: the pick itself, then one drill through a
|
||||
* window around it, which also catches a near miss. Both passes are the
|
||||
* click's own, so other layers reading the same click share them.
|
||||
* @param {import('../../input/dispatcher.js').ClickEvent} event
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function pickedRadioStationAt(event) {
|
||||
if (!event) return null;
|
||||
|
||||
const stationFromPick = (picked) => {
|
||||
const stationId = radioStationIdFromPick(picked);
|
||||
@@ -56,28 +61,17 @@ export function createInteraction({
|
||||
? stationId
|
||||
: null;
|
||||
};
|
||||
const primaryPick = scene.pick(position);
|
||||
const primaryPick = event.pick;
|
||||
const primaryStationId = stationFromPick(primaryPick);
|
||||
if (primaryStationId) return primaryStationId;
|
||||
const primaryId = resolvePickId(primaryPick);
|
||||
if (primaryId && isOwnedByOtherLayer('radio', primaryId)) return null;
|
||||
|
||||
if (typeof scene.drillPick === 'function') {
|
||||
const drilled = scene.drillPick(position, 16) || [];
|
||||
for (const picked of drilled) {
|
||||
const stationId = stationFromPick(picked);
|
||||
if (stationId) return stationId;
|
||||
}
|
||||
}
|
||||
|
||||
for (const [offsetX, offsetY] of RADIO_PICK_OFFSETS) {
|
||||
const offsetPosition = new Cesium.Cartesian2(
|
||||
position.x + offsetX,
|
||||
position.y + offsetY,
|
||||
);
|
||||
const picked = scene.pick(offsetPosition);
|
||||
const pickedId = resolvePickId(picked);
|
||||
if (pickedId && isOwnedByOtherLayer('radio', pickedId)) continue;
|
||||
for (const picked of event.drill(
|
||||
16,
|
||||
RADIO_PICK_WINDOW_PX,
|
||||
RADIO_PICK_WINDOW_PX,
|
||||
)) {
|
||||
const stationId = stationFromPick(picked);
|
||||
if (stationId) return stationId;
|
||||
}
|
||||
@@ -112,16 +106,12 @@ export function createInteraction({
|
||||
}
|
||||
|
||||
function installInteraction() {
|
||||
if (!layerState._viewer || layerState._clickHandler) return;
|
||||
if (!layerState._viewer || layerState._clickSubscription) return;
|
||||
registerPickOwner('radio', (id) => id.startsWith(RADIO_PREFIX));
|
||||
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
layerState._viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
const viewer = layerState._viewer;
|
||||
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!radioPresentationAllowed()) return;
|
||||
const stationId = pickedRadioStationAt(click.position);
|
||||
const stationId = pickedRadioStationAt(event);
|
||||
if (!stationId) return;
|
||||
layerState._playFallbackId = null;
|
||||
layerState._playFallbackFocus = null;
|
||||
@@ -134,7 +124,7 @@ export function createInteraction({
|
||||
new CustomEvent('gev:radio-selected', { detail: { stationId } }),
|
||||
);
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
// Polling remains bounded during flights, but a stationary camera no longer
|
||||
// rewrites every station's visibility four times per second while voice and
|
||||
// audio processing share the main thread.
|
||||
@@ -146,8 +136,8 @@ export function createInteraction({
|
||||
|
||||
function removeInteraction() {
|
||||
unregisterPickOwner('radio');
|
||||
layerState._clickHandler?.destroy();
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
if (layerState._horizonTimer) clearInterval(layerState._horizonTimer);
|
||||
layerState._horizonTimer = null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createInteraction } from './interaction.js';
|
||||
import { RADIO_PICK_WINDOW_PX } from './policy.js';
|
||||
|
||||
function interaction() {
|
||||
const state = { _stationById: new Map([['kexp', {}]]) };
|
||||
return createInteraction({
|
||||
state,
|
||||
services: {
|
||||
picking: {
|
||||
resolvePickId: (picked) => picked?.id ?? null,
|
||||
isOwnedByOtherLayer: (layer, id) => id === 'flight-1',
|
||||
registerPickOwner() {},
|
||||
unregisterPickOwner() {},
|
||||
},
|
||||
overlays: { setOverlaySourceVisible() {} },
|
||||
},
|
||||
parts: {},
|
||||
});
|
||||
}
|
||||
|
||||
/** A click event whose drill answers only with the window it is asked for. */
|
||||
function clickEvent({ pick, windowHits = [] }) {
|
||||
const drills = [];
|
||||
return {
|
||||
drills,
|
||||
pick,
|
||||
drill(limit, width, height) {
|
||||
drills.push([limit, width, height]);
|
||||
return width === RADIO_PICK_WINDOW_PX && height === RADIO_PICK_WINDOW_PX
|
||||
? windowHits
|
||||
: [];
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('a near miss finds the station through one windowed drill', () => {
|
||||
const { pickedRadioStationAt } = interaction();
|
||||
const event = clickEvent({
|
||||
pick: undefined,
|
||||
windowHits: [{ id: 'tile' }, { id: 'radio:kexp' }],
|
||||
});
|
||||
assert.equal(pickedRadioStationAt(event), 'kexp');
|
||||
assert.deepEqual(event.drills, [
|
||||
[16, RADIO_PICK_WINDOW_PX, RADIO_PICK_WINDOW_PX],
|
||||
]);
|
||||
});
|
||||
|
||||
test('a direct hit needs no drill, and another layer’s contact keeps its click', () => {
|
||||
const { pickedRadioStationAt } = interaction();
|
||||
const direct = clickEvent({ pick: { id: 'radio:kexp' } });
|
||||
assert.equal(pickedRadioStationAt(direct), 'kexp');
|
||||
assert.deepEqual(direct.drills, []);
|
||||
const other = clickEvent({
|
||||
pick: { id: 'flight-1' },
|
||||
windowHits: [{ id: 'radio:kexp' }],
|
||||
});
|
||||
assert.equal(pickedRadioStationAt(other), null);
|
||||
});
|
||||
@@ -12,6 +12,9 @@ export const SELECTED_LIFT_M = 5;
|
||||
|
||||
const RADIO_PICK_TOLERANCE_PX = 8;
|
||||
|
||||
/** A click this close to a station picks it: one drill window of this size. */
|
||||
export const RADIO_PICK_WINDOW_PX = RADIO_PICK_TOLERANCE_PX * 2 + 1;
|
||||
|
||||
export const RADIO_TUNER_DIRECTORY_LIMIT = 750;
|
||||
|
||||
export const RADIO_TUNER_STATION_LIMIT = RADIO_TUNER_DIRECTORY_LIMIT;
|
||||
@@ -51,17 +54,6 @@ export const RADIO_OVERLAY_SOURCE_OPTIONS = Object.freeze({
|
||||
moving: false,
|
||||
});
|
||||
|
||||
export const RADIO_PICK_OFFSETS = Object.freeze([
|
||||
[0, -RADIO_PICK_TOLERANCE_PX],
|
||||
[RADIO_PICK_TOLERANCE_PX, 0],
|
||||
[0, RADIO_PICK_TOLERANCE_PX],
|
||||
[-RADIO_PICK_TOLERANCE_PX, 0],
|
||||
[6, -6],
|
||||
[6, 6],
|
||||
[-6, 6],
|
||||
[-6, -6],
|
||||
]);
|
||||
|
||||
export const DEFAULT_RADIO_FILTER = 'all';
|
||||
|
||||
export const GLOBAL_RADIO_ALTITUDE_M = 2_000_000;
|
||||
|
||||
@@ -122,7 +122,7 @@ export function createState({ services }) {
|
||||
|
||||
layerState._playFallbackAttemptId = null;
|
||||
|
||||
layerState._clickHandler = null;
|
||||
layerState._clickSubscription = null;
|
||||
|
||||
layerState._horizonTimer = null;
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
* responses, and the Cesium/viewer/document fakes the box tool needs.
|
||||
*/
|
||||
import { thumbnailOrder } from './model.js';
|
||||
import {
|
||||
FAKE_EVENT_TYPES as EVENT_TYPES,
|
||||
FakeScreenSpaceEventHandler,
|
||||
fakeInput,
|
||||
} from '../../input/testDoubles.mjs';
|
||||
|
||||
export const BOX = Object.freeze({
|
||||
west: -97.8,
|
||||
@@ -60,40 +65,11 @@ export function response({
|
||||
};
|
||||
}
|
||||
|
||||
const EVENT_TYPES = {
|
||||
LEFT_DOWN: 'down',
|
||||
MOUSE_MOVE: 'move',
|
||||
LEFT_UP: 'up',
|
||||
LEFT_CLICK: 'click',
|
||||
LEFT_DOUBLE_CLICK: 'dblclick',
|
||||
};
|
||||
|
||||
/**
|
||||
* Cesium, viewer and document fakes for `initImageryBoxTool`. The canvas is
|
||||
* 1000 × 500 px mapped linearly onto 0.2° near Austin; y < 40 px is sky.
|
||||
*/
|
||||
export function boxToolFakes() {
|
||||
const handlers = [];
|
||||
class ScreenSpaceEventHandler {
|
||||
constructor(canvas) {
|
||||
this.canvas = canvas;
|
||||
this.actions = new Map();
|
||||
this.destroyed = false;
|
||||
handlers.push(this);
|
||||
}
|
||||
setInputAction(fn, type) {
|
||||
this.actions.set(type, fn);
|
||||
}
|
||||
getInputAction(type) {
|
||||
return this.actions.get(type);
|
||||
}
|
||||
removeInputAction(type) {
|
||||
this.actions.delete(type);
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
}
|
||||
class CustomDataSource {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
@@ -107,8 +83,6 @@ export function boxToolFakes() {
|
||||
}
|
||||
const color = { withAlpha: (alpha) => ({ alpha }) };
|
||||
const cesium = {
|
||||
ScreenSpaceEventHandler,
|
||||
ScreenSpaceEventType: EVENT_TYPES,
|
||||
CustomDataSource,
|
||||
CallbackProperty: class {},
|
||||
PolylineDashMaterialProperty: class {},
|
||||
@@ -118,7 +92,7 @@ export function boxToolFakes() {
|
||||
Cartesian3: { fromDegreesArray: (values) => values },
|
||||
};
|
||||
|
||||
const stock = new ScreenSpaceEventHandler('stock');
|
||||
const stock = new FakeScreenSpaceEventHandler();
|
||||
const originalClick = () => 'select';
|
||||
const originalDouble = () => 'track';
|
||||
stock.setInputAction(originalClick, EVENT_TYPES.LEFT_CLICK);
|
||||
@@ -159,13 +133,13 @@ export function boxToolFakes() {
|
||||
},
|
||||
};
|
||||
|
||||
const input = fakeInput(viewer, { eventTypes: EVENT_TYPES });
|
||||
|
||||
const pickWorld = (_viewer, nx, ny) =>
|
||||
ny * 500 < 40 ? null : { lon: -97.9 + nx * 0.2, lat: 30.4 - ny * 0.2 };
|
||||
/** The live (non-stock) canvas handler, if the tool has one bound. */
|
||||
const handler = () =>
|
||||
handlers.find((h) => h.canvas !== 'stock' && !h.destroyed) || null;
|
||||
const fire = (type, event) =>
|
||||
handler()?.actions.get(EVENT_TYPES[type])?.(event);
|
||||
/** Whether the tool has pointer input bound on the scene's dispatcher. */
|
||||
const bound = () => input.input.subscriberCount() > 0;
|
||||
const fire = (type, event) => input.handler.fire(EVENT_TYPES[type], event);
|
||||
/** Dispatch a keydown to the tool's document listener. */
|
||||
const key = (name) => {
|
||||
const event = {
|
||||
@@ -187,7 +161,8 @@ export function boxToolFakes() {
|
||||
viewer,
|
||||
documentRef,
|
||||
pickWorld,
|
||||
handler,
|
||||
input: input.input,
|
||||
bound,
|
||||
fire,
|
||||
key,
|
||||
types: EVENT_TYPES,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { readEntityRecord } from '../../data/entityRecords.js';
|
||||
|
||||
export function createInteraction({
|
||||
@@ -18,7 +17,7 @@ export function createInteraction({
|
||||
}
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (layerState._clickHandler) return; // already installed
|
||||
if (layerState._clickSubscription) return; // already installed
|
||||
|
||||
// Cross-layer untrack (H2, mirror of flights): if ANOTHER layer (flights,
|
||||
// military, …) grabs the follow-camera, drop our tracking so the orbit ring /
|
||||
@@ -44,14 +43,9 @@ export function createInteraction({
|
||||
});
|
||||
}
|
||||
|
||||
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
layerState._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!layerState._enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const picked = event.pick;
|
||||
|
||||
if (picked) {
|
||||
// Clicking tracked entity itself — ignore
|
||||
@@ -82,7 +76,7 @@ export function createInteraction({
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
parts.tracking._clearTracking(false, { origin: 'user' });
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
}
|
||||
|
||||
@@ -105,10 +105,8 @@ export function createLifecycle({
|
||||
parts.tracking._clearTracking();
|
||||
parts.labels._syncIssOverlay();
|
||||
// Remove click handler + keydown listener + preRender propagation while disabled
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
if (layerState._trackedEntityChangedRemove) {
|
||||
layerState._trackedEntityChangedRemove();
|
||||
layerState._trackedEntityChangedRemove = null;
|
||||
@@ -127,10 +125,8 @@ export function createLifecycle({
|
||||
layerState._enabled = false;
|
||||
parts.tracking._clearTracking();
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
if (layerState._clickHandler) {
|
||||
layerState._clickHandler.destroy();
|
||||
layerState._clickHandler = null;
|
||||
}
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
if (layerState._trackedEntityChangedRemove) {
|
||||
layerState._trackedEntityChangedRemove();
|
||||
layerState._trackedEntityChangedRemove = null;
|
||||
|
||||
@@ -84,7 +84,7 @@ export function createState({ services }) {
|
||||
|
||||
state._trackedEntity = null;
|
||||
|
||||
state._clickHandler = null;
|
||||
state._clickSubscription = null;
|
||||
|
||||
/** @type {Cesium.Event.RemoveCallback|null} trackedEntityChanged listener disposer (cross-layer untrack) */
|
||||
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { CLICK_PICK_WINDOW_PX, STREET_LEVEL_LAYER_ID } from './policy.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
/** One click handler for every provider's lines and cones, and the marker. */
|
||||
export function createSelection({ state, parts }) {
|
||||
const { picking, input } = state.services;
|
||||
const { picking } = state.services;
|
||||
|
||||
/** The id carries a provider's prefix: that provider handles the pick. */
|
||||
function onClick(click) {
|
||||
function onClick(event) {
|
||||
const viewer = state.viewer;
|
||||
if (!viewer || !state.enabled) return;
|
||||
if (input?.isPointerFree && !input.isPointerFree()) return;
|
||||
const picked = viewer.scene.pick(
|
||||
click.position,
|
||||
CLICK_PICK_WINDOW_PX,
|
||||
CLICK_PICK_WINDOW_PX,
|
||||
);
|
||||
const picked = event.pickWindow(CLICK_PICK_WINDOW_PX, CLICK_PICK_WINDOW_PX);
|
||||
const id = picking?.resolvePickId
|
||||
? picking.resolvePickId(picked)
|
||||
: picked?.id;
|
||||
const route = parts.router.resolve(id);
|
||||
// Not ours: the ground handler decides whether it is the map itself.
|
||||
if (!route) {
|
||||
parts.openAtGround?.(click.position, picked);
|
||||
parts.openAtGround?.(event.position, picked);
|
||||
return;
|
||||
}
|
||||
// The position marker is the core's own: nothing to select.
|
||||
if (!route.instance) return;
|
||||
route.instance.handlePick(route.id, {
|
||||
groundPoint: () => groundPointAt(viewer, click.position),
|
||||
groundPoint: () => groundPointAt(viewer, event.position),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,23 +63,17 @@ export function createSelection({ state, parts }) {
|
||||
}
|
||||
|
||||
function install(viewer) {
|
||||
if (state.clickHandler) return;
|
||||
state.clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
state.clickHandler.setInputAction(
|
||||
onClick,
|
||||
Cesium.ScreenSpaceEventType.LEFT_CLICK,
|
||||
);
|
||||
if (state.clickSubscription) return;
|
||||
state.clickSubscription = inputFor(viewer).onClick(onClick);
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick);
|
||||
}
|
||||
|
||||
function uninstall() {
|
||||
// Nothing to undo for a layer that was never enabled.
|
||||
if (!state.clickHandler) return;
|
||||
if (!state.clickHandler.isDestroyed()) state.clickHandler.destroy();
|
||||
state.clickHandler = null;
|
||||
if (!state.clickSubscription) return;
|
||||
state.clickSubscription();
|
||||
state.clickSubscription = null;
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
picking?.unregisterPickOwner?.(STREET_LEVEL_LAYER_ID);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createSelection } from './selection.js';
|
||||
import { createPickRouter } from './pickRouter.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
|
||||
/** The selection installed on a stand-in viewer, with what its clicks reach. */
|
||||
function harness({ selected = false, services = {}, providers = [] } = {}) {
|
||||
@@ -40,7 +41,7 @@ function harness({ selected = false, services = {}, providers = [] } = {}) {
|
||||
const state = {
|
||||
viewer,
|
||||
enabled: true,
|
||||
clickHandler: null,
|
||||
clickSubscription: null,
|
||||
services: { picking: null, input: null, ...services },
|
||||
providers: new Map([
|
||||
[
|
||||
@@ -71,17 +72,16 @@ function harness({ selected = false, services = {}, providers = [] } = {}) {
|
||||
sequences.selected = false;
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
const selection = createSelection({ state, parts });
|
||||
selection.install(viewer);
|
||||
const action = (type) =>
|
||||
state.clickHandler.getInputAction(Cesium.ScreenSpaceEventType[type]);
|
||||
return {
|
||||
state,
|
||||
sequences,
|
||||
opened,
|
||||
groundClicks,
|
||||
scene,
|
||||
click: (x = 10) => action('LEFT_CLICK')({ position: { x, y: 10 } }),
|
||||
click: (x = 10) => input.click({ x, y: 10 }),
|
||||
/** A keydown reaching the document from `target`; the event as handled. */
|
||||
key(key, target, { defaultPrevented = false } = {}) {
|
||||
const event = {
|
||||
@@ -248,7 +248,10 @@ test('a click on a provider line hands it the ground under the click, measured o
|
||||
const point = handled[0].click.groundPoint();
|
||||
assert.ok(Math.abs(point.lon + 83.0458) < 1e-9);
|
||||
assert.ok(Math.abs(point.lat - 42.3314) < 1e-9);
|
||||
assert.deepEqual(groundPicks, [{ x: 40, y: 10 }]);
|
||||
assert.deepEqual(
|
||||
groundPicks.map(({ x, y }) => ({ x, y })),
|
||||
[{ x: 40, y: 10 }],
|
||||
);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ export function createState({ services }) {
|
||||
groundClickReady: false,
|
||||
|
||||
marker: { collection: null, billboard: null, look: null },
|
||||
clickHandler: null,
|
||||
clickSubscription: null,
|
||||
};
|
||||
}
|
||||
@@ -4,10 +4,11 @@ import { defaultSweepClock } from './policy.js';
|
||||
import { createRendering } from './rendering.js';
|
||||
import { createIngestion } from './ingestion.js';
|
||||
import { createInteraction } from './interaction.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
export function createSubmarineCableLayer({
|
||||
source,
|
||||
overlayHost,
|
||||
screenSpaceEventHandlerFactory,
|
||||
inputFor = defaultInputFor,
|
||||
mapStackEventTarget = null,
|
||||
sweepClock = defaultSweepClock,
|
||||
}) {
|
||||
@@ -21,7 +22,7 @@ export function createSubmarineCableLayer({
|
||||
state,
|
||||
parts,
|
||||
source,
|
||||
screenSpaceEventHandlerFactory,
|
||||
inputFor,
|
||||
mapStackEventTarget,
|
||||
};
|
||||
parts.rendering = createRendering(context);
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { cablePicks } from './pickState.js';
|
||||
|
||||
export function createInteraction({ state, screenSpaceEventHandlerFactory }) {
|
||||
export function createInteraction({ state, inputFor }) {
|
||||
function registerPickEntity(entity, info) {
|
||||
cablePicks.write(entity).info = info;
|
||||
}
|
||||
|
||||
function beginInteraction(viewer) {
|
||||
if (state._clickHandler) return;
|
||||
state._clickHandler = screenSpaceEventHandlerFactory(viewer.scene.canvas);
|
||||
state._clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (state._clickSubscription) return;
|
||||
state._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!state._enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
const record = resolvePickRecord(picked);
|
||||
const record = resolvePickRecord(event.pick);
|
||||
if (!record?.reference) return;
|
||||
flyToReference(viewer, record.reference);
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
|
||||
function resolvePickRecord(picked) {
|
||||
|
||||
@@ -101,10 +101,8 @@ export function createLifecycle({ state, parts, source, mapStackEventTarget }) {
|
||||
// Pinned by the direct-destroy host test: removing this line leaves a
|
||||
// visible overlay source with orphan labels.
|
||||
state._overlayPublisher.hide();
|
||||
if (state._clickHandler) {
|
||||
state._clickHandler.destroy();
|
||||
state._clickHandler = null;
|
||||
}
|
||||
state._clickSubscription?.();
|
||||
state._clickSubscription = null;
|
||||
if (state._preRenderRemover) {
|
||||
state._preRenderRemover();
|
||||
state._preRenderRemover = null;
|
||||
|
||||
@@ -51,7 +51,7 @@ export function createState({ sweepClock, overlayHost }) {
|
||||
|
||||
state._surfaceRecords = [];
|
||||
|
||||
state._clickHandler = null;
|
||||
state._clickSubscription = null;
|
||||
|
||||
state._preRenderRemover = null;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
releaseContinuousRender,
|
||||
uninstallRenderGovernor,
|
||||
} from '../../renderGovernor.js';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
|
||||
const BOSTON = { lat: 42.3601, lon: -71.0589 };
|
||||
|
||||
@@ -319,9 +320,11 @@ function harness(
|
||||
else globalThis.window = originalWindow;
|
||||
});
|
||||
|
||||
const input = fakeInput(viewer);
|
||||
return {
|
||||
layer,
|
||||
viewer,
|
||||
input,
|
||||
primitives,
|
||||
sprites,
|
||||
pickOwners,
|
||||
@@ -3169,11 +3172,7 @@ test('click handler selects a migrated scripted billboard and prepares a valid d
|
||||
const entry = app.vehicles()[0];
|
||||
assert.equal(entry.markerCollection, app.state()._animatedMarkers);
|
||||
app.viewer.scene.pick = () => ({ primitive: entry.marker, id: entry.key });
|
||||
app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)({
|
||||
position: new Cesium.Cartesian2(500, 400),
|
||||
});
|
||||
app.input.click(new Cesium.Cartesian2(500, 400));
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
const body = app.layer._transitPartsForTest().trails.diagnostics().body;
|
||||
assert.ok(body.geometryInstances.length > 0);
|
||||
@@ -3401,11 +3400,7 @@ test('preset clicks preserve both pick id paths through moving and stationary co
|
||||
assert.equal(entry.marker.id, entry.key);
|
||||
for (const pick of [{ id: entry.key }, { primitive: entry.marker }]) {
|
||||
app.viewer.scene.pick = () => pick;
|
||||
app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)(
|
||||
{ position: new Cesium.Cartesian2(500, 400) },
|
||||
);
|
||||
app.input.click(new Cesium.Cartesian2(500, 400));
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
parts.selection.clearSelection();
|
||||
}
|
||||
@@ -3449,19 +3444,20 @@ test('sensor clicks map displayed pixels into the pre-shader pick buffer', async
|
||||
clientHeight: 1080,
|
||||
};
|
||||
const uniforms = { intensity: 1, pixelation: 1 };
|
||||
let preset = 'surveillance';
|
||||
scene.postProcessStages = {
|
||||
getStageByName: () => ({ enabled: true, uniforms }),
|
||||
getStageByName: (name) =>
|
||||
name === `godsEyeView_${preset}`
|
||||
? { enabled: true, uniforms }
|
||||
: undefined,
|
||||
};
|
||||
const click = app
|
||||
.state()
|
||||
._clickHandler.getInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
app.layer._transitPartsForTest().rendering.setStylePreset('surveillance');
|
||||
click({ position: new Cesium.Cartesian2(1440, 540) });
|
||||
const click = (position) => app.input.click(position);
|
||||
click(new Cesium.Cartesian2(1440, 540));
|
||||
assert.ok(Math.abs(actual.x - 1472) < 1e-6);
|
||||
assert.equal(actual.y, 540);
|
||||
app.layer._transitPartsForTest().rendering.setStylePreset('thermal');
|
||||
preset = 'thermal';
|
||||
uniforms.pixelation = 1.5;
|
||||
click({ position: new Cesium.Cartesian2(100.9, 200.1) });
|
||||
click(new Cesium.Cartesian2(100.9, 200.1));
|
||||
assert.ok(Math.abs(actual.x - 100.5) < 1e-6);
|
||||
assert.ok(Math.abs(actual.y - 201) < 1e-6);
|
||||
assert.equal(app.state()._selectedKey, entry.key);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
createTransitSelectedOverlayEntry,
|
||||
} from './policy.js';
|
||||
import { getRegisteredTransitFeed } from '../../data/transitFeeds.js';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
|
||||
/**
|
||||
@@ -115,49 +115,12 @@ export function createSelection({ state, services, parts }) {
|
||||
}
|
||||
|
||||
function installClickHandler(viewer) {
|
||||
if (state._clickHandler) return;
|
||||
state._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
state._clickHandler.setInputAction((click) => {
|
||||
// Ambient selection never competes for a pointer a tool has claimed:
|
||||
// placing a draw vertex on top of a bus must not also select the bus.
|
||||
if (!isPointerFree()) return;
|
||||
const scene = viewer.scene;
|
||||
// Pick buffers precede post-processing. Map a sensor pixel back through
|
||||
// the active shader's barrel distortion and quantization before picking.
|
||||
const position = Cesium.Cartesian2.clone(click.position);
|
||||
const style = state._stylePreset;
|
||||
const stage = scene.postProcessStages?.getStageByName?.(
|
||||
`godsEyeView_${style}`,
|
||||
);
|
||||
if (stage?.enabled && (style === 'thermal' || style === 'surveillance')) {
|
||||
const intensity = stage.uniforms.intensity;
|
||||
const canvas = scene.canvas,
|
||||
w = canvas.clientWidth,
|
||||
h = canvas.clientHeight;
|
||||
let u = position.x / w,
|
||||
v = 1 - position.y / h;
|
||||
if (style === 'surveillance') {
|
||||
const x = u * 2 - 1,
|
||||
y = v * 2 - 1,
|
||||
r2 = x * x + y * y;
|
||||
const d = 1 + r2 * intensity * 0.25 + r2 * r2 * intensity * 0.075;
|
||||
u = (x * d + 1) / 2;
|
||||
v = (y * d + 1) / 2;
|
||||
}
|
||||
const grid = 1 + (stage.uniforms.pixelation - 1) * intensity;
|
||||
u +=
|
||||
((Math.floor((u * canvas.width) / grid) * grid) / canvas.width - u) *
|
||||
intensity;
|
||||
v +=
|
||||
((Math.floor((v * canvas.height) / grid) * grid) / canvas.height -
|
||||
v) *
|
||||
intensity;
|
||||
position.x = u * w;
|
||||
position.y = (1 - v) * h;
|
||||
}
|
||||
const picked = scene.pick(position);
|
||||
if (state._clickSubscription) return;
|
||||
// The dispatcher maps a sensor-style click back into the pick buffer
|
||||
// (src/input/sensorPick.js) and skips it while a tool holds the pointer.
|
||||
state._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
const position = event.position;
|
||||
const picked = event.pick;
|
||||
state._lastPickForTest = {
|
||||
id: typeof picked?.id === 'string' ? picked.id : null,
|
||||
primitiveId:
|
||||
@@ -188,15 +151,13 @@ export function createSelection({ state, services, parts }) {
|
||||
}
|
||||
}
|
||||
if (state._selectedKey) clearSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
}
|
||||
|
||||
function removeClickHandler() {
|
||||
if (state._clickHandler) {
|
||||
state._clickHandler.destroy();
|
||||
state._clickHandler = null;
|
||||
}
|
||||
state._clickSubscription?.();
|
||||
state._clickSubscription = null;
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ export function createState({ services }) {
|
||||
/** @type {(() => void)|null} */
|
||||
state._preRenderRemove = null;
|
||||
state._renderHeld = false;
|
||||
/** @type {Cesium.ScreenSpaceEventHandler|null} */
|
||||
state._clickHandler = null;
|
||||
/** @type {(() => void)|null} Unsubscribes the vehicle-selection click. */
|
||||
state._clickSubscription = null;
|
||||
/**
|
||||
* The vehicles currently mid-glide. The per-frame pass walks THIS, not the
|
||||
* whole fleet, and the render hold is derived from it together with the
|
||||
|
||||
@@ -119,11 +119,10 @@ export function createLifecycle({
|
||||
state.records.all = [];
|
||||
state.records.byMmsi = new Map();
|
||||
state.records.unkeyed = [];
|
||||
state.clickHandler = null;
|
||||
state.clickSubscription = null;
|
||||
state.keyTarget = null;
|
||||
state.keydownHandler = null;
|
||||
state.trackedEntityRemover = null;
|
||||
state.interactionHandlerFactory = null;
|
||||
state.interactionKeyTarget = null;
|
||||
state.preRenderRemover = null;
|
||||
components.rendering.cancelTrailingVisibilityPass();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -10,7 +9,7 @@ export function createSelection({
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { resolvePickId, isOwnedByOtherLayer, pickContact } = services.picking;
|
||||
const { isOwnedByOtherLayer } = services.picking;
|
||||
const { requestWorldFocus } = services.worldFocus;
|
||||
const {
|
||||
selectEntityContext,
|
||||
@@ -20,27 +19,15 @@ export function createSelection({
|
||||
const aisLiveVesselsLayer = layer;
|
||||
|
||||
function installInteraction(viewer) {
|
||||
if (state.clickHandler || !viewer) return;
|
||||
const handler = state.interactionHandlerFactory
|
||||
? state.interactionHandlerFactory(viewer)
|
||||
: new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
bindVesselInteraction(
|
||||
viewer,
|
||||
handler,
|
||||
state.interactionKeyTarget || document,
|
||||
);
|
||||
if (state.clickSubscription || !viewer) return;
|
||||
bindVesselInteraction(viewer, state.interactionKeyTarget || document);
|
||||
}
|
||||
|
||||
function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
state.clickHandler = handler;
|
||||
handler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
function bindVesselInteraction(viewer, keyTarget) {
|
||||
state.clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!state.feed.enabled) return;
|
||||
const picked = pickContact
|
||||
? pickContact(viewer.scene, click.position)
|
||||
: viewer.scene.pick(click.position);
|
||||
const pickedId = resolvePickId(picked);
|
||||
const picked = event.hit;
|
||||
const pickedId = event.id;
|
||||
let record = pickedId ? state.records.byMmsi.get(pickedId) : null;
|
||||
// A vessel icon's pick id is its row id: the MMSI, or an unkeyed row's.
|
||||
// Removing a row destroys its pick id, so an evicted vessel cannot be
|
||||
@@ -73,8 +60,8 @@ export function createSelection({
|
||||
// actionable hit rectangles before treating the click as empty space.
|
||||
const cardHit = !record
|
||||
? vesselState._vesselOverlayHost.hitTest?.(
|
||||
click.position?.x,
|
||||
click.position?.y,
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
{
|
||||
...(cycloneBackground
|
||||
? {}
|
||||
@@ -106,7 +93,7 @@ export function createSelection({
|
||||
});
|
||||
if (transition.action === 'deselect') clearVesselInspection();
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
state.keyTarget = keyTarget;
|
||||
state.keydownHandler = onVesselKeyDown;
|
||||
keyTarget.addEventListener('keydown', state.keydownHandler);
|
||||
@@ -140,10 +127,8 @@ export function createSelection({
|
||||
}
|
||||
|
||||
function removeVesselInteraction() {
|
||||
if (state.clickHandler) {
|
||||
state.clickHandler.destroy();
|
||||
state.clickHandler = null;
|
||||
}
|
||||
state.clickSubscription?.();
|
||||
state.clickSubscription = null;
|
||||
if (state.keyTarget && state.keydownHandler) {
|
||||
state.keyTarget.removeEventListener('keydown', state.keydownHandler);
|
||||
}
|
||||
|
||||
@@ -58,16 +58,15 @@ export function createVesselState({ source, services }) {
|
||||
/** The vessels' icon set and the primitive that draws it. */
|
||||
icons: null,
|
||||
iconPrimitive: null,
|
||||
clickHandler: null,
|
||||
/** The click subscription's unsubscribe. */
|
||||
clickSubscription: null,
|
||||
/** Exact EventTarget currently holding the Escape listener. */
|
||||
keyTarget: null,
|
||||
/** Exact callback registered on keyTarget. */
|
||||
keydownHandler: null,
|
||||
/** Cesium trackedEntityChanged listener disposer. */
|
||||
trackedEntityRemover: null,
|
||||
/** Test-only factory used to exercise enable-time interaction installation. */
|
||||
interactionHandlerFactory: null,
|
||||
/** Test-only key target paired with interactionHandlerFactory. */
|
||||
/** Test-only key target for enable-time interaction installation. */
|
||||
interactionKeyTarget: null,
|
||||
preRenderRemover: null,
|
||||
/** Pending timer that renders one frame after a cadence-skipped pass. */
|
||||
|
||||
@@ -12,16 +12,16 @@ export function createTesting({
|
||||
const aisLiveVesselsLayer = layer;
|
||||
|
||||
/**
|
||||
* Bind the production interaction callbacks to mockable viewer/handler
|
||||
* surfaces. Test-only seam; behavior is shared with installInteraction().
|
||||
* Bind the production interaction callbacks to a mockable viewer. Clicks
|
||||
* come through the viewer's input dispatcher (src/input/testDoubles.mjs).
|
||||
* Test-only seam; behavior is shared with installInteraction().
|
||||
* @param {Object} viewer - Viewer-like object with scene.pick().
|
||||
* @param {Object} handler - Handler-like object with setInputAction().
|
||||
* @param {Object} keyTarget - EventTarget-like object with add/removeEventListener().
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
function _bindVesselInteractionForTest(viewer, handler, keyTarget) {
|
||||
components.selection.bindVesselInteraction(viewer, handler, keyTarget);
|
||||
function _bindVesselInteractionForTest(viewer, keyTarget) {
|
||||
components.selection.bindVesselInteraction(viewer, keyTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,6 @@ export function createTesting({
|
||||
state.feed.firstConnectPhase = options.firstConnectPhase || 'idle';
|
||||
state.feed.firstConnectStartedAt = options.firstConnectStartedAt ?? null;
|
||||
state.feed.firstConnectDeadline = options.firstConnectDeadline ?? null;
|
||||
state.interactionHandlerFactory = options.interactionHandlerFactory || null;
|
||||
state.interactionKeyTarget = options.interactionKeyTarget || null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user