mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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:
1 parent
56d56a4d6d
commit
af449184ca
5 files changed
+64
-31
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import { destroyTrack } from '../../data/contactPlayback.js';
|
||||
import * as Cesium from 'cesium';
|
||||
// The Cesium camera factory: given a viewer of a caller's own, with no
|
||||
// renderer bound, the layer's camera reads find a camera port.
|
||||
import '../../render/cesium/camera.js';
|
||||
import {
|
||||
claimCameraSensitivity,
|
||||
releaseCameraSensitivity,
|
||||
|
||||
@@ -306,6 +306,34 @@ function harness(
|
||||
},
|
||||
});
|
||||
|
||||
// The layer reads the camera through its port; this one reads the fake
|
||||
// camera above as the Cesium port reads a real one, so a test can still
|
||||
// move it by changing the fake.
|
||||
const unbindCamera = bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose() {
|
||||
const carto = viewer.camera.positionCartographic;
|
||||
return {
|
||||
lon: carto ? Cesium.Math.toDegrees(carto.longitude) : NaN,
|
||||
lat: carto ? Cesium.Math.toDegrees(carto.latitude) : NaN,
|
||||
height: carto ? carto.height : NaN,
|
||||
};
|
||||
},
|
||||
viewRectangle() {
|
||||
const rect = viewer.camera.computeViewRectangle?.(
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
);
|
||||
if (!rect) return null;
|
||||
const deg = Cesium.Math.toDegrees;
|
||||
return {
|
||||
west: deg(rect.west),
|
||||
south: deg(rect.south),
|
||||
east: deg(rect.east),
|
||||
north: deg(rect.north),
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
installRenderGovernor(framePortFor(viewer.scene));
|
||||
layer.init(viewer);
|
||||
|
||||
@@ -316,6 +344,7 @@ function harness(
|
||||
/* a test may already have destroyed it */
|
||||
}
|
||||
uninstallRenderGovernor(framePortFor(viewer.scene));
|
||||
unbindCamera();
|
||||
_resetRenderGovernorForTest();
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -151,7 +151,6 @@
|
||||
"src/layers/transit/lifecycle.js",
|
||||
"src/layers/transit/rendering.js",
|
||||
"src/layers/transit/testing.js",
|
||||
"src/layers/transit/viewport.js",
|
||||
"src/layers/vessels/cameraArea.js",
|
||||
"src/layers/vessels/evidence.js",
|
||||
"src/layers/vessels/queries.js",
|
||||
|
||||
Reference in new issue
Block a user