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

+37 -100
View File
@@ -1,96 +1,38 @@
/** Frame the complete finite footprint of a session-local file. */
import * as Cesium from 'cesium';
import { guardCameraAboveGround } from '../cameraGroundGuard.js';
import { rangeForBoundingSphere } from '../data/cameraFraming.js';
import { cancelCameraArrival } from '../data/cameraArrival.js';
import { heightsFor } from '../queries/heights.js';
import { distance, fromDegrees, toLonLatH } from '../geo/index.js';
import { sphereFromPoints } from '../geo/sphere.js';
import { findCamera, findQuery } from '../render/rendererOf.js';
/** 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;
}
/** Fly synchronously to the footprint; later navigation always owns its camera. */
export function flyToDataSource(
/**
* Fly synchronously to a footprint, `[lon, lat, height]` points (degrees,
* metres) such as a file's (`dataSourcePoints`); later navigation always
* owns its camera. False when there is nothing to frame or no camera.
*/
export function flyToFootprint(
viewer,
dataSource,
points,
{ duration = 1.5, ground = null } = {},
) {
const points = dataSourcePoints(dataSource);
if (!points.length) return false;
if (!points?.length) return false;
const camera = findCamera(viewer);
if (!camera) return false;
cancelCameraArrival(viewer);
const positions = points.map(([lon, lat, height]) =>
Cesium.Cartesian3.fromDegrees(lon, lat, height),
fromDegrees(lon, lat, height),
);
const sphere = Cesium.BoundingSphere.fromPoints(positions);
const center =
Cesium.Cartographic.fromCartesian(sphere.center) ||
Cesium.Cartographic.fromDegrees(points[0][0], points[0][1]);
const lat = Cesium.Math.toDegrees(center.latitude),
lon = Cesium.Math.toDegrees(center.longitude);
const terrain = viewer.scene
? heightsFor(viewer.scene).now(center, { against: 'terrain' })
: null;
const sphere = sphereFromPoints(positions);
const center = toLonLatH(sphere.center) || {
lon: points[0][0],
lat: points[0][1],
height: 0,
};
const { lat, lon } = center;
const terrain =
findQuery(viewer)?.sampleHeightNow({ lon, lat }, { against: 'terrain' }) ??
null;
const cached = ground?.cachedGroundFloor?.(lat, lon);
const height =
Number.isFinite(terrain) && terrain > 0
@@ -101,25 +43,20 @@ export function flyToDataSource(
? terrain
: 0;
ground?.warmGroundFloor?.([{ lat, lon }]);
sphere.center = Cesium.Cartesian3.fromRadians(
center.longitude,
center.latitude,
Math.max(0, height, center.height),
);
sphere.radius = 0;
const framed = {
center: fromDegrees(lon, lat, Math.max(0, height, center.height)),
radius: 0,
};
for (const position of positions)
sphere.radius = Math.max(
sphere.radius,
Cesium.Cartesian3.distance(sphere.center, position),
);
viewer.camera?.flyToBoundingSphere?.(sphere, {
offset: new Cesium.HeadingPitchRange(
viewer.camera.heading || 0,
-Math.PI / 2,
Math.max(800, rangeForBoundingSphere(viewer, sphere.radius)),
),
duration,
complete: () => guardCameraAboveGround(viewer, { lat, lon }),
framed.radius = Math.max(framed.radius, distance(framed.center, position));
camera.flyToBounds(framed, {
offset: {
heading: camera.pose().heading || 0,
pitch: -Math.PI / 2,
range: Math.max(800, rangeForBoundingSphere(viewer, framed.radius)),
},
durationS: duration,
onComplete: () => guardCameraAboveGround(viewer, { lat, lon }),
});
return true;
}