mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
fix(cctv): keep a clicked group in frame and let counts take clicks over plain fills
- The flight after a count click checks the frame on both axes and at the height of the highest mount, so a group on a slope or in a very wide window stays in view; when it cannot, it flies to the nearest cell with two or more cameras, never to a lone camera that joined the count. - A count takes a click over a background fill no layer owns (earthquake discs, fire perimeters), and still yields to a scene item another layer registered. - A count crossing the HUD edge refreshes the view only when the active icon or a lone camera depends on it, and never mid-motion, so panning no longer runs extra full view passes. - A count restored at the HUD edge keeps the lone cameras its outline covers, and leaves the others as icons.
This commit is contained in:
1 parent
f6982dc934
commit
aba4c9e533
14 files changed
+674
-41
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import {
|
||||
addCellCamera,
|
||||
createCameraCell,
|
||||
mergeCountCells,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { createNavigation } from './navigation.js';
|
||||
|
||||
const M = 111_320;
|
||||
|
||||
// Cesium's default 60 degree field of view spans the wider side, so a 4:3
|
||||
// window has a vertical fovy of about 46.8 degrees. Two pairs 50 km and 80 km
|
||||
// east of an eye 800 m up merge into one count. At half the distance all four
|
||||
// fit in the frame (the group is wide, not tall), so the flight must keep all
|
||||
// four in frame instead of approaching only the near pair.
|
||||
test('a count click on an east-west group that fits keeps every member in the frame', () => {
|
||||
const viewer = {};
|
||||
const flights = [];
|
||||
const aspectRatio = 800 / 600;
|
||||
const fovy = 2 * Math.atan(Math.tan(Math.PI / 6) / aspectRatio);
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose: () => ({ fovy, aspectRatio, position: fromDegrees(0, 0, 800) }),
|
||||
flyToBounds: (bounds, options) => flights.push({ bounds, options }),
|
||||
},
|
||||
canvas: { clientHeight: 600, clientWidth: 800 },
|
||||
});
|
||||
try {
|
||||
const members = [];
|
||||
const cells = [50_000, 80_000].map((start) => {
|
||||
const cell = createCameraCell(String(start));
|
||||
for (const eastM of [start, start + 10]) {
|
||||
const lon = eastM / M;
|
||||
addCellCamera(cell, { lat: 0, lon, absoluteHeightM: 8 });
|
||||
members.push(lon);
|
||||
}
|
||||
return cell;
|
||||
});
|
||||
const screens = [
|
||||
{ x: 400, y: 300 },
|
||||
{ x: 433, y: 300 },
|
||||
];
|
||||
const groups = mergeCountCells(
|
||||
cells,
|
||||
() => screens.shift(),
|
||||
() => ({ width: 40, height: 40 }),
|
||||
2,
|
||||
);
|
||||
assert.equal(groups.length, 1);
|
||||
assert.equal(groups[0].count, 4);
|
||||
// Reference: a north-up top-down frame at half the distance holds all four.
|
||||
const halfwayM = 65_005 / 2;
|
||||
const refHalfX = halfwayM * Math.tan(fovy / 2) * aspectRatio;
|
||||
assert.ok(members.every((lon) => Math.abs(lon * M - 65_005) <= refHalfX));
|
||||
createNavigation({ state: { _viewer: viewer }, parts: {} }).zoomToCell(
|
||||
groups[0],
|
||||
);
|
||||
assert.equal(flights.length, 1);
|
||||
const { range } = flights[0].options.offset;
|
||||
const center = toLonLatH(flights[0].bounds.center);
|
||||
const halfX = range * Math.tan(fovy / 2) * aspectRatio;
|
||||
const inFrame = members.filter(
|
||||
(lon) => Math.abs((lon - center.lon) * M) <= halfX,
|
||||
);
|
||||
assert.equal(
|
||||
inFrame.length,
|
||||
4,
|
||||
`only ${inFrame.length} of 4 members in frame (range ${Math.round(range)} m)`,
|
||||
);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user