Read transit's viewport from the camera port

Feed activation and the view bounds read the camera port's pose and view
rectangle instead of the Cesium camera; the look-at centre comes from
geo/rectangle, which crosses the antimeridian as Cesium's does. The layer's
lifecycle loads the Cesium camera factory, so a viewer of a caller's own
still has a camera to read. viewport leaves the Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-06 21:23:57 -08:00
1 parent 56d56a4d6d
commit af449184ca
5 files changed
+64 -31

No files matched your search

+20 -30
View File
@@ -1,4 +1,6 @@
import * as Cesium from 'cesium';
import { rectangleCenter } from '../../geo/rectangle.js';
import { toDegrees, toRadians } from '../../geo/vector.js';
import { findCamera } from '../../render/rendererOf.js';
import {
ACTIVATION_ENTER_ALTITUDE_M,
ACTIVATION_EXIT_ALTITUDE_M,
@@ -18,28 +20,26 @@ export function createViewport({ state, services, parts }) {
const { governorRequestRender } = services.render;
function getCameraAltitude(viewer = state._viewer) {
const carto = viewer?.camera?.positionCartographic;
return carto && Number.isFinite(carto.height) ? carto.height : Infinity;
const height = findCamera(viewer)?.pose().height;
return Number.isFinite(height) ? height : Infinity;
}
/** Where the camera looks: its view rectangle's middle, else under the eye. */
function getCameraCenterLatLon(viewer = state._viewer) {
const rect = viewer?.camera?.computeViewRectangle?.(
viewer.scene.globe?.ellipsoid,
);
const camera = findCamera(viewer);
const rect = camera?.viewRectangle();
if (rect) {
const center = Cesium.Rectangle.center(rect);
return {
lat: Cesium.Math.toDegrees(center.latitude),
lon: Cesium.Math.toDegrees(center.longitude),
};
}
const carto = viewer?.camera?.positionCartographic;
if (carto) {
return {
lat: Cesium.Math.toDegrees(carto.latitude),
lon: Cesium.Math.toDegrees(carto.longitude),
};
const center = rectangleCenter({
west: toRadians(rect.west),
south: toRadians(rect.south),
east: toRadians(rect.east),
north: toRadians(rect.north),
});
return { lat: toDegrees(center.lat), lon: toDegrees(center.lon) };
}
const pose = camera?.pose();
if (pose && Number.isFinite(pose.lat) && Number.isFinite(pose.lon))
return { lat: pose.lat, lon: pose.lon };
return null;
}
@@ -53,18 +53,8 @@ export function createViewport({ state, services, parts }) {
* animating. Cheap, and only on a settled camera — never per frame.
*/
function refreshViewBounds() {
const viewer = state._viewer;
const rect = viewer?.camera?.computeViewRectangle?.(
viewer.scene.globe?.ellipsoid,
);
state._viewBounds = rect
? inflateViewBounds({
south: Cesium.Math.toDegrees(rect.south),
north: Cesium.Math.toDegrees(rect.north),
west: Cesium.Math.toDegrees(rect.west),
east: Cesium.Math.toDegrees(rect.east),
})
: null;
const rect = findCamera(state._viewer)?.viewRectangle();
state._viewBounds = rect ? inflateViewBounds(rect) : null;
// The sweep itself is deferred: `marker.show` is a dirty flag, and a drag
// fires this on every frame, so re-deciding visibility inline would put the
// whole fleet back into the vertex buffer once a frame — the exact cost