mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
fix(cctv): keep the Context camera card's still and tidy the visibility port
The still preview gate looked only at the CCTV panel, so the Context camera card, which reads the same frame, stopped updating while the panel was collapsed or another phone sheet was open. A mounted card now counts itself in the CCTV store, and the still is requested while the panel or a card is shown; live video still follows the panel only. Review follow-ups in the same area: - visiblePoints is registered once, in createCesiumPorts, and drops checks for input that cannot happen; the contract documents horizonMarginM and when it answers false or null. - The layer passes the mount and the four corners once each and asks findCamera for the port. - Phone sheet names come from a shared module instead of literals. - Layer tests cover the fetch gate; the geometry cases moved to the camera port tests. Comments and CURRENT-STATE match the code.
This commit is contained in:
1 parent
b020a1cd91
commit
99a70a0e0c
18 files changed
+545
-430
No files matched your search
@@ -42,7 +42,9 @@ export function fitToProjection(sourceW, sourceH) {
|
||||
};
|
||||
}
|
||||
|
||||
const PLANE_POINTS = ['mount', 'tl', 'tr', 'br', 'bl'];
|
||||
const _scratchPoints = [];
|
||||
// Keep the occluding surface below common negative geoid undulations.
|
||||
const HORIZON_MARGIN_M = 200;
|
||||
|
||||
export function createFrames({ state: layerState, services, parts, source }) {
|
||||
@@ -241,33 +243,18 @@ export function createFrames({ state: layerState, services, parts, source }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a camera's monitor plane can be on screen: the mount, the far cap
|
||||
* and its corners are bounded by one sphere that is tested against the view
|
||||
* frustum, and at least one of those points must be above a conservative
|
||||
* horizon computed from a shrunken reference ellipsoid.
|
||||
* Anything this cannot judge (no viewer, a 2D or Columbus scene, no geometry
|
||||
* yet) counts as visible, so a missing input never blocks a picture.
|
||||
* Whether a camera's monitor plane may be on screen; what cannot be judged counts as visible.
|
||||
* @param {Object} record - Camera record.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
function projectionInView(record) {
|
||||
const viewer = layerState._viewer;
|
||||
if (!viewer || viewer.isDestroyed?.()) return true;
|
||||
const camera = findCamera(viewer);
|
||||
const camera = findCamera(layerState._viewer);
|
||||
if (typeof camera?.visiblePoints !== 'function') return true;
|
||||
const placed = record?.frustumPositions;
|
||||
const placed = record.frustumPositions;
|
||||
if (!placed) return true;
|
||||
const points = _scratchPoints;
|
||||
points.length = 0;
|
||||
if (record?.position) points.push(record.position);
|
||||
if (placed?.mount) points.push(placed.mount);
|
||||
if (placed?.capCenter) points.push(placed.capCenter);
|
||||
if (placed?.tl) points.push(placed.tl);
|
||||
if (placed?.tr) points.push(placed.tr);
|
||||
if (placed?.br) points.push(placed.br);
|
||||
if (placed?.bl) points.push(placed.bl);
|
||||
// Unknown modes or unsupported cameras must not suppress pictures.
|
||||
for (const key of PLANE_POINTS) points.push(placed[key]);
|
||||
return camera.visiblePoints(points, HORIZON_MARGIN_M) !== false;
|
||||
}
|
||||
|
||||
@@ -304,9 +291,7 @@ export function createFrames({ state: layerState, services, parts, source }) {
|
||||
// bypass a provider's explicit minimum between image requests.
|
||||
if (sourceRefreshMs > 0 && sinceLastRefresh < sourceRefreshMs) return;
|
||||
if (!force && sinceLastRefresh < refreshMs) return;
|
||||
// A plane nobody can see (panned away, far side of the globe) needs no new
|
||||
// picture; the next tick after it comes back fetches one. A forced refresh
|
||||
// (fresh activation, calibration) still runs.
|
||||
// Skip before stamping lastImageRefreshAt, so the first tick back in view fetches.
|
||||
if (!force && !projectionInView(record)) return;
|
||||
runtime.lastImageRefreshAt = now;
|
||||
|
||||
@@ -441,7 +426,6 @@ export function createFrames({ state: layerState, services, parts, source }) {
|
||||
mediaUrlFor,
|
||||
paintProjectionPlaceholder,
|
||||
refreshProjectionImage,
|
||||
projectionInView,
|
||||
paintPlaceholderThrottled,
|
||||
drawProjectionFrame,
|
||||
};
|
||||
|
||||
+44
-252
@@ -3,9 +3,7 @@
|
||||
// 1920x1080 projection canvas, instead of being stretched to fill it.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { createPointsVisibility } from '../../render/cesium/camera.js';
|
||||
import { createFrames, fitToProjection } from './frames.js';
|
||||
import {
|
||||
FRAME_SIGNATURE_W,
|
||||
@@ -143,31 +141,23 @@ test('same pixels at a new aspect redraw at the new fit', () => {
|
||||
assert.equal(runtime.canvasStamp, 2);
|
||||
});
|
||||
|
||||
// A camera's monitor plane is fetched only while it can be on screen. The
|
||||
// viewer is a Cesium camera description over the real WGS84 globe: it hovers
|
||||
// 30 km above a mount at (0, 0) and looks straight down, so the plane is in
|
||||
// front of it; turned around, or moved to the far side of the globe, the
|
||||
// plane is not.
|
||||
const MOUNT = Cesium.Cartesian3.fromDegrees(0, 0, 20);
|
||||
const point = (lon, lat, alt = 20) =>
|
||||
Cesium.Cartesian3.fromDegrees(lon, lat, alt);
|
||||
const MOUNT = { x: 0, y: 0, z: 0 };
|
||||
|
||||
function planeRecord() {
|
||||
const image = {};
|
||||
return {
|
||||
camera: { id: 'plane' },
|
||||
billboard: { position: MOUNT },
|
||||
position: MOUNT,
|
||||
frustumPositions: {
|
||||
mount: MOUNT,
|
||||
capCenter: point(0.0005, 0, 20),
|
||||
tl: point(0.0004, 0.0001),
|
||||
tr: point(0.0006, 0.0001),
|
||||
br: point(0.0006, -0.0001),
|
||||
bl: point(0.0004, -0.0001),
|
||||
capCenter: { x: 1, y: 0, z: 0 },
|
||||
tl: { x: 1, y: -1, z: 1 },
|
||||
tr: { x: 1, y: 1, z: 1 },
|
||||
br: { x: 1, y: 1, z: -1 },
|
||||
bl: { x: 1, y: -1, z: -1 },
|
||||
},
|
||||
projection: {
|
||||
mode: 'image',
|
||||
image,
|
||||
image: {},
|
||||
imageLoading: false,
|
||||
imageReady: false,
|
||||
lastImageRefreshAt: 0,
|
||||
@@ -175,42 +165,6 @@ function planeRecord() {
|
||||
};
|
||||
}
|
||||
|
||||
function viewerAt(position, direction, up) {
|
||||
const viewer = {
|
||||
isDestroyed: () => false,
|
||||
scene: { mode: Cesium.SceneMode.SCENE3D },
|
||||
camera: {
|
||||
positionWC: position,
|
||||
directionWC: direction,
|
||||
upWC: up,
|
||||
frustum: new Cesium.PerspectiveFrustum({
|
||||
fov: Cesium.Math.toRadians(60),
|
||||
aspectRatio: 16 / 9,
|
||||
near: 1,
|
||||
// Cesium's default far plane, as the app uses: a smaller one rejects
|
||||
// the far-side mount before the horizon check is ever reached.
|
||||
far: 5e8,
|
||||
}),
|
||||
},
|
||||
};
|
||||
bindRenderer(viewer, {
|
||||
camera: {
|
||||
visiblePoints: createPointsVisibility(viewer.scene, viewer.camera),
|
||||
},
|
||||
});
|
||||
return viewer;
|
||||
}
|
||||
|
||||
// Above the mount, looking straight down at the ground.
|
||||
function lookingDown() {
|
||||
const position = point(0, 0, 30000);
|
||||
return viewerAt(
|
||||
position,
|
||||
Cesium.Cartesian3.negate(Cesium.Cartesian3.UNIT_X, new Cesium.Cartesian3()),
|
||||
Cesium.Cartesian3.UNIT_Z,
|
||||
);
|
||||
}
|
||||
|
||||
function framesFor(viewer) {
|
||||
const state = {
|
||||
_viewer: viewer,
|
||||
@@ -230,28 +184,33 @@ function framesFor(viewer) {
|
||||
});
|
||||
}
|
||||
|
||||
test('a plane in front of the camera fetches its picture', () => {
|
||||
const frames = framesFor(lookingDown());
|
||||
function framesWithCamera(t, camera) {
|
||||
const host = {};
|
||||
t.after(bindRenderer(host, { camera }));
|
||||
return framesFor(host);
|
||||
}
|
||||
|
||||
test('a plane the renderer may show fetches its picture', (t) => {
|
||||
const visiblePoints = t.mock.fn(() => true);
|
||||
const frames = framesWithCamera(t, { visiblePoints });
|
||||
const record = planeRecord();
|
||||
assert.equal(frames.projectionInView(record), true);
|
||||
frames.refreshProjectionImage(record);
|
||||
assert.match(
|
||||
record.projection.image.src,
|
||||
/^\/api\/cctv\/frame\?id=plane&projTs=/,
|
||||
);
|
||||
assert.equal(record.projection.imageLoading, true);
|
||||
assert.equal(visiblePoints.mock.callCount(), 1);
|
||||
const [points, margin] = visiblePoints.mock.calls[0].arguments;
|
||||
const { mount, tl, tr, br, bl } = record.frustumPositions;
|
||||
assert.deepEqual(points, [mount, tl, tr, br, bl]);
|
||||
assert.equal(points[0], mount);
|
||||
assert.equal(margin, 200);
|
||||
});
|
||||
|
||||
test('a plane behind the camera is not fetched, but a forced refresh is', () => {
|
||||
const down = lookingDown();
|
||||
const away = viewerAt(
|
||||
down.camera.positionWC,
|
||||
Cesium.Cartesian3.UNIT_X,
|
||||
Cesium.Cartesian3.UNIT_Z,
|
||||
);
|
||||
const frames = framesFor(away);
|
||||
test('a plane the renderer cannot show is not fetched, but a forced refresh is', (t) => {
|
||||
const frames = framesWithCamera(t, { visiblePoints: () => false });
|
||||
const record = planeRecord();
|
||||
assert.equal(frames.projectionInView(record), false);
|
||||
frames.refreshProjectionImage(record);
|
||||
assert.equal(record.projection.image.src, undefined);
|
||||
assert.equal(record.projection.lastImageRefreshAt, 0);
|
||||
@@ -259,199 +218,32 @@ test('a plane behind the camera is not fetched, but a forced refresh is', () =>
|
||||
assert.match(record.projection.image.src, /projTs=/);
|
||||
});
|
||||
|
||||
test('a nearby plane below the ellipsoid still fetches for a low viewer', () => {
|
||||
test('a skipped refresh does not use up the interval', (t) => {
|
||||
let visible = false;
|
||||
const frames = framesWithCamera(t, { visiblePoints: () => visible });
|
||||
const record = planeRecord();
|
||||
const mount = point(0, 0, -18);
|
||||
const cap = point(0.00054, 0, -18);
|
||||
const position = point(0.00135, 0, 4);
|
||||
record.billboard.position = mount;
|
||||
record.frustumPositions = { mount, capCenter: cap };
|
||||
const direction = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(cap, position, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
|
||||
const sphere = Cesium.BoundingSphere.fromPoints([mount, cap]);
|
||||
const culling = viewer.camera.frustum.computeCullingVolume(
|
||||
position,
|
||||
direction,
|
||||
viewer.camera.upWC,
|
||||
);
|
||||
assert.notEqual(culling.computeVisibility(sphere), Cesium.Intersect.OUTSIDE);
|
||||
const frames = framesFor(viewer);
|
||||
assert.equal(frames.projectionInView(record), true);
|
||||
frames.refreshProjectionImage(record);
|
||||
assert.match(record.projection.image.src, /projTs=/);
|
||||
|
||||
// The same below-ellipsoid plane remains visible from a higher viewer.
|
||||
const high = point(0.00135, 0, 1200);
|
||||
const highDirection = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(cap, high, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
assert.equal(
|
||||
framesFor(
|
||||
viewerAt(high, highDirection, Cesium.Cartesian3.UNIT_Z),
|
||||
).projectionInView(record),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('the horizon still rejects a negative-height plane on the far side', () => {
|
||||
for (const altitude of [4, 30000, 2e7]) {
|
||||
const record = planeRecord();
|
||||
const mount = point(0, 0, -18);
|
||||
const cap = point(0.00054, 0, -18);
|
||||
record.billboard.position = mount;
|
||||
record.frustumPositions = { mount, capCenter: cap };
|
||||
const position = point(180, 0, altitude);
|
||||
const direction = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(mount, position, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
|
||||
const sphere = Cesium.BoundingSphere.fromPoints([mount, cap]);
|
||||
assert.notEqual(
|
||||
viewer.camera.frustum
|
||||
.computeCullingVolume(position, direction, viewer.camera.upWC)
|
||||
.computeVisibility(sphere),
|
||||
Cesium.Intersect.OUTSIDE,
|
||||
);
|
||||
assert.equal(framesFor(viewer).projectionInView(record), false);
|
||||
}
|
||||
});
|
||||
|
||||
test('a low viewer can see a plane beyond the WGS84 horizon', () => {
|
||||
const record = planeRecord();
|
||||
const mount = point(0, 0, 1);
|
||||
record.billboard.position = mount;
|
||||
record.frustumPositions = { mount };
|
||||
const position = point(0.2, 0, 4);
|
||||
const direction = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(mount, position, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const viewer = viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z);
|
||||
assert.equal(framesFor(viewer).projectionInView(record), true);
|
||||
});
|
||||
|
||||
test('a plane below the horizon is not fetched', () => {
|
||||
const far = point(180, 0, 30000);
|
||||
const viewer = viewerAt(
|
||||
far,
|
||||
Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(MOUNT, far, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
Cesium.Cartesian3.UNIT_Z,
|
||||
);
|
||||
const frames = framesFor(viewer);
|
||||
assert.equal(frames.projectionInView(planeRecord()), false);
|
||||
});
|
||||
|
||||
test('a skipped refresh does not use up the interval: the plane fetches once it is back in view', () => {
|
||||
const record = planeRecord();
|
||||
const frames = framesFor(lookingDown());
|
||||
const away = viewerAt(
|
||||
lookingDown().camera.positionWC,
|
||||
Cesium.Cartesian3.UNIT_X,
|
||||
Cesium.Cartesian3.UNIT_Z,
|
||||
);
|
||||
const awayFrames = framesFor(away);
|
||||
awayFrames.refreshProjectionImage(record);
|
||||
assert.equal(record.projection.image.src, undefined);
|
||||
visible = true;
|
||||
frames.refreshProjectionImage(record);
|
||||
assert.match(record.projection.image.src, /projTs=/);
|
||||
});
|
||||
|
||||
test('the renderer scene host culls the far side without raw viewer access', () => {
|
||||
const native = lookingDown();
|
||||
const viewer = { isDestroyed: () => false };
|
||||
const camera = native.camera;
|
||||
camera.directionWC = Cesium.Cartesian3.UNIT_X;
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera: { visiblePoints: createPointsVisibility(native.scene, camera) },
|
||||
});
|
||||
try {
|
||||
assert.equal(framesFor(viewer).projectionInView(planeRecord()), false);
|
||||
} finally {
|
||||
unbind();
|
||||
test('what cannot be judged counts as visible', (t) => {
|
||||
for (const frames of [
|
||||
framesWithCamera(t, { visiblePoints: () => null }),
|
||||
framesWithCamera(t, { pose: () => ({}) }),
|
||||
framesFor(null),
|
||||
]) {
|
||||
const record = planeRecord();
|
||||
frames.refreshProjectionImage(record);
|
||||
assert.match(record.projection.image.src, /projTs=/);
|
||||
}
|
||||
});
|
||||
|
||||
test('visibility checks reuse the points array across ticks', () => {
|
||||
const seen = [];
|
||||
const host = {};
|
||||
const unbind = bindRenderer(host, {
|
||||
camera: {
|
||||
visiblePoints: (points) => {
|
||||
seen.push(points);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
try {
|
||||
const frames = framesFor(host);
|
||||
frames.projectionInView(planeRecord());
|
||||
frames.projectionInView(planeRecord());
|
||||
assert.equal(seen.length, 2);
|
||||
assert.strictEqual(seen[0], seen[1]);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('deep viewers do not lose nearby planes to the horizon test', () => {
|
||||
const mount = point(0, 0, -350);
|
||||
const position = point(0.00135, 0, -300);
|
||||
const direction = Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(mount, position, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const record = planeRecord();
|
||||
record.frustumPositions = { mount };
|
||||
record.position = mount;
|
||||
assert.equal(
|
||||
framesFor(
|
||||
viewerAt(position, direction, Cesium.Cartesian3.UNIT_Z),
|
||||
).projectionInView(record),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('flat and unknown projections fail open', () => {
|
||||
const native = lookingDown();
|
||||
native.camera.directionWC = Cesium.Cartesian3.UNIT_X;
|
||||
native.scene.mode = Cesium.SceneMode.COLUMBUS_VIEW;
|
||||
assert.equal(framesFor(native).projectionInView(planeRecord()), true);
|
||||
native.scene.mode = Cesium.SceneMode.SCENE3D;
|
||||
native.camera.directionWC = undefined;
|
||||
assert.equal(framesFor(native).projectionInView(planeRecord()), true);
|
||||
const host = {};
|
||||
const unbind = bindRenderer(host, { camera: { pose: () => ({}) } });
|
||||
try {
|
||||
assert.equal(framesFor(host).projectionInView(planeRecord()), true);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('what cannot be judged counts as visible', () => {
|
||||
const record = planeRecord();
|
||||
assert.equal(framesFor(null).projectionInView(record), true);
|
||||
assert.equal(
|
||||
framesFor({ ...lookingDown(), isDestroyed: () => true }).projectionInView(
|
||||
record,
|
||||
),
|
||||
true,
|
||||
);
|
||||
const flat = lookingDown();
|
||||
flat.scene.mode = Cesium.SceneMode.SCENE2D;
|
||||
assert.equal(framesFor(flat).projectionInView(record), true);
|
||||
const noGeometry = {
|
||||
camera: { id: 'plane' },
|
||||
projection: record.projection,
|
||||
position: point(180, 0, 20),
|
||||
};
|
||||
assert.equal(framesFor(lookingDown()).projectionInView(noGeometry), true);
|
||||
const noGeometry = planeRecord();
|
||||
delete noGeometry.frustumPositions;
|
||||
const visiblePoints = t.mock.fn(() => false);
|
||||
framesWithCamera(t, { visiblePoints }).refreshProjectionImage(noGeometry);
|
||||
assert.equal(visiblePoints.mock.callCount(), 0);
|
||||
assert.match(noGeometry.projection.image.src, /projTs=/);
|
||||
});
|
||||
+12
-41
@@ -86,6 +86,9 @@ function sameMatrix(array, matrix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const finiteVector = (v) =>
|
||||
!!v && Number.isFinite(v.x) && Number.isFinite(v.y) && Number.isFinite(v.z);
|
||||
|
||||
/** Conservative globe/frustum visibility; null means unknown. */
|
||||
export function createPointsVisibility(scene, camera) {
|
||||
const visibilitySphere = new Cesium.BoundingSphere();
|
||||
@@ -93,47 +96,20 @@ export function createPointsVisibility(scene, camera) {
|
||||
let visibilityEllipsoid = null;
|
||||
let visibilityOccluder = null;
|
||||
return function visiblePoints(points, marginM) {
|
||||
if (
|
||||
scene.mode !== Cesium.SceneMode.SCENE3D ||
|
||||
!points?.length ||
|
||||
!Number.isFinite(marginM) ||
|
||||
marginM < 0 ||
|
||||
typeof camera.frustum?.computeCullingVolume !== 'function'
|
||||
)
|
||||
return null;
|
||||
const radii = Cesium.Ellipsoid.WGS84.radii;
|
||||
if (marginM >= Math.min(radii.x, radii.y, radii.z)) return null;
|
||||
const eye = camera.positionWC;
|
||||
if (
|
||||
!eye ||
|
||||
!Number.isFinite(eye.x) ||
|
||||
!Number.isFinite(eye.y) ||
|
||||
!Number.isFinite(eye.z)
|
||||
)
|
||||
return null;
|
||||
const direction = camera.directionWC;
|
||||
const up = camera.upWC;
|
||||
if (
|
||||
!direction ||
|
||||
!up ||
|
||||
!Number.isFinite(direction.x) ||
|
||||
!Number.isFinite(direction.y) ||
|
||||
!Number.isFinite(direction.z) ||
|
||||
!Number.isFinite(up.x) ||
|
||||
!Number.isFinite(up.y) ||
|
||||
!Number.isFinite(up.z)
|
||||
scene.mode !== Cesium.SceneMode.SCENE3D ||
|
||||
!points?.length ||
|
||||
!finiteVector(eye) ||
|
||||
!finiteVector(direction) ||
|
||||
!finiteVector(up) ||
|
||||
!points.every(finiteVector)
|
||||
)
|
||||
return null;
|
||||
for (const p of points) {
|
||||
if (
|
||||
!p ||
|
||||
!Number.isFinite(p.x) ||
|
||||
!Number.isFinite(p.y) ||
|
||||
!Number.isFinite(p.z)
|
||||
)
|
||||
return null;
|
||||
}
|
||||
if (visibilityMargin !== marginM) {
|
||||
const radii = Cesium.Ellipsoid.WGS84.radii;
|
||||
visibilityMargin = marginM;
|
||||
visibilityEllipsoid = new Cesium.Ellipsoid(
|
||||
radii.x - marginM,
|
||||
@@ -143,6 +119,7 @@ export function createPointsVisibility(scene, camera) {
|
||||
visibilityOccluder = new Cesium.EllipsoidalOccluder(visibilityEllipsoid);
|
||||
}
|
||||
const inverse = visibilityEllipsoid.oneOverRadii;
|
||||
// Inside the ellipsoid Cesium's occluder hides nearby points; judge by the frustum alone.
|
||||
const outside =
|
||||
Math.hypot(eye.x * inverse.x, eye.y * inverse.y, eye.z * inverse.z) >= 1;
|
||||
if (outside) {
|
||||
@@ -156,11 +133,7 @@ export function createPointsVisibility(scene, camera) {
|
||||
}
|
||||
if (!visible) return false;
|
||||
}
|
||||
const culling = camera.frustum.computeCullingVolume(
|
||||
eye,
|
||||
camera.directionWC,
|
||||
camera.upWC,
|
||||
);
|
||||
const culling = camera.frustum.computeCullingVolume(eye, direction, up);
|
||||
return (
|
||||
culling.computeVisibility(
|
||||
Cesium.BoundingSphere.fromPoints(points, visibilitySphere),
|
||||
@@ -752,8 +725,6 @@ export function createCesiumCamera({
|
||||
});
|
||||
// Cesium keeps the eye in `camera.transform`: a tracked entity's frame, a
|
||||
// `lookAt` target's, or the identity.
|
||||
if (!capabilities || capabilities.has('pointVisibility'))
|
||||
cameraPort.visiblePoints = createPointsVisibility(scene, camera);
|
||||
if (!capabilities || capabilities.has('followFrame'))
|
||||
cameraPort.followFrame = () => {
|
||||
if (!lastFollowFrame || !sameMatrix(lastFollowFrame, camera.transform))
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
headlessCamera,
|
||||
withVirtualClock,
|
||||
} from './cameraGoldens.js';
|
||||
import { createCesiumCamera } from './camera.js';
|
||||
import { createCesiumCamera, createPointsVisibility } from './camera.js';
|
||||
import { createCesiumPorts } from './ports.js';
|
||||
import { bindRenderer, cameraOf } from '../rendererOf.js';
|
||||
|
||||
@@ -337,11 +337,20 @@ test('the camera port gives the clock its own tick back as it goes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('camera visibility is unknown outside 3D and resolves on the globe', () => {
|
||||
const { scene, camera } = headlessCamera();
|
||||
scene.postUpdate = new Cesium.Event();
|
||||
test('visiblePoints is there only with its capability, and unknown outside 3D', (t) => {
|
||||
const { scene } = headlessCamera();
|
||||
for (const name of ['preUpdate', 'postUpdate', 'preRender', 'postRender'])
|
||||
scene[name] = new Cesium.Event();
|
||||
scene.primitives = { add() {}, remove() {} };
|
||||
scene.requestRender = () => {};
|
||||
const { port } = createCesiumCamera({ scene, camera, report: () => {} });
|
||||
const viewer = { scene, clock: { currentTime: Cesium.JulianDate.now() } };
|
||||
const without = createCesiumPorts(viewer, { capabilities: new Set() });
|
||||
assert.equal(without.camera.visiblePoints, undefined);
|
||||
without.dispose();
|
||||
const ports = createCesiumPorts(viewer, {
|
||||
capabilities: new Set(['pointVisibility']),
|
||||
});
|
||||
t.after(() => ports.dispose());
|
||||
const points = [Cesium.Cartesian3.fromDegrees(0, 0, 10)];
|
||||
for (const mode of [
|
||||
Cesium.SceneMode.SCENE2D,
|
||||
@@ -350,10 +359,123 @@ test('camera visibility is unknown outside 3D and resolves on the globe', () =>
|
||||
undefined,
|
||||
]) {
|
||||
scene.mode = mode;
|
||||
assert.equal(port.visiblePoints(points, 200), null);
|
||||
assert.equal(ports.camera.visiblePoints(points, 200), null);
|
||||
}
|
||||
scene.mode = Cesium.SceneMode.SCENE3D;
|
||||
assert.equal(typeof port.visiblePoints(points, 200), 'boolean');
|
||||
assert.equal(typeof ports.camera.visiblePoints(points, 200), 'boolean');
|
||||
});
|
||||
|
||||
const point = (lon, lat, altitude = 20) =>
|
||||
Cesium.Cartesian3.fromDegrees(lon, lat, altitude);
|
||||
const down = Cesium.Cartesian3.negate(
|
||||
Cesium.Cartesian3.UNIT_X,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const up = Cesium.Cartesian3.UNIT_Z;
|
||||
const frustum = new Cesium.PerspectiveFrustum({
|
||||
fov: Cesium.Math.toRadians(60),
|
||||
aspectRatio: 16 / 9,
|
||||
near: 1,
|
||||
// Cesium's default far plane, as the app uses.
|
||||
far: 5e8,
|
||||
});
|
||||
|
||||
function visibility(position, direction, up) {
|
||||
const visiblePoints = createPointsVisibility(
|
||||
{ mode: Cesium.SceneMode.SCENE3D },
|
||||
{ positionWC: position, directionWC: direction, upWC: up, frustum },
|
||||
);
|
||||
return (points) => visiblePoints(points, 200);
|
||||
}
|
||||
|
||||
function directionTo(position, target) {
|
||||
return Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.subtract(target, position, new Cesium.Cartesian3()),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
}
|
||||
|
||||
function assertInFrustum(points, position, direction) {
|
||||
const culling = frustum.computeCullingVolume(position, direction, up);
|
||||
assert.notEqual(
|
||||
culling.computeVisibility(Cesium.BoundingSphere.fromPoints(points)),
|
||||
Cesium.Intersect.OUTSIDE,
|
||||
);
|
||||
}
|
||||
|
||||
test('a plane in front of the camera is visible', () => {
|
||||
assert.equal(visibility(point(0, 0, 30000), down, up)([point(0, 0)]), true);
|
||||
});
|
||||
|
||||
test('a plane behind the camera is outside the frustum', () => {
|
||||
assert.equal(
|
||||
visibility(point(0, 0, 30000), Cesium.Cartesian3.UNIT_X, up)([point(0, 0)]),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('a corner can be in view when the mount and centre are outside', () => {
|
||||
const visible = visibility(point(0, 0, 30000), down, up);
|
||||
const mount = point(0.3, 0);
|
||||
const points = [
|
||||
mount,
|
||||
point(0.1, 0.0001),
|
||||
point(0.3, 0.0001),
|
||||
point(0.3, -0.0001),
|
||||
point(0.1, -0.0001),
|
||||
];
|
||||
assert.equal(visible(points), true);
|
||||
assert.equal(visible([mount]), false);
|
||||
assert.equal(visible([point(0.2, 0)]), false);
|
||||
});
|
||||
|
||||
test('a nearby plane below the ellipsoid is visible to low and high viewers', () => {
|
||||
const cap = point(0.00054, 0, -18);
|
||||
const points = [point(0, 0, -18), cap];
|
||||
for (const altitude of [4, 1200]) {
|
||||
const position = point(0.00135, 0, altitude);
|
||||
const direction = directionTo(position, cap);
|
||||
assertInFrustum(points, position, direction);
|
||||
assert.equal(visibility(position, direction, up)(points), true);
|
||||
}
|
||||
});
|
||||
|
||||
test('the horizon rejects a negative-height plane on the far side', () => {
|
||||
const mount = point(0, 0, -18);
|
||||
const points = [mount, point(0.00054, 0, -18)];
|
||||
for (const altitude of [4, 30000, 2e7]) {
|
||||
const position = point(180, 0, altitude);
|
||||
const direction = directionTo(position, mount);
|
||||
assertInFrustum(points, position, direction);
|
||||
assert.equal(visibility(position, direction, up)(points), false);
|
||||
}
|
||||
});
|
||||
|
||||
test('a low viewer can see a plane beyond the WGS84 horizon', () => {
|
||||
const mount = point(0, 0, 1);
|
||||
const position = point(0.2, 0, 4);
|
||||
assert.equal(
|
||||
visibility(position, directionTo(position, mount), up)([mount]),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('deep viewers do not lose nearby planes to the horizon test', () => {
|
||||
const mount = point(0, 0, -350);
|
||||
const position = point(0.00135, 0, -300);
|
||||
assert.equal(
|
||||
visibility(position, directionTo(position, mount), up)([mount]),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('a non-finite camera direction leaves visibility unknown', () => {
|
||||
const visible = visibility(
|
||||
point(0, 0, 30000),
|
||||
new Cesium.Cartesian3(NaN, 0, 0),
|
||||
up,
|
||||
);
|
||||
assert.equal(visible([point(0, 0)]), null);
|
||||
});
|
||||
|
||||
test('setFov holds the vertical angle across resizes, and waits for a first one', () => {
|
||||
|
||||
@@ -485,7 +485,7 @@ export function createCesiumPorts(
|
||||
: {}),
|
||||
});
|
||||
const cameraPort = cameraPart.port;
|
||||
if (controlled && capabilities.has('pointVisibility'))
|
||||
if (capabilities.has('pointVisibility'))
|
||||
cameraPort.visiblePoints = createPointsVisibility(scene, camera);
|
||||
measureCameraChanged = cameraPart.measureChanged ?? null;
|
||||
const effectsPart = createCesiumEffects(scene, {
|
||||
|
||||
Vendored
+8
-1
@@ -234,7 +234,14 @@ export type CameraEvent =
|
||||
'changed' | 'moveStart' | 'moveEnd' | 'followChanged' | 'flightEnd';
|
||||
|
||||
export interface CameraPort {
|
||||
/** Conservative visibility of an ECEF point set, with a horizon margin in metres; null means unknown. */
|
||||
/**
|
||||
* Whether any of the ECEF points may be on screen: false only when their
|
||||
* bounding sphere is outside the view or all of them are below the horizon
|
||||
* of WGS84 shrunk by `horizonMarginM` metres; null when it cannot tell
|
||||
* (not a 3D scene, an empty point set, or a non-finite point or camera
|
||||
* vector), which callers treat as visible. Supply a finite, nonnegative
|
||||
* margin smaller than the shortest WGS84 radius.
|
||||
*/
|
||||
visiblePoints?(points: Ecef[], horizonMarginM: number): boolean | null;
|
||||
pose(): CameraPose;
|
||||
/**
|
||||
|
||||
+11
-5
@@ -1,3 +1,5 @@
|
||||
import { watch } from 'vue';
|
||||
import { MOBILE_SHEET_ATTR } from './mobileSheets.js';
|
||||
import {
|
||||
EMPTY_CCTV_FRAME,
|
||||
_clearCctvFrame,
|
||||
@@ -86,11 +88,14 @@ export class CctvControls {
|
||||
attributeFilter: ['class', 'hidden'],
|
||||
});
|
||||
// On phones the panel is on screen only while the Cameras sheet is open.
|
||||
if (typeof document !== 'undefined' && document.body)
|
||||
this._videoVisibilityObserver.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class', 'data-mobile-sheet'],
|
||||
});
|
||||
this._videoVisibilityObserver.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class', MOBILE_SHEET_ATTR],
|
||||
});
|
||||
this._offPreviewCards = watch(
|
||||
() => this.store.previewCards,
|
||||
() => this._renderCctvState(this._cctvState),
|
||||
);
|
||||
this.listen(document, 'visibilitychange', () =>
|
||||
this._renderCctvState(this._cctvState),
|
||||
);
|
||||
@@ -163,6 +168,7 @@ export class CctvControls {
|
||||
this._quebecCctvOverlay?.dispose();
|
||||
this._cctvVideoSurface?.stop();
|
||||
this._videoVisibilityObserver?.disconnect();
|
||||
this._offPreviewCards?.();
|
||||
this._actionGeneration++;
|
||||
this.listeners.abort();
|
||||
this._cctvUnsubscribe?.();
|
||||
|
||||
+68
-44
@@ -20,7 +20,7 @@ const BUTTONS = {
|
||||
_cctvProjectionBtn: 'cctv-projection-btn',
|
||||
};
|
||||
|
||||
function panel(t) {
|
||||
function panel(t, { video = false } = {}) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
@@ -32,6 +32,7 @@ function panel(t) {
|
||||
document.getElementById(id),
|
||||
]),
|
||||
);
|
||||
if (video) elements._cctvVideo = document.getElementById('cctv-video');
|
||||
const controls = new CctvControls({
|
||||
elements: {
|
||||
...elements,
|
||||
@@ -377,16 +378,7 @@ test('a second edit of the same chip gets a fresh input', async (t) => {
|
||||
});
|
||||
|
||||
test('the frame preview renders each step of a camera frame request', async (t) => {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
const requests = mockImages(t);
|
||||
const { controls, byId } = panel(t);
|
||||
// The preview loads while the panel is open; the panel starts collapsed.
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
@@ -610,15 +602,7 @@ test('the meta line of a disabled layer does not describe its last camera', () =
|
||||
});
|
||||
|
||||
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||
const stillState = (frameUrl) => ({
|
||||
enabled: true,
|
||||
count: 1,
|
||||
cameraIndex: [camera],
|
||||
activeCameraId: 'a',
|
||||
activeCamera: { ...camera, frameUrl, sourceKind: 'snapshot' },
|
||||
});
|
||||
|
||||
test('the still preview is fetched only while the tab and the panel are shown', async (t) => {
|
||||
function mockImages(t) {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
@@ -626,6 +610,22 @@ test('the still preview is fetched only while the tab and the panel are shown',
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
return requests;
|
||||
}
|
||||
|
||||
const stillState = (frameUrl, id = 'a') => ({
|
||||
enabled: true,
|
||||
count: 2,
|
||||
cameraIndex: [camera, { ...camera, id: 'b' }],
|
||||
activeCameraId: id,
|
||||
activeCamera: { ...camera, id, frameUrl, sourceKind: 'snapshot' },
|
||||
});
|
||||
|
||||
test('the still preview is fetched only while the tab and the panel are shown', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const hidden = Object.getOwnPropertyDescriptor(document, 'hidden');
|
||||
let tabHidden = false;
|
||||
Object.defineProperty(document, 'hidden', {
|
||||
@@ -633,11 +633,11 @@ test('the still preview is fetched only while the tab and the panel are shown',
|
||||
get: () => tabHidden,
|
||||
});
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
if (hidden) Object.defineProperty(document, 'hidden', hidden);
|
||||
else delete document.hidden;
|
||||
});
|
||||
const { controls, byId } = panel(t);
|
||||
assert.equal(controls._cctvVideo, undefined);
|
||||
const panelElement = byId('cctv-panel');
|
||||
const state = stillState;
|
||||
|
||||
@@ -668,15 +668,8 @@ test('the still preview is fetched only while the tab and the panel are shown',
|
||||
});
|
||||
|
||||
test('the still preview waits for the Cameras sheet on phones', async (t) => {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
@@ -704,22 +697,53 @@ test('the still preview waits for the Cameras sheet on phones', async (t) => {
|
||||
assert.equal(requests.length, 2, 'desktop ignores the sheet');
|
||||
});
|
||||
|
||||
test('a still-only panel (no video element) resumes from the class change', async (t) => {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
test('a camera picked while the panel is collapsed shows its own still on expanding', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, byId } = panel(t);
|
||||
assert.equal(controls._cctvVideo, undefined);
|
||||
const panelElement = byId('cctv-panel');
|
||||
panelElement.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 0);
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
await settle();
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
panelElement.classList.add('collapsed');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('b1.jpg', 'b'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
panelElement.classList.remove('collapsed');
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'b1.jpg');
|
||||
assert.equal(byId('cctv-frame').dataset.cameraId, 'b');
|
||||
assert.notEqual(byId('cctv-frame').getAttribute('src'), 'a1.jpg');
|
||||
});
|
||||
|
||||
test('leaving the Cameras sheet stops the live video and coming back starts it again', async (t) => {
|
||||
const { controls, byId } = panel(t, { video: true });
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'cameras');
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
controls._renderCctvState({
|
||||
enabled: true,
|
||||
count: 1,
|
||||
cameraIndex: [camera],
|
||||
activeCameraId: 'a',
|
||||
activeCamera: { ...camera, isVideo: true },
|
||||
});
|
||||
const first = controls._cctvVideoSurface;
|
||||
assert.ok(first);
|
||||
const stop = t.mock.method(first, 'stop');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
await settle();
|
||||
assert.equal(stop.mock.callCount(), 1);
|
||||
assert.equal(controls._cctvVideoSurface, null);
|
||||
document.body.setAttribute('data-mobile-sheet', 'cameras');
|
||||
await settle();
|
||||
assert.ok(controls._cctvVideoSurface);
|
||||
assert.notEqual(controls._cctvVideoSurface, first);
|
||||
});
|
||||
+24
-13
@@ -4,6 +4,15 @@ import { cctvSourceLabelText, cctvSourceMessageText } from './cctvFrames.js';
|
||||
import { createCctvVideoSurface } from './cctvVideo.js';
|
||||
import { presentCctvCalibration } from './cctvCalibration.js';
|
||||
import { roundHeadingDegrees } from '../data/headingDegrees.js';
|
||||
import {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
sheetForPanelId,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
const CAMERAS_SHEET = sheetForPanelId('cctv-panel');
|
||||
const CONTEXT_SHEET = sheetForPanelId('global-context-panel');
|
||||
|
||||
export function _calBadgeLabel(badge) {
|
||||
switch (badge) {
|
||||
case 'calibrated':
|
||||
@@ -274,19 +283,21 @@ export function _renderCctvState(state) {
|
||||
const liveIntent =
|
||||
enabled && !!activeCamera?.isVideo && !activeCamera?.browserMediaUrl;
|
||||
this.store.setLive(liveIntent);
|
||||
// A background tab or a collapsed panel shows nothing, so neither plays the
|
||||
// video nor fetches the still; the observer and the visibilitychange listener
|
||||
// render again when the panel is shown.
|
||||
// On phones the panel also belongs to one sheet: the shell hides it unless
|
||||
// data-mobile-sheet is 'cameras'.
|
||||
const body = typeof document !== 'undefined' ? document.body : null;
|
||||
const sheetClosed =
|
||||
!!body?.classList?.contains('mobile-shell') &&
|
||||
body.getAttribute('data-mobile-sheet') !== 'cameras';
|
||||
// A background tab, a collapsed panel or a closed phone sheet shows no
|
||||
// picture; the observers and visibilitychange render again on showing.
|
||||
const body = globalThis.document?.body;
|
||||
const phone = body?.classList.contains(MOBILE_SHELL_CLASS);
|
||||
const sheet = body?.getAttribute(MOBILE_SHEET_ATTR);
|
||||
const tabShown = !!body && !document.hidden;
|
||||
const panelShown =
|
||||
!(typeof document !== 'undefined' && document.hidden) &&
|
||||
!this._cctvPanel?.classList?.contains('collapsed') &&
|
||||
!sheetClosed;
|
||||
tabShown &&
|
||||
!this._cctvPanel?.classList.contains('collapsed') &&
|
||||
(!phone || sheet === CAMERAS_SHEET);
|
||||
// Context's camera card shows the same still.
|
||||
const cardShown =
|
||||
tabShown &&
|
||||
this.store.previewCards > 0 &&
|
||||
(!phone || sheet === CONTEXT_SHEET);
|
||||
if (this._cctvVideo) {
|
||||
const visible = liveIntent && panelShown;
|
||||
if (!visible || this._cctvVideoCameraId !== activeId) {
|
||||
@@ -313,7 +324,7 @@ export function _renderCctvState(state) {
|
||||
// immediate so navigation never waits on the prior camera's request.
|
||||
if (
|
||||
nextSrc &&
|
||||
panelShown &&
|
||||
(panelShown || cardShown) &&
|
||||
(cameraChanged || (!frameLoading && this._frame.currentSrc !== nextSrc))
|
||||
) {
|
||||
this._queueCctvFrame(nextSrc, nextCameraId, cameraChanged);
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp, nextTick } from 'vue';
|
||||
import { CctvControls } from './cctvControls.js';
|
||||
import { useCctvStore } from './stores/cctv.js';
|
||||
import CctvPanel from './views/panels/CctvPanel.vue';
|
||||
import CctvPreview from './views/panels/CctvPreview.vue';
|
||||
|
||||
const settle = () => new Promise((r) => setTimeout(r, 0));
|
||||
const camera = {
|
||||
id: 'a',
|
||||
city: 'Austin',
|
||||
name: 'Congress Ave',
|
||||
headingDeg: 91.6,
|
||||
fovDeg: 60,
|
||||
rangeM: 120.4,
|
||||
sourceLabel: 'Configured Source',
|
||||
calBadge: 'curated',
|
||||
};
|
||||
const stillState = (frameUrl, id = 'a') => ({
|
||||
enabled: true,
|
||||
count: 2,
|
||||
cameraIndex: [camera, { ...camera, id: 'b' }],
|
||||
activeCameraId: id,
|
||||
activeCamera: { ...camera, id, frameUrl, sourceKind: 'snapshot' },
|
||||
});
|
||||
|
||||
function fixture(t, { card = true } = {}) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const cardHost = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
const app = createApp(CctvPanel).use(pinia);
|
||||
app.mount(host);
|
||||
let preview;
|
||||
function mountCard() {
|
||||
preview = createApp(CctvPreview, { cameraId: 'a' }).use(pinia);
|
||||
preview.mount(cardHost);
|
||||
}
|
||||
if (card) mountCard();
|
||||
const controls = new CctvControls({
|
||||
elements: {
|
||||
_cctvPanel: document.getElementById('cctv-panel'),
|
||||
_cctvFrame: document.getElementById('cctv-frame'),
|
||||
_cctvFrameWrap: document.getElementById('cctv-frame-wrap'),
|
||||
},
|
||||
cctv: {},
|
||||
actions: {
|
||||
isEnabled: () => true,
|
||||
setPanelCollapsed() {},
|
||||
syncViewport() {},
|
||||
},
|
||||
store: useCctvStore(pinia),
|
||||
});
|
||||
t.after(() => {
|
||||
controls.destroy();
|
||||
app.unmount();
|
||||
preview?.unmount();
|
||||
});
|
||||
return {
|
||||
controls,
|
||||
cardHost,
|
||||
mountCard,
|
||||
panelEl: document.getElementById('cctv-panel'),
|
||||
};
|
||||
}
|
||||
|
||||
function mockImages(t) {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
return requests;
|
||||
}
|
||||
|
||||
test('desktop: the Context card keeps refreshing while the accordion folds CCTV', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
panelEl.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(cardHost.querySelector('img')?.getAttribute('src'), 'a1.jpg');
|
||||
// Context opens: the desktop accordion folds CCTV (class collapsed).
|
||||
panelEl.classList.add('collapsed');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
requests[1].onload();
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
assert.equal(requests.length, 3);
|
||||
assert.equal(requests[2].src, 'a3.jpg');
|
||||
requests[2].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(cardHost.querySelector('img')?.getAttribute('src'), 'a3.jpg');
|
||||
});
|
||||
|
||||
test('phone: a camera picked with the Context sheet open gets its still', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'context');
|
||||
panelEl.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(
|
||||
requests.length >= 1,
|
||||
'the Context card on the Context sheet requests the still',
|
||||
);
|
||||
requests.at(-1).onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(
|
||||
cardHost.querySelector('.cctv-preview__expand'),
|
||||
'the card shows a frame, not Acquiring frame…',
|
||||
);
|
||||
});
|
||||
|
||||
test('phone: the card on a closed Context sheet waits', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 0);
|
||||
document.body.setAttribute('data-mobile-sheet', 'context');
|
||||
await settle();
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
|
||||
test('desktop: a card that mounts asks for the still', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl, mountCard } = fixture(t, { card: false });
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 0);
|
||||
mountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
export const MOBILE_SHELL_CLASS = 'mobile-shell';
|
||||
export const MOBILE_SHEET_ATTR = 'data-mobile-sheet';
|
||||
|
||||
/**
|
||||
* Panels each sheet expands. A sheet also shows its rail's other panels
|
||||
* collapsed (Scenes under Layers), per styles/mobile-shell.css.
|
||||
*/
|
||||
export const MOBILE_SHEET_PANELS = Object.freeze({
|
||||
layers: Object.freeze(['data-panel']),
|
||||
cameras: Object.freeze(['cctv-panel', 'street-level-panel']),
|
||||
context: Object.freeze(['global-context-panel']),
|
||||
search: Object.freeze(['location-bar']),
|
||||
more: Object.freeze(['control-panel', 'pp-toggles']),
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} panelId
|
||||
* @returns {string|null} The sheet that presents `panelId`.
|
||||
*/
|
||||
export function sheetForPanelId(panelId) {
|
||||
for (const [sheet, ids] of Object.entries(MOBILE_SHEET_PANELS)) {
|
||||
if (ids.includes(panelId)) return sheet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+13
-26
@@ -18,22 +18,20 @@ import {
|
||||
readPanelState,
|
||||
} from './rail/panelState.js';
|
||||
|
||||
import {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
MOBILE_SHEET_PANELS,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
export {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
MOBILE_SHEET_PANELS,
|
||||
sheetForPanelId,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
export const MOBILE_SHELL_MEDIA_QUERY = '(max-width: 720px)';
|
||||
export const MOBILE_SHELL_CLASS = 'mobile-shell';
|
||||
export const MOBILE_SHEET_ATTR = 'data-mobile-sheet';
|
||||
|
||||
/**
|
||||
* Panels each sheet expands. A sheet also shows its rail's other panels
|
||||
* collapsed (Scenes under Layers), per styles/mobile-shell.css.
|
||||
*/
|
||||
export const MOBILE_SHEET_PANELS = Object.freeze({
|
||||
layers: Object.freeze(['data-panel']),
|
||||
cameras: Object.freeze(['cctv-panel', 'street-level-panel']),
|
||||
context: Object.freeze(['global-context-panel']),
|
||||
search: Object.freeze(['location-bar']),
|
||||
more: Object.freeze(['control-panel', 'pp-toggles']),
|
||||
});
|
||||
|
||||
export const MOBILE_TABS = Object.freeze([
|
||||
Object.freeze({ sheet: 'layers', label: msg('Layers'), icon: 'layers' }),
|
||||
Object.freeze({ sheet: 'cameras', label: msg('Cameras'), icon: 'videocam' }),
|
||||
@@ -58,17 +56,6 @@ const BORROWED_PANELS = Object.freeze([
|
||||
|
||||
const BORROW_OPTIONS = Object.freeze({ persist: false, syncShare: false });
|
||||
|
||||
/**
|
||||
* @param {string} panelId
|
||||
* @returns {string|null} The sheet that presents `panelId`.
|
||||
*/
|
||||
export function sheetForPanelId(panelId) {
|
||||
for (const [sheet, ids] of Object.entries(MOBILE_SHEET_PANELS)) {
|
||||
if (ids.includes(panelId)) return sheet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sheet after a tab press: the same tab closes its sheet, another opens.
|
||||
* @param {string|null} current
|
||||
|
||||
@@ -20,6 +20,8 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
|
||||
/** The preview: requested and shown frame, loading and error state. */
|
||||
const frame = shallowRef(null);
|
||||
/** Number of camera cards outside the panel showing its preview, including Context's card. */
|
||||
const previewCards = shallowRef(0);
|
||||
/** Whether the live video surface replaces the still frame. */
|
||||
const live = shallowRef(false);
|
||||
/** `{label, state}` for the source badge; null until first synced. */
|
||||
@@ -49,6 +51,11 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
frame.value = markRaw(next);
|
||||
}
|
||||
|
||||
/** @param {boolean} shown */
|
||||
function showPreviewCard(shown) {
|
||||
previewCards.value = Math.max(0, previewCards.value + (shown ? 1 : -1));
|
||||
}
|
||||
|
||||
/** @param {boolean} on */
|
||||
function setLive(on) {
|
||||
live.value = Boolean(on);
|
||||
@@ -73,6 +80,7 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
view,
|
||||
calEdit,
|
||||
frame,
|
||||
previewCards,
|
||||
live,
|
||||
sourceBadge,
|
||||
summary,
|
||||
@@ -80,6 +88,7 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
publish,
|
||||
setCalEdit,
|
||||
setFrame,
|
||||
showPreviewCard,
|
||||
setLive,
|
||||
setSourceBadge,
|
||||
setSummary,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { useCctvStore } from '../../stores/cctv.js';
|
||||
@@ -13,7 +13,8 @@ const props = defineProps({
|
||||
cameraId: { type: String, default: '' },
|
||||
});
|
||||
|
||||
const { view, frame, sourceBadge } = storeToRefs(useCctvStore());
|
||||
const cctv = useCctvStore();
|
||||
const { view, frame, sourceBadge } = storeToRefs(cctv);
|
||||
const chrome = usePanelChromeStore();
|
||||
const { panels } = storeToRefs(chrome);
|
||||
|
||||
@@ -54,7 +55,11 @@ watch(big, (open) => {
|
||||
if (open) document.addEventListener('keydown', onKey);
|
||||
else document.removeEventListener('keydown', onKey);
|
||||
});
|
||||
onBeforeUnmount(() => document.removeEventListener('keydown', onKey));
|
||||
onMounted(() => cctv.showPreviewCard(true));
|
||||
onBeforeUnmount(() => {
|
||||
cctv.showPreviewCard(false);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
});
|
||||
|
||||
function openPanel() {
|
||||
if (panels.value['cctv-panel']?.collapsed !== false) chrome.act('toggle', 'cctv-panel');
|
||||
|
||||
Reference in new issue
Block a user