fix(alpr): a double-click follows a camera with its card again

Each camera was an entity, which the default renderer's double-click
followed, showing its card; a camera no longer shown, or a hidden layer,
took the follow with it. As a draw-port icon it took no part in it.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:18:51 -08:00
1 parent 37a1e1500b
commit c57a8bea83
3 files changed
+67 -1

No files matched your search

+39 -1
View File
@@ -315,7 +315,7 @@ function cameraHarness(layer = alprCamerasLayer) {
},
});
let box = { south: 30.26, west: -97.75, north: 30.28, east: -97.73 };
let click, picked;
let click, dblclick, picked;
const credits = new Set();
const viewer = {
creditDisplay: {
@@ -344,6 +344,15 @@ function cameraHarness(layer = alprCamerasLayer) {
// port follows on a tracking widget of the fake's.
trackedEntityChanged: new Cesium.Event(),
entities: {},
// The viewer's stock double-click (its follow), which the input port
// takes and runs before layers' own.
screenSpaceEventHandler: {
getInputAction: (type) =>
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
? () => {}
: undefined,
removeInputAction() {},
},
};
const ports = fakeScenePorts(viewer);
bindFakeCesiumCamera(viewer, ports);
@@ -361,6 +370,11 @@ function cameraHarness(layer = alprCamerasLayer) {
modifier === undefined
)
click = fn;
if (
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK &&
modifier === undefined
)
dblclick = fn;
return setInput.call(this, fn, type, modifier);
};
try {
@@ -409,6 +423,11 @@ function cameraHarness(layer = alprCamerasLayer) {
picked = item ? { id: { set: icons().id, id: item.id } } : undefined;
click({ position: new Cesium.Cartesian2() });
},
dblclick(id) {
const item = typeof id === 'string' ? icons()?.items.get(id) : null;
picked = item ? { id: { set: icons().id, id: item.id } } : undefined;
dblclick({ position: new Cesium.Cartesian2() });
},
restore() {
layer.destroy(viewer);
Date.now = originals.now;
@@ -1547,3 +1566,22 @@ test('ALPR display tags collapse controls and cap final text without erasing Uni
assert.equal(record.cameraType, null);
assert.equal(record.zone, 'traffic zone');
});
test('a double-click follows a camera with its card until it is no longer shown, as its entity was', async () => {
const { followedOf } = await import('./followed.js');
const h = cameraHarness();
try {
await alprCamerasLayer.update();
h.dblclick('alpr:42');
const followed = followedOf(h.viewer);
assert.ok(followed, 'the camera is followed');
assert.equal(followed.key, 'alpr:42');
assert.ok(followed.entity, 'through its entity record, for its card');
h.setFetch(async () => cameraResponse([cameraNode(43)]));
h.expire();
await alprCamerasLayer.update();
assert.equal(followedOf(h.viewer), null, 'gone: no longer followed');
} finally {
h.restore();
}
});
+4
View File
@@ -70,6 +70,8 @@ export function createAlprCamerasLayer({ source, services } = {}) {
postRenderRemove: null,
lastAnchorSampleAt: 0,
clickSubscription: null,
/** The follow a double-click on a camera started, while installed. */
stockFollow: null,
debounceTimer: null,
/** Snapped box of the last successful query; a view still inside it reuses its records. */
lastQueryBox: null,
@@ -344,6 +346,8 @@ export function createAlprCamerasLayer({ source, services } = {}) {
state.postRenderRemove = null;
state.clickSubscription?.();
state.clickSubscription = null;
state.stockFollow?.destroy();
state.stockFollow = null;
clearRendered();
state.markers.dispose();
state.credit = null;
+24
View File
@@ -1,5 +1,6 @@
import { isFollowing } from '../../data/followed.js';
import { inputFor } from '../../input/dispatcher.js';
import { followOnDoubleClick } from '../../data/stockFollow.js';
import { distance, fromDegrees, toLonLatH } from '../../geo/index.js';
import {
LAYER_ID,
@@ -322,6 +323,7 @@ export function createAlprPresentation({ state, services, source }) {
visibleRecords = [];
clampedMarkers.clear();
markers.clear();
state.stockFollow?.stop();
removeEntityContextsForLayer(LAYER_ID);
}
@@ -376,6 +378,8 @@ export function createAlprPresentation({ state, services, source }) {
if (!visibleIds.has(carrier.id)) gone.push(carrier.id);
if (gone.length) {
markers.remove(gone);
// A camera no longer shown takes its follow with it.
state.stockFollow?.retain((key) => Boolean(markers.get(key)));
for (const id of gone) clampedMarkers.delete(id);
changed = true;
}
@@ -594,6 +598,26 @@ export function createAlprPresentation({ state, services, source }) {
selectRecord(id);
else if (state.selectedId) clearSelection();
});
// A double-click follows a camera, its card shown, as the default
// renderer followed its entity.
state.stockFollow = followOnDoubleClick({
viewer,
inputFor,
name: LAYER_ID,
enabled: () => state.enabled,
targetFor: (hit) => {
const carrier = hit.set === markers.icons?.id && markers.get(hit.id);
if (!carrier) return null;
return {
key: carrier.id,
position: () => {
const at = alprIconPosition(carrier);
return at ? { ...at } : null;
},
entity: carrier,
};
},
});
}
return {
initOverlay: () => overlay.init(),