mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(cctv): a count click yields to what is on top and keeps its group in frame
- A count click stands aside when an overlay label or another layer's card already took the click, and CCTV now claims a count click in the shared pick registry, so the flights layer no longer reads it as an empty-map click and keeps tracking its aircraft. - The flight to a group halves the distance only while the group stays in frame; otherwise it flies to the nearest ground cell of the group, so a tilted click no longer ends with no camera on screen. - Counts hidden under the HUD no longer push the active icon aside, and a lone camera that would move a merged count under the HUD leaves the original count and its icon as they were. - Cameras on one mount are spread before counts merge, so a spread icon no longer slides under a neighbouring count. - The ground module comment says how a camera without a batch height takes the drawn terrain.
This commit is contained in:
1 parent
2b7a6b0c63
commit
f6982dc934
16 files changed
+452
-70
No files matched your search
+11
-5
@@ -1998,10 +1998,13 @@ middle. The marker grows with the count and paints on the world overlay at
|
||||
callout resolution. The count covers the whole cell up to the horizon, including
|
||||
its off-screen cameras. Overlapping markers merge and add their counts. A lone
|
||||
camera whose icon would touch a marker joins the nearest one, unless the HUD
|
||||
hides that marker. The active camera keeps its own icon beside any marker that
|
||||
would cover it and stays out of the count. A click on a marker zooms in on its
|
||||
group, at least halving the distance each time. The view stays put while the
|
||||
cockpit or a tracked object holds it. Ambient cards and coverage attach only to
|
||||
hides the merged marker. In that case the lone camera keeps its icon and the
|
||||
count stays where it was before the merge. The active camera keeps its own icon
|
||||
beside any marker that would cover it and stays out of the count. A click on a
|
||||
marker zooms in on its group, at least halving the distance each time. If halving
|
||||
would leave the group wider than the frame, the view zooms in on the group's
|
||||
ground cell nearest the eye. The cockpit or a tracked object holds the view
|
||||
in place. Ambient cards and coverage attach only to
|
||||
cameras drawn as icons. On a globe map a marker stands on the drawn terrain. A
|
||||
camera the height batch never answered for takes the drawn terrain as its ground
|
||||
once it is near the screen. It reads that height again from much closer, once
|
||||
@@ -2131,7 +2134,10 @@ trail, a route. A layer under another layer's card or label
|
||||
(`isUnderOtherCard`) does nothing: it neither acts on its item there nor
|
||||
treats the click as empty space, so a tracked aircraft stays tracked and a
|
||||
selection stays selected. Context (`src/ui/entityContextBridge.js`) names
|
||||
nothing under a card. With no card on top, the scene rules are unchanged.
|
||||
nothing under a card. A layer can claim a target it paints outside the overlay's
|
||||
entries (`registerClickClaim`) where no card or label is on top. A CCTV count
|
||||
claims each click that zooms to it, so a tracked aircraft stays tracked.
|
||||
With no card or claim on top, the scene rules are unchanged.
|
||||
World-overlay hit rectangles are what is painted on screen until the next
|
||||
paint: an overlay change (a click subscriber publishing its selection card)
|
||||
no longer clears them mid-click, and a paint that draws nothing clears them
|
||||
|
||||
@@ -662,6 +662,8 @@
|
||||
"src/layers/cctv/source.test.mjs",
|
||||
"src/layers/cctv/frames.test.mjs",
|
||||
"src/layers/cctv/countMarkers.test.mjs",
|
||||
"src/layers/cctv/count_click_overlay.test.mjs",
|
||||
"src/layers/cctv/count_click_framing.test.mjs",
|
||||
"src/layers/cctv/ground.test.mjs",
|
||||
"src/layers/cctv/rendering.test.mjs",
|
||||
"src/data/alprCameras.js",
|
||||
|
||||
@@ -86,6 +86,8 @@ const RETRY_BASE_MS = 15_000;
|
||||
const RETRY_MAX_MS = 5 * 60 * 1000;
|
||||
|
||||
export const CCTV_OVERLAY_SOURCE_ID = 'cctv';
|
||||
/** The source a CCTV count marker takes clicks as. */
|
||||
export const CCTV_COUNT_CARD_SOURCE_ID = 'cctv-count';
|
||||
export const CCTV_THUMBNAIL_ALTITUDE_SCALE = Object.freeze({
|
||||
fullEnd: CCTV_CARD_SCALE_FULL_M,
|
||||
midEnd: CCTV_CARD_SCALE_MID_M,
|
||||
|
||||
@@ -136,7 +136,8 @@ function visitNeighbors(marker, grid, gap, visit) {
|
||||
* one grid bucket. Even the widest pill can only touch its eight neighbors.
|
||||
* A cell with one camera takes the footprint `sizeFor(1)` gives its icon and
|
||||
* joins the nearest count it touches. Lone cameras never join each other
|
||||
* or bridge two counts.
|
||||
* or bridge two counts. A spread icon's `offsetPx` shifts its footprint sideways.
|
||||
* A merged group lists its ground cells in `parts`.
|
||||
* Ground cells stay intact for the camera picker and individual-icon pass.
|
||||
*/
|
||||
export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
@@ -150,7 +151,7 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
// The view projector reuses its result object.
|
||||
return {
|
||||
cell,
|
||||
x: screen?.x,
|
||||
x: screen ? screen.x + (cell.offsetPx ?? 0) : undefined,
|
||||
y: screen?.y,
|
||||
halfSegment: (width - height) / 2,
|
||||
radius: height / 2,
|
||||
@@ -201,8 +202,10 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
} else {
|
||||
const group = createCameraCell(seed.cell.key);
|
||||
group.lone = [];
|
||||
group.parts = [];
|
||||
for (const { cell } of members) {
|
||||
addCell(group, cell);
|
||||
group.parts.push(...(cell.parts ?? [cell]));
|
||||
if (cell.count === 1) group.lone.push(cell);
|
||||
else if (cell.lone) group.lone.push(...cell.lone);
|
||||
}
|
||||
@@ -218,3 +221,13 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
/** Rebuild a group's count under its original key, excluding lone cameras. */
|
||||
export function withoutLoneCameras(group) {
|
||||
const counts = (group.parts ?? []).filter((cell) => cell.count > 1);
|
||||
if (!counts.length) return null;
|
||||
const core = createCameraCell(group.key);
|
||||
core.parts = counts;
|
||||
for (const cell of counts) addCell(core, cell);
|
||||
return core;
|
||||
}
|
||||
@@ -154,6 +154,24 @@ export function pickContact(query, position, options = {}) {
|
||||
let _overlayHitTest = null;
|
||||
/** @type {WeakMap<object, {sourceId: string, entryId: string}|null>} */
|
||||
const clickCards = new WeakMap();
|
||||
const _clickClaims = new Map();
|
||||
|
||||
/**
|
||||
* Register a target drawn outside the world overlay's entries, such as a CCTV
|
||||
* count. A claim runs once per click where no card or label is painted above
|
||||
* it and must not call `clickCard`.
|
||||
* @param {string} layerId
|
||||
* @param {(click: object) => ({sourceId: string, entryId: string}|null)} claim
|
||||
*/
|
||||
export function registerClickClaim(layerId, claim) {
|
||||
if (!layerId || typeof claim !== 'function') return;
|
||||
_clickClaims.set(layerId, claim);
|
||||
}
|
||||
|
||||
/** Remove a layer's claim when it is disabled or destroyed. */
|
||||
export function unregisterClickClaim(layerId) {
|
||||
_clickClaims.delete(layerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets (or with null, clears) the hit test that names the card or label
|
||||
@@ -166,8 +184,8 @@ export function setClickCardHitTest(hitTest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The topmost interactive card or label painted at a click, read once per
|
||||
* click so every handler of it sees the same one whatever ran first.
|
||||
* The topmost interactive card or label painted at a click, or a target a
|
||||
* layer claims (`registerClickClaim`). All handlers share one result per click.
|
||||
* @param {{screenPosition?: {x: number, y: number}}|null|undefined} click
|
||||
* @returns {{sourceId: string, entryId: string}|null}
|
||||
*/
|
||||
@@ -179,14 +197,28 @@ export function clickCard(click) {
|
||||
try {
|
||||
card = _overlayHitTest?.(at?.x, at?.y) ?? null;
|
||||
} catch {
|
||||
// a broken hit test must never break click handling
|
||||
clickCards.set(click, null);
|
||||
return null;
|
||||
}
|
||||
if (!card) {
|
||||
// A claim that reads this click again cannot re-enter the claims loop.
|
||||
clickCards.set(click, null);
|
||||
for (const claim of _clickClaims.values()) {
|
||||
try {
|
||||
card = claim(click) ?? null;
|
||||
} catch {
|
||||
card = null;
|
||||
}
|
||||
if (card) break;
|
||||
}
|
||||
}
|
||||
clickCards.set(click, card);
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when another layer's card or label is painted on top at a click. The
|
||||
* True when another layer has the top card, label, or claimed target
|
||||
* (`registerClickClaim`) at a click. The
|
||||
* card on top takes the click: a scene item under it does not act, and is
|
||||
* not empty space either, so the layer leaves its selection alone.
|
||||
* @param {object} click The shared dispatcher event.
|
||||
|
||||
@@ -20,6 +20,8 @@ import {
|
||||
clickCard,
|
||||
isUnderOtherCard,
|
||||
setClickCardHitTest,
|
||||
registerClickClaim,
|
||||
unregisterClickClaim,
|
||||
} from './pickRegistry.js';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -237,3 +239,42 @@ test("the card on top is read once per click, and only another layer's card coun
|
||||
setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
|
||||
test('a click claim is the card on top only where no card or label is painted', () => {
|
||||
const event = (x) => ({ screenPosition: { x, y: 5 } });
|
||||
let calls = 0;
|
||||
registerClickClaim('counts', (click) => {
|
||||
calls++;
|
||||
return click.screenPosition.x === 4
|
||||
? { sourceId: 'counts', entryId: 'k' }
|
||||
: null;
|
||||
});
|
||||
try {
|
||||
registerClickClaim('counts', null);
|
||||
const click = event(4);
|
||||
assert.equal(isUnderOtherCard(click), true);
|
||||
assert.equal(isUnderOtherCard(click, ['counts']), false);
|
||||
assert.equal(calls, 1);
|
||||
assert.equal(clickCard(event(9)), null);
|
||||
const quake = { sourceId: 'quake-card', entryId: 'q1' };
|
||||
setClickCardHitTest(() => quake);
|
||||
assert.deepEqual(clickCard(event(4)), quake);
|
||||
assert.equal(calls, 2);
|
||||
setClickCardHitTest(() => {
|
||||
throw new Error('broken overlay hit test');
|
||||
});
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
assert.equal(calls, 2);
|
||||
setClickCardHitTest(null);
|
||||
|
||||
unregisterClickClaim('counts');
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
registerClickClaim('counts', () => {
|
||||
throw new Error('broken claim');
|
||||
});
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
} finally {
|
||||
unregisterClickClaim('counts');
|
||||
setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
cellLonLat,
|
||||
formatCameraCount,
|
||||
mergeCountCells,
|
||||
withoutLoneCameras,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { WORLD_OVERLAY_STYLE } from '../../overlays/worldOverlayTokens.js';
|
||||
import {
|
||||
@@ -200,7 +201,27 @@ export function createCountMarkers(
|
||||
ground(visible);
|
||||
let changed = visible.length !== markers.length;
|
||||
for (let i = 0; i < visible.length; i++) {
|
||||
const cell = visible[i];
|
||||
let cell = visible[i];
|
||||
// If the merged count is under the HUD, restore the count and its lone icons.
|
||||
if (hardUi && cell.lone?.length) {
|
||||
const at = project(cellCenter(cell));
|
||||
const { width, height } = sizeFor(cell.count);
|
||||
const rect = at && {
|
||||
x: at.x - width / 2,
|
||||
y: at.y - height / 2,
|
||||
w: width,
|
||||
h: height,
|
||||
};
|
||||
if (rect && hardUi(rect)) {
|
||||
for (const lone of cell.lone) lone.absorbed = false;
|
||||
const core = withoutLoneCameras(cell);
|
||||
if (core) {
|
||||
core.releasedAt = rect;
|
||||
ground([core]);
|
||||
cell = core;
|
||||
}
|
||||
}
|
||||
}
|
||||
const marker = (markers[i] ??= { focus: 1 });
|
||||
const last = marker.cell;
|
||||
const size = sizeFor(cell.count);
|
||||
@@ -217,20 +238,6 @@ export function createCountMarkers(
|
||||
marker.hudHidden = undefined;
|
||||
changed = true;
|
||||
}
|
||||
// A count hidden by the HUD leaves its lone cameras visible as icons.
|
||||
if (hardUi && cell.lone?.length) {
|
||||
const at = project(marker.pos);
|
||||
if (
|
||||
at &&
|
||||
hardUi({
|
||||
x: at.x - size.width / 2,
|
||||
y: at.y - size.height / 2,
|
||||
w: size.width,
|
||||
h: size.height,
|
||||
})
|
||||
)
|
||||
for (const lone of cell.lone) lone.absorbed = false;
|
||||
}
|
||||
changed ||=
|
||||
size.text !== marker.text ||
|
||||
size.width !== marker.width ||
|
||||
@@ -267,6 +274,8 @@ export function createCountMarkers(
|
||||
ctx.textBaseline = 'middle';
|
||||
for (let i = 0; i < markers.length; i++) {
|
||||
const marker = markers[i];
|
||||
// The core can stay visible while the HUD uncovers the merged count.
|
||||
if (marker.cell.releasedAt) refresh ||= !hardUi(marker.cell.releasedAt);
|
||||
const { height } = marker;
|
||||
const { x: px, y: py, z: pz } = marker.pos;
|
||||
const w = m[3] * px + m[7] * py + m[11] * pz + m[15];
|
||||
@@ -291,12 +300,14 @@ export function createCountMarkers(
|
||||
)
|
||||
continue;
|
||||
const hidden = Boolean(hardUi?.(rect));
|
||||
if (marker.hudHidden !== hidden) {
|
||||
const previous = marker.hudHidden;
|
||||
if (previous !== hidden) {
|
||||
marker.hudHidden = hidden;
|
||||
// A first frame or moving HUD can change which lone icons must show.
|
||||
refresh ||= marker.cell.lone?.some(
|
||||
(cell) => cell.absorbed === hidden,
|
||||
);
|
||||
// The active icon steps aside only for visible counts.
|
||||
refresh ||=
|
||||
hidden ||
|
||||
previous !== undefined ||
|
||||
marker.cell.lone?.some((cell) => cell.absorbed === hidden);
|
||||
}
|
||||
if (hidden) continue;
|
||||
const fade =
|
||||
|
||||
@@ -126,6 +126,25 @@ test('a lone camera clear of the HUD keeps its icon when the count beside it is
|
||||
}
|
||||
});
|
||||
|
||||
test('a count stays visible when a lone camera would move it under the HUD', async () => {
|
||||
const cells = [cellAt('a', 200, 2), cellAt('b', 234, 1)];
|
||||
const hud = { overlapsHardUi: (rect) => rect.x + rect.w > 225 };
|
||||
const m = counts(() => m.update(cells, project));
|
||||
paint(hud);
|
||||
m.update(cells, project);
|
||||
assert.equal(paint(hud)[0]?.text, '2');
|
||||
assert.equal(cells[1].absorbed, false);
|
||||
await Promise.resolve();
|
||||
paint(hud);
|
||||
await Promise.resolve();
|
||||
|
||||
paint();
|
||||
await Promise.resolve();
|
||||
assert.equal(cells[1].absorbed, true);
|
||||
assert.equal(paint()[0]?.text, '3');
|
||||
m.dispose();
|
||||
});
|
||||
|
||||
test('counts fade with the Scope keyhole like the callouts', () => {
|
||||
const m = counts(undefined, (_x, _y, keyhole) => keyhole.alpha);
|
||||
m.update([cellAt('a', 400, 2)], project);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import {
|
||||
addCellCamera,
|
||||
createCameraCell,
|
||||
mergeCountCells,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { createNavigation } from './navigation.js';
|
||||
|
||||
// A count of four merged in a tilted view: two pairs 10 km and 40 km north of
|
||||
// an eye 800 m up. After the click, at least one member must be in frame.
|
||||
test('a count click from a tilted view keeps the group members in the frame', () => {
|
||||
const viewer = {};
|
||||
const flights = [];
|
||||
const fovy = Math.PI / 3;
|
||||
const aspectRatio = 800 / 600;
|
||||
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 metresPerDegree = 111_320;
|
||||
const members = [];
|
||||
const cells = [10_000, 40_000].map((start) => {
|
||||
const cell = createCameraCell(String(start));
|
||||
for (const northM of [start, start + 10]) {
|
||||
const lat = northM / metresPerDegree;
|
||||
addCellCamera(cell, { lat, lon: 0, absoluteHeightM: 8 });
|
||||
members.push(fromDegrees(0, lat, 8));
|
||||
}
|
||||
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);
|
||||
const state = { _viewer: viewer };
|
||||
const navigation = createNavigation({ state, parts: {} });
|
||||
navigation.zoomToCell(groups[0]);
|
||||
assert.equal(flights.length, 1);
|
||||
const { range, pitch } = flights[0].options.offset;
|
||||
assert.equal(pitch, -Math.PI / 2);
|
||||
const { center } = flights[0].bounds;
|
||||
const halfSpanM = range * Math.tan(fovy / 2);
|
||||
assert.ok(
|
||||
members.some((point) => distance(point, center) <= halfSpanM),
|
||||
'no member of the group is in the final frame',
|
||||
);
|
||||
assert.ok(range < distance(fromDegrees(0, 0, 800), center));
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSelection } from './selection.js';
|
||||
|
||||
function setup() {
|
||||
let zooms = 0,
|
||||
clicks = 0;
|
||||
const selection = createSelection({
|
||||
services: { activation: {}, picking },
|
||||
state: {
|
||||
_enabled: true,
|
||||
_counts: { pickedCell: () => ({}) },
|
||||
_cctvOverlayHost: { hitTest: () => null },
|
||||
},
|
||||
parts: {
|
||||
navigation: { zoomToCell: () => zooms++ },
|
||||
rendering: { extractPickedCameraId: () => null },
|
||||
},
|
||||
});
|
||||
const click = selection.bindCctvWorldClickGesture(
|
||||
{ onClick: (fn) => fn },
|
||||
() => clicks++,
|
||||
);
|
||||
return { click, counts: () => [zooms, clicks] };
|
||||
}
|
||||
|
||||
test('a click a painted overlay target took (Space Missions label) does not fly to the count', () => {
|
||||
const { click, counts } = setup();
|
||||
// What the dispatcher hands subscribers after an onOverlayClick handler returned true.
|
||||
click({
|
||||
screenPosition: { x: 20, y: 26 },
|
||||
overlay: true,
|
||||
topHit: { set: '', id: null, surface: false },
|
||||
drawHit: null,
|
||||
gesture: { travelPx: 0, durationMs: 20 },
|
||||
});
|
||||
assert.equal(
|
||||
counts()[0],
|
||||
0,
|
||||
'count flight ran although an overlay target handled the click',
|
||||
);
|
||||
});
|
||||
|
||||
test("another layer's world-overlay card on top (clickCard) takes the click from the count", () => {
|
||||
const { click, counts } = setup();
|
||||
picking.setClickCardHitTest(() => ({
|
||||
sourceId: 'earthquakes',
|
||||
entryId: 'eq-1',
|
||||
}));
|
||||
try {
|
||||
click({
|
||||
screenPosition: { x: 20, y: 26 },
|
||||
topHit: null,
|
||||
drawHit: null,
|
||||
gesture: { travelPx: 0, durationMs: 20 },
|
||||
});
|
||||
assert.ok(
|
||||
picking.isUnderOtherCard({ screenPosition: { x: 1, y: 1 } }, ['cctv']),
|
||||
);
|
||||
assert.equal(counts()[0], 0, 'count flight ran under another layer card');
|
||||
} finally {
|
||||
picking.setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
@@ -22,11 +22,12 @@ export function createGround({ state: layerState, services, parts, source }) {
|
||||
* - `google-3d` — photoreal stack: globe hidden, the visible Google 3D
|
||||
* tileset IS the surface → one-shot scene sampling refines.
|
||||
* - `terrain-globe` — any globe stack: the Re:Earth point-height prior IS the
|
||||
* resolution (zero scene queries).
|
||||
* resolution. A camera the batch left unanswered takes the
|
||||
* drawn terrain from the view pass (`adoptDrawnGround`).
|
||||
*
|
||||
* Only an explicit `false` (the photoreal stack hides the globe) selects
|
||||
* `google-3d`; undefined/null (no viewer / torn down) must fall to the regime
|
||||
* that never touches the scene. Pure — exported for the unit suite.
|
||||
* that never samples the scene's tiles. Pure — exported for the unit suite.
|
||||
* @param {boolean|undefined|null} globeShow - Whether the renderer shows the
|
||||
* globe (`globe.isGlobeVisible()`).
|
||||
* @returns {'google-3d'|'terrain-globe'}
|
||||
|
||||
@@ -23,8 +23,14 @@ export function createLifecycle({
|
||||
source,
|
||||
}) {
|
||||
const { activateCctvCameraFromWorldClick } = services.activation;
|
||||
const { resolvePickId, registerPickOwner, unregisterPickOwner, clickCard } =
|
||||
services.picking;
|
||||
const {
|
||||
resolvePickId,
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
clickCard,
|
||||
registerClickClaim,
|
||||
unregisterClickClaim,
|
||||
} = services.picking;
|
||||
const { onFocusTargetAppear } = services.focus;
|
||||
const { releaseContinuousRender } = services.render;
|
||||
|
||||
@@ -510,6 +516,7 @@ export function createLifecycle({
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
});
|
||||
registerClickClaim?.('cctv', parts.selection.countClickCard);
|
||||
if (!layerState._activeCameraId && layerState._records.length) {
|
||||
layerState._activeCameraId = parts.navigation.openingCameraId();
|
||||
layerState._autoHopSuspended = false;
|
||||
@@ -546,6 +553,7 @@ export function createLifecycle({
|
||||
services.credits?.hideOsmCredit?.(layerState._viewer, 'cctv');
|
||||
layerState._enabled = false;
|
||||
unregisterPickOwner('cctv');
|
||||
unregisterClickClaim?.('cctv');
|
||||
// ADJUST mode does not survive a layer toggle — predictable re-entry.
|
||||
layerState._calibrationMode = false;
|
||||
releaseContinuousRender('cctv-adjust');
|
||||
@@ -580,6 +588,7 @@ export function createLifecycle({
|
||||
parts.cards.handleVisibilityChange,
|
||||
);
|
||||
unregisterPickOwner('cctv');
|
||||
unregisterClickClaim?.('cctv');
|
||||
if (layerState._mapStackListener && typeof window !== 'undefined') {
|
||||
window.removeEventListener(
|
||||
'gev:map-stack-changed',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import { rangeForBoundingSphere } from '../../data/cameraFraming.js';
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { cellBounds } from '../../data/cctvCellCounts.js';
|
||||
import { cellBounds, cellCenter } from '../../data/cctvCellCounts.js';
|
||||
import { CCTV_FOCUS_RESULT, VIEW_CELL_PX, VIEW_MIN_CELL_M } from './policy.js';
|
||||
import { cameraOf, canvasOf } from '../../render/rendererOf.js';
|
||||
|
||||
@@ -131,6 +131,20 @@ export function createNavigation({
|
||||
return CCTV_FOCUS_RESULT.FOCUSED;
|
||||
}
|
||||
|
||||
/** The ground cell of a group nearest the eye, or the group itself if unmerged. */
|
||||
function nearestPart(cell, eye) {
|
||||
let nearest = cell;
|
||||
let best = Infinity;
|
||||
for (const part of cell.parts ?? []) {
|
||||
const d = distance(eye, cellCenter(part));
|
||||
if (d < best) {
|
||||
best = d;
|
||||
nearest = part;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
/** Frame a group's padded bounds from above, including coincident mounts. */
|
||||
function zoomToCell(cell) {
|
||||
const viewer = layerState._viewer;
|
||||
@@ -140,18 +154,23 @@ export function createNavigation({
|
||||
const tanHalfY = Math.tan((pose.fovy || Math.PI / 3) / 2);
|
||||
const canvas = canvasOf(viewer);
|
||||
const height = canvas?.clientHeight || canvas?.height || 1;
|
||||
const bounds = cellBounds(cell);
|
||||
// Half the range where cells stop grouping, so even coincident mounts split.
|
||||
const closeRange =
|
||||
(VIEW_MIN_CELL_M * height) / (4 * VIEW_CELL_PX * tanHalfY);
|
||||
const fitRange = (bounds) =>
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius));
|
||||
// Approach long groups in halves so every click gets closer.
|
||||
const halfway = pose.position
|
||||
? distance(pose.position, bounds.center) / 2
|
||||
: Infinity;
|
||||
const range = Math.min(
|
||||
halfway,
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius)),
|
||||
);
|
||||
const halfway = (bounds) =>
|
||||
pose.position ? distance(pose.position, bounds.center) / 2 : Infinity;
|
||||
let bounds = cellBounds(cell);
|
||||
const fit = fitRange(bounds);
|
||||
let range = Math.min(halfway(bounds), fit);
|
||||
// If the group exceeds the narrower side of the frame, approach its nearest part.
|
||||
const tanHalf = tanHalfY * Math.min(1, pose.aspectRatio || 1);
|
||||
if (range < fit && range * tanHalf < bounds.radius) {
|
||||
bounds = cellBounds(nearestPart(cell, pose.position));
|
||||
range = Math.min(halfway(bounds), fitRange(bounds));
|
||||
}
|
||||
camera.flyToBounds(bounds, {
|
||||
offset: { heading: 0, pitch: -Math.PI / 2, range },
|
||||
durationS: 1.2,
|
||||
|
||||
@@ -546,6 +546,17 @@ export function createRendering({
|
||||
cell.rank = rank;
|
||||
}
|
||||
}
|
||||
// Check each mount mate against counts where its icon will be drawn.
|
||||
const lone = visibleCells.filter((cell) => cell.count === 1);
|
||||
spreadSharedMounts(
|
||||
shown.concat(lone.map((cell) => cell.winner)),
|
||||
pose,
|
||||
metresPerPixelPerMetre,
|
||||
pass,
|
||||
);
|
||||
for (const cell of lone)
|
||||
cell.offsetPx =
|
||||
cell.winner.spreadPass === pass ? cell.winner.spreadPx : 0;
|
||||
// A count stands on the drawn terrain too: its cell may be too far for
|
||||
// its cameras to have been read. Marks each lone camera that a count
|
||||
// marker beside it has taken in.
|
||||
@@ -559,7 +570,6 @@ export function createRendering({
|
||||
shown.push(record);
|
||||
}
|
||||
}
|
||||
spreadSharedMounts(shown, pose, metresPerPixelPerMetre, pass);
|
||||
clearActiveOfCounts(project, pose, metresPerPixelPerMetre, pass);
|
||||
const writes = [];
|
||||
let coverageChanged = false;
|
||||
@@ -626,10 +636,10 @@ export function createRendering({
|
||||
|
||||
/**
|
||||
* Cameras on one mount would draw as one icon with several callouts. Among
|
||||
* the cameras shown, those within VIEW_SITE_M horizontally get draw
|
||||
* positions side by side along the screen's horizontal, in id order,
|
||||
* `VIEW_SITE_SPREAD_PX` apart at the distance they are seen from. The
|
||||
* record's own position is untouched: geometry and cards keep the mount.
|
||||
* icon candidates, those within VIEW_SITE_M horizontally get draw positions
|
||||
* side by side in id order, `VIEW_SITE_SPREAD_PX` apart on screen. A mate
|
||||
* absorbed by a count keeps its place in the row. Geometry and cards stay
|
||||
* on the mount.
|
||||
*/
|
||||
function spreadSharedMounts(shown, pose, metresPerPixelPerMetre, pass) {
|
||||
const { right, direction, position: eye } = pose;
|
||||
@@ -669,11 +679,9 @@ export function createRendering({
|
||||
(p.x - eye.x) * direction.x +
|
||||
(p.y - eye.y) * direction.y +
|
||||
(p.z - eye.z) * direction.z;
|
||||
const metres =
|
||||
(i - (mates.length - 1) / 2) *
|
||||
VIEW_SITE_SPREAD_PX *
|
||||
metresPerPixelPerMetre *
|
||||
depth;
|
||||
const px = (i - (mates.length - 1) / 2) * VIEW_SITE_SPREAD_PX;
|
||||
record.spreadPx = px;
|
||||
const metres = px * metresPerPixelPerMetre * depth;
|
||||
record.spreadOffset = scale(right, metres);
|
||||
record.spreadPosition = add(p, record.spreadOffset);
|
||||
record.spreadPass = pass;
|
||||
@@ -681,7 +689,7 @@ export function createRendering({
|
||||
}
|
||||
}
|
||||
|
||||
/** Move the active camera's icon beside any count marker that would cover it. */
|
||||
/** Only counts visible outside the HUD push the active icon aside. */
|
||||
function clearActiveOfCounts(project, pose, metresPerPixelPerMetre, pass) {
|
||||
if (!layerState._activeCameraId) return;
|
||||
const record = layerState._recordById.get(layerState._activeCameraId);
|
||||
@@ -702,6 +710,7 @@ export function createRendering({
|
||||
(CAMERA_ICON_PX * 1.25 * iconScaleAt(distance(p, pose.position))) / 2;
|
||||
const spans = [];
|
||||
for (const marker of markers) {
|
||||
if (marker.hudHidden) continue;
|
||||
const at = project(marker.pos);
|
||||
if (
|
||||
!at ||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import {
|
||||
CCTV_COUNT_CARD_SOURCE_ID,
|
||||
CCTV_OVERLAY_SOURCE_ID,
|
||||
} from '../../data/cctvCards.js';
|
||||
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -8,7 +11,8 @@ export function createSelection({
|
||||
source,
|
||||
}) {
|
||||
const { CCTV_ACTIVATION_RESULT } = services.activation;
|
||||
const { resolvePickId, findPickOwner } = services.picking;
|
||||
const { resolvePickId, findPickOwner, isUnderOtherCard } = services.picking;
|
||||
const OWN_CARD_SOURCES = [CCTV_OVERLAY_SOURCE_ID, CCTV_COUNT_CARD_SOURCE_ID];
|
||||
|
||||
/**
|
||||
* Returns the camera record for the currently active camera. A stale ID falls
|
||||
@@ -30,15 +34,8 @@ export function createSelection({
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** A card painted above the count, or another layer's object, owns the click. */
|
||||
function countYields(event) {
|
||||
const { x, y } = event.screenPosition;
|
||||
if (
|
||||
layerState._cctvOverlayHost?.hitTest(x, y, {
|
||||
sourceId: CCTV_OVERLAY_SOURCE_ID,
|
||||
})?.entryId
|
||||
)
|
||||
return true;
|
||||
/** Whether another layer's scene object owns the click at this count. */
|
||||
function sceneTakesCountClick(event) {
|
||||
const top = event.topHit;
|
||||
if (!top) return false;
|
||||
const drawHit = event.drawHit;
|
||||
@@ -47,6 +44,34 @@ export function createSelection({
|
||||
return id !== null && findPickOwner?.(id) !== 'cctv';
|
||||
}
|
||||
|
||||
/** Leave other layers' cards to the caller since clickCard also calls this. */
|
||||
function clickedCount(event) {
|
||||
if (
|
||||
!isTrackingClickGesture(event.gesture) ||
|
||||
!layerState._enabled ||
|
||||
event.overlay
|
||||
)
|
||||
return null;
|
||||
const cell = layerState._counts?.pickedCell(event.screenPosition);
|
||||
if (!cell) return null;
|
||||
const { x, y } = event.screenPosition;
|
||||
if (
|
||||
layerState._cctvOverlayHost?.hitTest(x, y, {
|
||||
sourceId: CCTV_OVERLAY_SOURCE_ID,
|
||||
})?.entryId
|
||||
)
|
||||
return null;
|
||||
return sceneTakesCountClick(event) ? null : cell;
|
||||
}
|
||||
|
||||
/** The count marker as the card on top of a click it takes, for every layer's clickCard. */
|
||||
function countClickCard(event) {
|
||||
const cell = clickedCount(event);
|
||||
return cell
|
||||
? { sourceId: CCTV_COUNT_CARD_SOURCE_ID, entryId: String(cell.key ?? '') }
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind CCTV activation to clean taps. Drag-like and long-press gestures do
|
||||
* not reach camera activation or focus dispatch.
|
||||
@@ -59,10 +84,9 @@ export function createSelection({
|
||||
function bindCctvWorldClickGesture(input, onClick) {
|
||||
return input.onClick((event) => {
|
||||
if (!isTrackingClickGesture(event.gesture)) return;
|
||||
const cell =
|
||||
layerState._enabled &&
|
||||
layerState._counts?.pickedCell(event.screenPosition);
|
||||
if (cell && !countYields(event)) {
|
||||
const cell = clickedCount(event);
|
||||
// Another layer's card or label painted above the count takes the click.
|
||||
if (cell && !isUnderOtherCard?.(event, OWN_CARD_SOURCES)) {
|
||||
parts.navigation.zoomToCell(cell);
|
||||
return;
|
||||
}
|
||||
@@ -243,6 +267,7 @@ export function createSelection({
|
||||
return {
|
||||
getActiveRecord,
|
||||
bindCctvWorldClickGesture,
|
||||
countClickCard,
|
||||
setActiveCamera,
|
||||
deactivateActiveCamera,
|
||||
cctvEmptyClickDeselects,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import { CCTV_COUNT_CARD_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { CCTV_ACTIVATION_RESULT } from '../../cctvFocusRequest.js';
|
||||
@@ -150,3 +151,63 @@ test("a count click yields to a card above it and to another layer's object, not
|
||||
picking.unregisterPickOwner('cctv');
|
||||
}
|
||||
});
|
||||
|
||||
test('a count click is the card on top for every layer, unless the count yields', () => {
|
||||
let zooms = 0;
|
||||
let clicks = 0;
|
||||
const selection = createSelection({
|
||||
services: { activation: {}, picking },
|
||||
state: {
|
||||
_enabled: true,
|
||||
_counts: { pickedCell: (p) => (p?.x === 20 ? { key: 'g' } : null) },
|
||||
_cctvOverlayHost: { hitTest: () => null },
|
||||
},
|
||||
parts: {
|
||||
navigation: { zoomToCell: () => zooms++ },
|
||||
rendering: {
|
||||
extractPickedCameraId: (hit) =>
|
||||
hit?.set === 'cctv-icons' ? hit.id : null,
|
||||
},
|
||||
},
|
||||
});
|
||||
const click = selection.bindCctvWorldClickGesture(
|
||||
{ onClick: (fn) => fn },
|
||||
() => clicks++,
|
||||
);
|
||||
const event = (topHit = null, x = 20, durationMs = 20) => ({
|
||||
screenPosition: { x, y: 26 },
|
||||
topHit,
|
||||
drawHit: topHit,
|
||||
gesture: { travelPx: 0, durationMs },
|
||||
});
|
||||
picking.registerClickClaim('cctv', selection.countClickCard);
|
||||
try {
|
||||
const aircraftFirst = event();
|
||||
assert.equal(picking.isUnderOtherCard(aircraftFirst), true);
|
||||
assert.deepEqual(picking.clickCard(aircraftFirst), {
|
||||
sourceId: CCTV_COUNT_CARD_SOURCE_ID,
|
||||
entryId: 'g',
|
||||
});
|
||||
click(aircraftFirst);
|
||||
assert.deepEqual([zooms, clicks], [1, 0]);
|
||||
|
||||
const cctvFirst = event();
|
||||
click(cctvFirst);
|
||||
assert.equal(picking.isUnderOtherCard(cctvFirst), true);
|
||||
assert.deepEqual([zooms, clicks], [2, 0]);
|
||||
|
||||
for (const [e, claimed, expected] of [
|
||||
[event({ set: 'flights', id: 'abc' }), false, [2, 1]],
|
||||
[event({ set: 'cctv-icons', id: 'cam-2' }), true, [3, 1]],
|
||||
[event(null, 20, 1000), false, [3, 1]],
|
||||
[event(null, 60), false, [3, 2]],
|
||||
[{ ...event(), overlay: true }, false, [3, 3]],
|
||||
]) {
|
||||
assert.equal(picking.isUnderOtherCard(e), claimed);
|
||||
click(e);
|
||||
assert.deepEqual([zooms, clicks], expected);
|
||||
}
|
||||
} finally {
|
||||
picking.unregisterClickClaim('cctv');
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user