From afd8dba67bc871fee68e74c9d072b5ff9e205e35 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sun, 8 Nov 2026 14:49:27 -0800 Subject: [PATCH] Give sensor picks plain screen positions and the canvas from their caller sensorPickPosition returns {x, y} rather than a Cesium Cartesian2 and is handed the canvas it sizes by, so it no longer reaches Cesium or the viewer and leaves the Cesium allow-list. The style records stay keyed by the scene object. --- src/input/dispatcher.js | 10 +++++++--- src/input/dispatcher.test.mjs | 10 +++++++--- src/input/sensorPick.js | 15 ++++++++------- src/render/cesiumAllowList.json | 1 - 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/input/dispatcher.js b/src/input/dispatcher.js index 34b706354..a3e2b1920 100644 --- a/src/input/dispatcher.js +++ b/src/input/dispatcher.js @@ -126,7 +126,7 @@ const dispatchers = new WeakMap(); * method is memoized, so subscribers share the passes. * @typedef {object} ClickEvent * @property {{x: number, y: number}} screenPosition Where the user clicked. - * @property {Cesium.Cartesian2} position Where that lands in the pick buffer + * @property {{x: number, y: number}} position Where that lands in the pick buffer * (corrected for sensor styles; see sensorPick.js). * @property {ClickGesture} gesture * @property {object|undefined} pick `scene.pick` at `position`. @@ -270,7 +270,11 @@ function createDispatcher(viewer, { createHandler, now, document } = {}) { // Where the pointer lands in the pick buffer, as a click's // `position` is (corrected for sensor styles); made on first read. get pickPosition() { - pickPosition ??= sensorPickPosition(viewer.scene, endPosition); + pickPosition ??= sensorPickPosition( + viewer.scene, + endPosition, + viewer.scene.canvas, + ); return pickPosition; }, }); @@ -370,7 +374,7 @@ function createDispatcher(viewer, { createHandler, now, document } = {}) { */ function createClickEvent(viewer, click, gesture) { const scene = viewer.scene; - const position = sensorPickPosition(scene, click.position); + const position = sensorPickPosition(scene, click.position, scene.canvas); const memo = new Map(); const once = (key, compute) => { if (!memo.has(key)) memo.set(key, compute()); diff --git a/src/input/dispatcher.test.mjs b/src/input/dispatcher.test.mjs index 6abf7699f..589818b71 100644 --- a/src/input/dispatcher.test.mjs +++ b/src/input/dispatcher.test.mjs @@ -418,11 +418,11 @@ test('sensor styles move the pick to where the picture came from', () => { }; registerStyleStages(scene, { surveillance: stage }); const click = { x: 300, y: 50 }; - const mapped = sensorPickPosition(scene, click); + const mapped = sensorPickPosition(scene, click, scene.canvas); assert.notDeepEqual([mapped.x, mapped.y], [300, 50]); assert.deepEqual(click, { x: 300, y: 50 }, 'the click is left alone'); stage.enabled = false; - const plain = sensorPickPosition(scene, click); + const plain = sensorPickPosition(scene, click, scene.canvas); assert.deepEqual([plain.x, plain.y], [300, 50]); }); @@ -440,7 +440,11 @@ test('a move carries its pick-buffer position, sensor-corrected as a click is', const seen = []; h.input.onPointer('move', (event) => seen.push(event)); h.handler.fire(TYPES.MOUSE_MOVE, { endPosition: { x: 300, y: 50 } }); - const expected = sensorPickPosition(h.viewer.scene, { x: 300, y: 50 }); + const expected = sensorPickPosition( + h.viewer.scene, + { x: 300, y: 50 }, + h.viewer.scene.canvas, + ); assert.deepEqual( [seen[0].pickPosition.x, seen[0].pickPosition.y], [expected.x, expected.y], diff --git a/src/input/sensorPick.js b/src/input/sensorPick.js index 91978ac27..16ccd309f 100644 --- a/src/input/sensorPick.js +++ b/src/input/sensorPick.js @@ -6,27 +6,28 @@ * different spot of the scene: map it back through the shader's barrel * distortion and quantization first. */ -import * as Cesium from 'cesium'; import { styleStagesOf } from '../styles/styleStages.js'; const SENSOR_STYLES = ['thermal', 'surveillance']; /** * The pick-buffer position for a screen click. - * @param {Cesium.Scene} scene + * @param {object} scene The scene object the styles are recorded on. * @param {{x: number, y: number}} position CSS pixels on the canvas. - * @returns {Cesium.Cartesian2} A new position; the click's own is left alone. + * @param {{width: number, height: number, clientWidth: number, + * clientHeight: number}} canvas The canvas the scene draws in. + * @returns {{x: number, y: number}} A new position; the click's own is left + * alone. */ -export function sensorPickPosition(scene, position) { - const out = new Cesium.Cartesian2(position.x, position.y); +export function sensorPickPosition(scene, position, canvas) { + const out = { x: position.x, y: position.y }; const stages = styleStagesOf(scene); if (!stages) return out; for (const style of SENSOR_STYLES) { const stage = stages[style]; if (!stage?.enabled) continue; const intensity = stage.uniforms.intensity; - const canvas = scene.canvas, - w = canvas.clientWidth, + const w = canvas.clientWidth, h = canvas.clientHeight; let u = out.x / w, v = 1 - out.y / h; diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index 98739ecdd..3a34c4189 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -8,7 +8,6 @@ "src/cyberSonarScene.js", "src/data/geoImportPins.js", "src/input/dispatcher.js", - "src/input/sensorPick.js", "src/layers/installations/rendering.js", "src/layers/recentImagery/rendering.js", "src/layers/satellites/rendering.js",