mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
fix(cctv): paint count markers on the world overlay canvas
The scene renders at CSS resolution and is stretched on a high-density display, so a count marker drawn as a scene sprite looked coarse next to the camera callouts, which the world overlay paints at device density. Paint the markers through the overlay's custom paint lane instead, in the callouts' typeface. Each paint reprojects the group centres; a click is resolved against the rectangles painted in the last frame and still zooms to the group without choosing a camera. A marker that would cover HUD chrome is skipped, as overlay entries are. With no aggregate sprites left, the contact sweep no longer needs to skip them, so that exclusion is removed.
This commit is contained in:
1 parent
87bff9957b
commit
aabfa5e084
12 files changed
+583
-249
No files matched your search
+186
-101
@@ -1,80 +1,62 @@
|
||||
import { createIconBook } from '../../render/motion/iconBook.js';
|
||||
import {
|
||||
cellCenter,
|
||||
formatCameraCount,
|
||||
mergeCountCells,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { getLocale } from '../../i18n/index.js';
|
||||
import { WORLD_OVERLAY_STYLE } from '../../overlays/worldOverlayTokens.js';
|
||||
import {
|
||||
COUNT_MARKER_PX,
|
||||
COUNT_MERGE_DISTANCE_PX,
|
||||
COUNT_MERGE_PASSES,
|
||||
} from './policy.js';
|
||||
|
||||
/** A pool of static count billboards sharing one canvas for each label. */
|
||||
export function createCountMarkers(set) {
|
||||
const book = createIconBook(set);
|
||||
const images = new Map();
|
||||
const groups = [];
|
||||
let locale;
|
||||
const FONT = WORLD_OVERLAY_STYLE.fontTitle;
|
||||
const RING = '#75e7ff';
|
||||
|
||||
/** Rasterise at twice the CSS size to keep small digits sharp. */
|
||||
function imageFor(text) {
|
||||
if (images.has(text)) return images.get(text);
|
||||
const canvas = document.createElement('canvas');
|
||||
const size = COUNT_MARKER_PX * 2;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const font = 'bold 24px sans-serif';
|
||||
ctx.font = font;
|
||||
// A two-pixel ring survives the halving to screen size, and the clear
|
||||
// margin leaves its outer edge room to antialias inside the sprite.
|
||||
const ring = 4;
|
||||
const margin = 4;
|
||||
const inset = margin + ring / 2;
|
||||
// Up to three digits sit inside the circle; a longer label gets a pill
|
||||
// with room for its rounded ends.
|
||||
const textWidth = Math.ceil(ctx.measureText(text).width);
|
||||
const fitsCircle = textWidth <= size - 2 * (margin + ring) - 4;
|
||||
canvas.width = fitsCircle ? size : textWidth + 2 * (margin + ring + 12);
|
||||
canvas.height = size;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(
|
||||
inset,
|
||||
inset,
|
||||
canvas.width - 2 * inset,
|
||||
size - 2 * inset,
|
||||
size / 2 - inset,
|
||||
);
|
||||
// A dark rim outside the ring keeps it off bright ground.
|
||||
ctx.lineWidth = ring + 4;
|
||||
ctx.strokeStyle = 'rgba(8, 14, 20, 0.85)';
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = '#0e1720';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = ring;
|
||||
ctx.strokeStyle = '#75e7ff';
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = ctx.strokeStyle;
|
||||
ctx.font = font;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(text, canvas.width / 2, size / 2);
|
||||
const image = { canvas, key: `cctv-count:${text}` };
|
||||
images.set(text, image);
|
||||
return image;
|
||||
/** Merged camera groups and their last painted hit rectangles in CSS pixels. */
|
||||
export function createCountMarkers(registerPaintLane, id, refreshView) {
|
||||
const markers = [];
|
||||
const hits = [];
|
||||
const widths = new Map();
|
||||
const fonts = globalThis.document?.fonts;
|
||||
let measureCtx;
|
||||
let hitCount = 0;
|
||||
const lane = registerPaintLane?.('ambient-label', paint, {
|
||||
id,
|
||||
active: false,
|
||||
target: 'shared',
|
||||
});
|
||||
fonts?.addEventListener?.('loadingdone', fontsLoaded);
|
||||
|
||||
/** Font changes can widen a pill enough to merge it with its neighbor. */
|
||||
function fontsLoaded() {
|
||||
widths.clear();
|
||||
if (!markers.length) return;
|
||||
refreshView();
|
||||
lane?.requestPaint();
|
||||
}
|
||||
|
||||
/** Reuse the first slots for visible cells and hide the unused tail. */
|
||||
/** Short labels fit the circle. A longer label leaves room for rounded ends. */
|
||||
function widthForText(text) {
|
||||
if (text.length <= 3) return COUNT_MARKER_PX;
|
||||
let width = widths.get(text);
|
||||
if (width === undefined) {
|
||||
measureCtx ??= document.createElement('canvas').getContext('2d');
|
||||
measureCtx.font = FONT;
|
||||
width = Math.max(
|
||||
COUNT_MARKER_PX + 1,
|
||||
Math.ceil(measureCtx.measureText(text).width) + 20,
|
||||
);
|
||||
widths.set(text, width);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
/** Reuse marker slots in ground-key order, and invalidate only changed frames. */
|
||||
function update(cells, project) {
|
||||
const writes = [];
|
||||
const nextLocale = getLocale();
|
||||
let slot = 0;
|
||||
// Ground-key order keeps the pooled slots stable across pans and health changes.
|
||||
let visible = cells
|
||||
.filter((cell) => cell.count > 1)
|
||||
.sort((a, b) => a.key.localeCompare(b.key));
|
||||
const widthFor = (count) =>
|
||||
imageFor(formatCameraCount(count)).canvas.width / 2;
|
||||
for (
|
||||
let pass = 0;
|
||||
pass < COUNT_MERGE_PASSES && visible.length > 1;
|
||||
@@ -83,57 +65,160 @@ export function createCountMarkers(set) {
|
||||
const merged = mergeCountCells(
|
||||
visible,
|
||||
project,
|
||||
widthFor,
|
||||
(count) => widthForText(formatCameraCount(count)),
|
||||
COUNT_MARKER_PX,
|
||||
COUNT_MERGE_DISTANCE_PX,
|
||||
);
|
||||
if (merged.length === visible.length) break;
|
||||
visible = merged;
|
||||
}
|
||||
for (const cell of visible) {
|
||||
const index = slot++;
|
||||
const last = groups[index];
|
||||
groups[index] = cell;
|
||||
// Bounds are live for picking even when the drawn label and mean stay put.
|
||||
let changed = visible.length !== markers.length;
|
||||
for (let i = 0; i < visible.length; i++) {
|
||||
const cell = visible[i];
|
||||
const marker = markers[i] ?? (markers[i] = { focus: 1 });
|
||||
const last = marker.cell;
|
||||
const text = formatCameraCount(cell.count);
|
||||
const width = widthForText(text);
|
||||
if (
|
||||
nextLocale === locale &&
|
||||
last?.count === cell.count &&
|
||||
last.lonSum === cell.lonSum &&
|
||||
last.latSum === cell.latSum &&
|
||||
last.heightSum === cell.heightSum
|
||||
!last ||
|
||||
last.count !== cell.count ||
|
||||
last.latSum !== cell.latSum ||
|
||||
last.lonSum !== cell.lonSum ||
|
||||
last.heightSum !== cell.heightSum
|
||||
) {
|
||||
marker.pos = cellCenter(cell);
|
||||
changed = true;
|
||||
} else if (
|
||||
last.west !== cell.west ||
|
||||
last.east !== cell.east ||
|
||||
last.south !== cell.south ||
|
||||
last.north !== cell.north ||
|
||||
last.low !== cell.low ||
|
||||
last.high !== cell.high
|
||||
) {
|
||||
changed = true;
|
||||
}
|
||||
changed ||= text !== marker.text || width !== marker.width;
|
||||
marker.cell = cell;
|
||||
marker.text = text;
|
||||
marker.width = width;
|
||||
// Paint never grows the hit buffer, even when a pan reveals every group.
|
||||
hits[i] ??= {};
|
||||
}
|
||||
markers.length = visible.length;
|
||||
// Keep the last frame pickable until the host clears its pixels.
|
||||
lane?.setActive(markers.length > 0 || hitCount > 0);
|
||||
if (changed) lane?.requestPaint();
|
||||
}
|
||||
|
||||
/** Draw at device density using the host's CSS-pixel transform and projection. */
|
||||
function paint(frame) {
|
||||
if (!markers.length) {
|
||||
// Deactivating invalidates the host, so finish the shared frame first.
|
||||
if (hitCount) queueMicrotask(deactivateIfEmpty);
|
||||
hitCount = 0;
|
||||
return;
|
||||
}
|
||||
hitCount = 0;
|
||||
const { ctx, occluder, viewProjectionMatrix: m } = frame;
|
||||
const height = COUNT_MARKER_PX;
|
||||
ctx.save();
|
||||
try {
|
||||
ctx.font = FONT;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
for (let i = 0; i < markers.length; i++) {
|
||||
const marker = markers[i];
|
||||
const { x: px, y: py, z: pz } = marker.pos;
|
||||
const w = m[3] * px + m[7] * py + m[11] * pz + m[15];
|
||||
if (!(w > 0) || (occluder && !occluder.isPointVisible(marker.pos)))
|
||||
continue;
|
||||
const x =
|
||||
(0.5 + (0.5 * (m[0] * px + m[4] * py + m[8] * pz + m[12])) / w) *
|
||||
frame.width;
|
||||
const y =
|
||||
(0.5 - (0.5 * (m[1] * px + m[5] * py + m[9] * pz + m[13])) / w) *
|
||||
frame.height;
|
||||
const rect = hits[hitCount];
|
||||
rect.x = x - marker.width / 2;
|
||||
rect.y = y - height / 2;
|
||||
rect.w = marker.width;
|
||||
rect.h = height;
|
||||
if (
|
||||
rect.x >= frame.width ||
|
||||
rect.y >= frame.height ||
|
||||
rect.x + rect.w <= 0 ||
|
||||
rect.y + rect.h <= 0 ||
|
||||
frame.overlapsHardUi(rect)
|
||||
)
|
||||
continue;
|
||||
ctx.globalAlpha = marker.focus;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(
|
||||
rect.x + 2,
|
||||
rect.y + 2,
|
||||
rect.w - 4,
|
||||
height - 4,
|
||||
height / 2 - 2,
|
||||
);
|
||||
ctx.strokeStyle = 'rgba(8, 14, 20, 0.85)';
|
||||
ctx.lineWidth = 4;
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = '#0e1720';
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = RING;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = RING;
|
||||
ctx.fillText(marker.text, x, y);
|
||||
rect.cell = marker.cell;
|
||||
hitCount++;
|
||||
}
|
||||
} finally {
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolve the topmost group actually painted at this screen position. */
|
||||
function pickedCell(point) {
|
||||
if (!point) return null;
|
||||
for (let i = hitCount - 1; i >= 0; i--) {
|
||||
const rect = hits[i];
|
||||
if (
|
||||
point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.w &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.h
|
||||
)
|
||||
continue;
|
||||
const id = `cctv-count:${index}`;
|
||||
const previous = book.item(id);
|
||||
const pos = cellCenter(cell);
|
||||
const image = imageFor(formatCameraCount(cell.count));
|
||||
const meta = previous?.meta ?? { aggregate: true, slot: index };
|
||||
meta.count = cell.count;
|
||||
writes.push({
|
||||
id,
|
||||
pos,
|
||||
image,
|
||||
meta,
|
||||
size: [image.canvas.width / 2, COUNT_MARKER_PX],
|
||||
disableDepthTest: Infinity,
|
||||
show: true,
|
||||
focus: previous?.focus,
|
||||
});
|
||||
return rect.cell;
|
||||
}
|
||||
locale = nextLocale;
|
||||
groups.length = slot;
|
||||
for (let i = slot; i < book.size; i++) {
|
||||
const item = book.item(`cctv-count:${i}`);
|
||||
if (item.show) writes.push({ ...item, show: false });
|
||||
}
|
||||
book.putMany(writes);
|
||||
if (!book.show) book.show = true;
|
||||
return null;
|
||||
}
|
||||
/** Resolve only a visible pooled billboard belonging to this layer. */
|
||||
function pickedCell(hit) {
|
||||
if (!book.show || !hit || hit.set !== book.setId) return null;
|
||||
const item = book.item(hit.id);
|
||||
return item?.show ? groups[item.meta.slot] : null;
|
||||
|
||||
/** A new group may already have arrived since the empty frame. */
|
||||
function deactivateIfEmpty() {
|
||||
if (!markers.length) lane?.setActive(false);
|
||||
}
|
||||
return { book, update, pickedCell };
|
||||
|
||||
/** Release the visible groups and clear their hit targets immediately. */
|
||||
function hide() {
|
||||
markers.length = hits.length = hitCount = 0;
|
||||
lane?.setActive(false);
|
||||
}
|
||||
|
||||
/** Unhook this viewer's painter and its font listener. */
|
||||
function dispose() {
|
||||
markers.length = hits.length = hitCount = 0;
|
||||
fonts?.removeEventListener?.('loadingdone', fontsLoaded);
|
||||
lane?.unregister();
|
||||
}
|
||||
|
||||
return {
|
||||
markers,
|
||||
update,
|
||||
pickedCell,
|
||||
hide,
|
||||
dispose,
|
||||
requestPaint: () => lane?.requestPaint(),
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
IDLE_COVERAGE_EDGE_MUTED,
|
||||
ACTIVE_COVERAGE_EDGE_DEPTHFAIL,
|
||||
IDLE_COVERAGE_COLOR,
|
||||
COUNT_MARKER_PX,
|
||||
VIEW_CELL_PX,
|
||||
VIEW_ICON_MARGIN,
|
||||
VIEW_MIN_CELL_M,
|
||||
@@ -142,12 +143,9 @@ export function createRendering({
|
||||
set.setColumns?.({ ids: [] });
|
||||
layerState._icons = createIconBook(set);
|
||||
layerState._counts = createCountMarkers(
|
||||
drawOf(viewer).icons({
|
||||
id: `cctv:${iconSets}:counts`,
|
||||
horizonCull: true,
|
||||
show: false,
|
||||
drawOrder: services.sprites?.spriteDrawOrder?.('cctv') ?? 0,
|
||||
}),
|
||||
services.overlays?.registerWorldOverlayPaintLane,
|
||||
`cctv:${iconSets}:counts`,
|
||||
refreshHorizonCulling,
|
||||
);
|
||||
return set.id;
|
||||
}
|
||||
@@ -156,7 +154,7 @@ export function createRendering({
|
||||
function destroyCameraIcons() {
|
||||
layerState._icons?.dispose();
|
||||
layerState._icons = null;
|
||||
layerState._counts?.book.dispose();
|
||||
layerState._counts?.dispose();
|
||||
layerState._counts = null;
|
||||
}
|
||||
|
||||
@@ -288,38 +286,52 @@ export function createRendering({
|
||||
let writes = 0;
|
||||
let transitioning = false;
|
||||
let activeCount = 0;
|
||||
/** Advance one icon or count billboard on the shared focus clock. */
|
||||
function apply(book, id, position) {
|
||||
const item = book?.item(id);
|
||||
if (!item) return;
|
||||
const scale = item.scale ?? 1;
|
||||
// CCTV never publishes a tracked focus target, so every icon is ambient.
|
||||
const focus = advanceSpriteFocus(item.meta, {
|
||||
// Keep hidden icons in the state/release pass so the active count cannot
|
||||
// drop while a stale dim alpha remains waiting to reappear.
|
||||
screenPosition:
|
||||
item.show === false || !position ? null : screenPositionFor(position),
|
||||
/** A changed focus factor for a camera icon or a painted count. */
|
||||
function changedFocus(owner, position, shown, width, height, current) {
|
||||
const focus = advanceSpriteFocus(owner, {
|
||||
screenPosition: shown && position ? screenPositionFor(position) : null,
|
||||
cameraDistance: position ? cameraDistanceFor(position) : Number.NaN,
|
||||
nowMs,
|
||||
target,
|
||||
params,
|
||||
spriteHalfWidthPx: item.size[0] * scale * 0.5,
|
||||
spriteHalfHeightPx: item.size[1] * scale * 0.5,
|
||||
spriteHalfWidthPx: width / 2,
|
||||
spriteHalfHeightPx: height / 2,
|
||||
});
|
||||
transitioning ||= focus.transitioning;
|
||||
if (focus.active) activeCount += 1;
|
||||
// Order-independent narrow amendment to always-visible icons: CCTV
|
||||
// contacts retain a non-zero floor while yielding near the tracked target.
|
||||
if (focusAlphaNeedsWrite(book.focus(id), focus.factor, params)) {
|
||||
book.setFocus(id, focus.factor);
|
||||
writes += 1;
|
||||
}
|
||||
if (focus.active) activeCount++;
|
||||
if (!focusAlphaNeedsWrite(current, focus.factor, params)) return null;
|
||||
writes++;
|
||||
return focus.factor;
|
||||
}
|
||||
for (const record of records || [])
|
||||
apply(icons, record.camera?.id, record.position);
|
||||
const counts = layerState._counts?.book;
|
||||
for (const id of counts?.ids() ?? [])
|
||||
apply(counts, id, counts.item(id).pos);
|
||||
for (const record of records || []) {
|
||||
const id = record.camera?.id;
|
||||
const item = icons?.item(id);
|
||||
if (!item) continue;
|
||||
const scale = item.scale ?? 1;
|
||||
const factor = changedFocus(
|
||||
item.meta,
|
||||
record.position,
|
||||
item.show !== false,
|
||||
item.size[0] * scale,
|
||||
item.size[1] * scale,
|
||||
icons.focus(id),
|
||||
);
|
||||
if (factor !== null) icons.setFocus(id, factor);
|
||||
}
|
||||
const counts = layerState._counts;
|
||||
const iconWrites = writes;
|
||||
for (const marker of counts?.markers ?? []) {
|
||||
const factor = changedFocus(
|
||||
marker,
|
||||
marker.pos,
|
||||
true,
|
||||
marker.width,
|
||||
COUNT_MARKER_PX,
|
||||
marker.focus,
|
||||
);
|
||||
if (factor !== null) marker.focus = factor;
|
||||
}
|
||||
if (writes > iconWrites) counts.requestPaint();
|
||||
return { writes, transitioning, activeCount, ran: true };
|
||||
}
|
||||
|
||||
@@ -567,7 +579,7 @@ export function createRendering({
|
||||
);
|
||||
parts.projection.clearProjectionOverlay();
|
||||
if (layerState._icons) layerState._icons.show = false;
|
||||
if (layerState._counts) layerState._counts.book.show = false;
|
||||
layerState._counts?.hide();
|
||||
parts.projection.pauseInactiveProjectionFeeds(null);
|
||||
}
|
||||
|
||||
@@ -911,6 +923,7 @@ export function createRendering({
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function pickCameraIdAt(position) {
|
||||
if (layerState._counts?.pickedCell(position)) return null;
|
||||
let hit = null;
|
||||
try {
|
||||
hit = findQuery(layerState._viewer)?.pick(position.x, position.y) ?? null;
|
||||
|
||||
@@ -120,28 +120,46 @@ test('the icons go with the viewer that drew them, whichever tears down', () =>
|
||||
const one = bindFakeDraw(first);
|
||||
const two = bindFakeDraw(second);
|
||||
const state = { _viewer: first };
|
||||
const lanes = [];
|
||||
const overlays = {
|
||||
registerWorldOverlayPaintLane(name, paint, options) {
|
||||
const lane = {
|
||||
name,
|
||||
paint,
|
||||
options,
|
||||
unregister() {
|
||||
this.disposed = true;
|
||||
},
|
||||
};
|
||||
lanes.push(lane);
|
||||
return lane;
|
||||
},
|
||||
};
|
||||
const { createCameraIcons, destroyCameraIcons } = createRendering({
|
||||
state,
|
||||
services: { focus: {} },
|
||||
services: { focus: {}, overlays },
|
||||
parts: {},
|
||||
source: {},
|
||||
});
|
||||
try {
|
||||
const old = createCameraIcons(first);
|
||||
const oldCounts = state._counts.book.setId;
|
||||
assert.equal(one.draw.sets.size, 1);
|
||||
assert.equal(lanes[0].name, 'ambient-label');
|
||||
assert.equal(lanes[0].options.target, 'shared');
|
||||
assert.equal(lanes[0].options.active, false);
|
||||
state._viewer = second;
|
||||
const current = createCameraIcons(second);
|
||||
assert.notEqual(old, current);
|
||||
assert.equal(one.draw.sets.get(old).disposed, true, 'a re-init lets go');
|
||||
assert.equal(two.draw.sets.get(current).disposed, false);
|
||||
assert.equal(one.draw.sets.get(oldCounts).disposed, true);
|
||||
const counts = two.draw.set(state._counts.book.setId);
|
||||
assert.equal(counts.spec.horizonCull, true);
|
||||
assert.equal(lanes[0].disposed, true);
|
||||
lanes[0].paint({});
|
||||
|
||||
destroyCameraIcons();
|
||||
assert.equal(two.draw.sets.get(current).disposed, true);
|
||||
assert.equal(state._icons, null);
|
||||
assert.equal(counts.disposed, true);
|
||||
assert.equal(lanes[1].disposed, true);
|
||||
lanes[1].paint({});
|
||||
assert.equal(state._counts, null);
|
||||
} finally {
|
||||
one.unbind();
|
||||
@@ -382,3 +400,35 @@ test('a pose with no perspective field of view is projected by the renderer', ()
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('hover picks the underlying camera only outside a painted count', () => {
|
||||
const viewer = {};
|
||||
const icon = { set: 'icons', id: 'camera' };
|
||||
let picks = 0;
|
||||
const unbind = bindRenderer(viewer, {
|
||||
query: {
|
||||
pick() {
|
||||
picks++;
|
||||
return icon;
|
||||
},
|
||||
},
|
||||
});
|
||||
try {
|
||||
const state = {
|
||||
_viewer: viewer,
|
||||
_counts: { pickedCell: ({ x }) => (x <= 17 ? {} : null) },
|
||||
_icons: { setId: icon.set, has: () => true },
|
||||
_recordById: new Map([[icon.id, {}]]),
|
||||
};
|
||||
const rendering = createRendering({
|
||||
state,
|
||||
services: { focus: {} },
|
||||
parts: {},
|
||||
});
|
||||
assert.equal(rendering.pickCameraIdAt({ x: 17, y: 0 }), null);
|
||||
assert.equal(picks, 0);
|
||||
assert.equal(rendering.pickCameraIdAt({ x: 18, y: 0 }), icon.id);
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
@@ -42,7 +42,8 @@ export function createSelection({
|
||||
return input.onClick((event) => {
|
||||
if (!isTrackingClickGesture(event.gesture)) return;
|
||||
const cell =
|
||||
layerState._enabled && layerState._counts?.pickedCell(event.drawHit);
|
||||
layerState._enabled &&
|
||||
layerState._counts?.pickedCell(event.screenPosition);
|
||||
if (cell) {
|
||||
parts.navigation.zoomToCell(cell);
|
||||
return;
|
||||
|
||||
@@ -72,7 +72,9 @@ test('a count click preserves the provisional opening pick until the view settle
|
||||
_viewer: viewer,
|
||||
_openingCameraProvisional: true,
|
||||
_activeCameraId: 'opening',
|
||||
_counts: { pickedCell: () => cell },
|
||||
_counts: {
|
||||
pickedCell: (point) => (point?.x === 14 && point.y === 26 ? cell : null),
|
||||
},
|
||||
};
|
||||
const parts = {};
|
||||
parts.navigation = createNavigation({ state, parts });
|
||||
@@ -87,7 +89,13 @@ test('a count click preserves the provisional opening pick until the view settle
|
||||
assert.fail('a count click reached activation or deselection');
|
||||
},
|
||||
);
|
||||
click({ drawHit: {}, gesture: { travelPx: 0, durationMs: 20 } });
|
||||
click({
|
||||
screenPosition: { x: 14, y: 26 },
|
||||
get drawHit() {
|
||||
assert.fail('the camera underneath was picked');
|
||||
},
|
||||
gesture: { travelPx: 0, durationMs: 20 },
|
||||
});
|
||||
assert.equal(flights.length, 1);
|
||||
assert.equal(state._activeCameraId, 'opening');
|
||||
assert.equal(state._openingCameraProvisional, true);
|
||||
|
||||
@@ -91,6 +91,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
||||
* @param {'off'|'on'|'viewshed'} [options.coverageMode='on'] Coverage mode.
|
||||
* @param {boolean} [options.showProjection=false] Projection visibility.
|
||||
* @param {Map<string, Object>} [options.healthById] Health rows by camera id.
|
||||
* @param {Function} [options.registerPaintLane] Receives the count painter.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
@@ -103,6 +104,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
||||
showProjection = false,
|
||||
healthById = new Map(),
|
||||
openingCameraProvisional = false,
|
||||
registerPaintLane,
|
||||
} = {}) {
|
||||
layerState._viewer = viewer;
|
||||
layerState._records = Array.isArray(records) ? records : [];
|
||||
@@ -132,10 +134,12 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
||||
// A real book (over a set that draws nothing): every record gets its
|
||||
// icon as init adds it.
|
||||
layerState._icons = createIconBook(testIconSet());
|
||||
layerState._counts = createCountMarkers({
|
||||
...testIconSet(),
|
||||
id: 'cctv:test:counts',
|
||||
});
|
||||
layerState._counts?.dispose();
|
||||
layerState._counts = createCountMarkers(
|
||||
registerPaintLane,
|
||||
'cctv:test:counts',
|
||||
parts.rendering.refreshHorizonCulling,
|
||||
);
|
||||
for (const record of layerState._records)
|
||||
if (record?.camera?.id) parts.rendering.addCameraIcon(record);
|
||||
}
|
||||
@@ -155,7 +159,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
|
||||
for (const runtime of layerState._projectionEntities)
|
||||
if (runtime?.plane) planes[runtime.plane.id] = runtime.plane;
|
||||
return {
|
||||
counts: layerState._counts?.book,
|
||||
counts: layerState._counts,
|
||||
gizmo: layerState._gizmo?.partsForTest() ?? {},
|
||||
coverage,
|
||||
planes,
|
||||
|
||||
Reference in new issue
Block a user