Fly to places, landmarks and imported files through the camera and query ports

The camera ground guard reads the eye from the camera port's pose, the
flight state from the port, and the surface under it from the query port's
heights, and lifts through the port. Place and landmark flights read the
terrain height from the query port and build their targets with geo.
Framing ranges read the field of view from the pose (the frustum's
wider-side angle, as it read before). An imported file's flight frames its
footprint, plain lon/lat/height points, with geo's bounding sphere and the
port's flyToBounds; walking the file's Cesium data source for those points
moves into the file importer, which stays on the Cesium allow-list.

The Cesium query port answers terrain heights without depth textures, as
the height service always has: only the drawn surface needs them.

cameraGroundGuard, locations, cameraFraming and flyToDataSource leave the
allow-list. The annotation resolver, still listed, loads the camera
factory for the application operations entry, which reached it through
locations before.
This commit is contained in:
Sameh Khamis committed 2026-11-07 03:11:51 -08:00
1 parent a2c4d27b5a
commit 7ab969599c
14 files changed
+303 -214

No files matched your search

+23 -4
View File
@@ -1,10 +1,29 @@
import * as Cesium from 'cesium';
import { toRadians } from '../geo/index.js';
import { findCamera } from '../render/rendererOf.js';
/** The camera port's pose, or null when there is none to read. */
function poseOf(viewer) {
try {
return findCamera(viewer)?.pose() ?? null;
} catch {
return null;
}
}
/** Camera range with breathing room in both viewport dimensions. */
export function rangeForBoundingSphere(viewer, radius) {
const frustum = viewer.camera?.frustum;
const verticalFov = Number(frustum?.fov) || Cesium.Math.toRadians(60);
const aspectRatio = Math.max(0.5, Number(frustum?.aspectRatio) || 1);
const pose = poseOf(viewer);
const fovy = Number(pose?.fovy);
const aspect = Number(pose?.aspectRatio);
// The frustum's field of view: along its wider side.
const fov =
fovy > 0 && aspect > 1
? 2 * Math.atan(Math.tan(fovy / 2) * aspect)
: fovy > 0
? fovy
: NaN;
const verticalFov = fov || toRadians(60);
const aspectRatio = Math.max(0.5, aspect || 1);
const horizontalFov = 2 * Math.atan(Math.tan(verticalFov / 2) * aspectRatio);
const limitingFov = Math.min(verticalFov, horizontalFov);
// Target 57% sphere occupancy so perspective still leaves at least 40%
+36
View File
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import * as Cesium from 'cesium';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import { rangeForBoundingSphere } from './cameraFraming.js';
/** The range as it was read from Cesium's frustum before the camera port. */
function rangeFromFrustum(frustum, radius) {
const verticalFov = frustum.fov;
const aspectRatio = Math.max(0.5, frustum.aspectRatio);
const horizontalFov = 2 * Math.atan(Math.tan(verticalFov / 2) * aspectRatio);
const limitingFov = Math.min(verticalFov, horizontalFov);
return (radius / Math.sin((limitingFov * 0.57) / 2)) * 1.05;
}
for (const aspectRatio of [16 / 9, 390 / 844, 1]) {
test(`framing reads the frustum's field of view through the camera port (aspect ${aspectRatio.toFixed(2)})`, () => {
const frustum = new Cesium.PerspectiveFrustum({
fov: Math.PI / 3,
aspectRatio,
near: 1,
far: 1e8,
});
const viewer = bindFakeCesiumCamera({ camera: { frustum } });
const range = rangeForBoundingSphere(viewer, 250);
assert.ok(
Math.abs(range - rangeFromFrustum(frustum, 250)) < 1e-6,
`${range} vs ${rangeFromFrustum(frustum, 250)}`,
);
});
}
test('framing without a camera assumes a 60 degree square view', () => {
const expected = rangeFromFrustum({ fov: Math.PI / 3, aspectRatio: 1 }, 100);
assert.ok(Math.abs(rangeForBoundingSphere({}, 100) - expected) < 1e-9);
});
+65
View File
@@ -1528,3 +1528,68 @@ export async function loadGeoFile(
).then(() => pins.sync()),
};
}
/** All visible positions, path vertices, polygon rings, walls and overlay bounds. */
export function dataSourcePoints(dataSource, time = Cesium.JulianDate.now()) {
const points = [];
const add = (position, grounded = false) => {
if (
!position ||
![position.x, position.y, position.z].every(Number.isFinite)
)
return;
const c = Cesium.Cartographic.fromCartesian(position);
if (c && Number.isFinite(c.longitude) && Number.isFinite(c.latitude))
points.push([
Cesium.Math.toDegrees(c.longitude),
Cesium.Math.toDegrees(c.latitude),
grounded ? 0 : c.height,
]);
};
if (dataSource?.show === false) return points;
for (const entity of dataSource?.importedEntities ??
dataSource?.entities?.values ??
[]) {
if (entity.isShowing === false) continue;
add(
entity.position?.getValue?.(time),
entity.billboard?.heightReference?.getValue?.(time) ===
Cesium.HeightReference.CLAMP_TO_GROUND,
);
for (const graphic of [entity.polyline, entity.wall])
for (const position of graphic?.positions?.getValue?.(time) || [])
add(position, graphic.clampToGround?.getValue?.(time) === true);
const rings = [entity.polygon?.hierarchy?.getValue?.(time)];
while (rings.length) {
const ring = rings.pop();
for (const position of ring?.positions || [])
add(
position,
entity.polygon?.perPositionHeight?.getValue?.(time) !== true,
);
for (const hole of ring?.holes || []) rings.push(hole);
}
const rectangle = entity.rectangle?.coordinates?.getValue?.(time);
if (rectangle) {
const bounds = Cesium.RectangleGeometry.computeRectangle({
rectangle,
rotation: entity.rectangle.rotation?.getValue?.(time) || 0,
});
for (const corner of [
'southwest',
'southeast',
'northwest',
'northeast',
]) {
const c = Cesium.Rectangle[corner](bounds);
if (Number.isFinite(c.longitude) && Number.isFinite(c.latitude))
points.push([
Cesium.Math.toDegrees(c.longitude),
Cesium.Math.toDegrees(c.latitude),
entity.rectangle.height?.getValue?.(time) || 0,
]);
}
}
}
return points;
}