mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Merge remote-tracking branch 'origin/main' into feat/alpr-model-specs
This commit is contained in:
commit
4eacbe67c7
2602 files changed
+251040
-57704
No files matched your search
+34
-42
@@ -1,5 +1,6 @@
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { isUnavailableCapability } from '../../sources/capability.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { cameraOf, drawOf, findFrame } from '../../render/rendererOf.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
REQUEST_DEBOUNCE_MS,
|
||||
@@ -11,11 +12,14 @@ import {
|
||||
boxContains,
|
||||
alprRetryDelayMs,
|
||||
validateAlprSnapshot,
|
||||
alprCreditMarkup,
|
||||
alprCredit,
|
||||
} from './model.js';
|
||||
import { createAlprPresentation } from './presentation.js';
|
||||
import { createAlprMarkerSet } from './markerState.js';
|
||||
import { t, tn, msg } from '../../i18n/index.js';
|
||||
|
||||
let instances = 0;
|
||||
|
||||
/**
|
||||
* Own one layer's requests, records, display and viewer subscriptions.
|
||||
* A source fetches a bounded box with an AbortSignal and resolves
|
||||
@@ -41,10 +45,12 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
|
||||
const state = {
|
||||
viewer: null,
|
||||
dataSource: null,
|
||||
/** The camera markers, drawn as one icon set. */
|
||||
markers: createAlprMarkerSet(),
|
||||
credit: null,
|
||||
creditTimer: null,
|
||||
creditPresented: false,
|
||||
creditOff: null,
|
||||
enabled: false,
|
||||
records: [],
|
||||
recordById: new Map(),
|
||||
@@ -65,7 +71,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
moveEndRemove: null,
|
||||
postRenderRemove: null,
|
||||
lastAnchorSampleAt: 0,
|
||||
clickHandler: null,
|
||||
clickSubscription: null,
|
||||
debounceTimer: null,
|
||||
/** Snapped box of the last successful query; a view still inside it reuses its records. */
|
||||
lastQueryBox: null,
|
||||
@@ -184,9 +190,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
}
|
||||
renderRecords();
|
||||
state.retrying = false;
|
||||
setAlprStatus(
|
||||
state.dataSource.entities.values.length ? 'ready' : 'empty',
|
||||
);
|
||||
setAlprStatus(state.markers.size ? 'ready' : 'empty');
|
||||
return;
|
||||
}
|
||||
// A move inside an in-flight query must not abort and restart that query.
|
||||
@@ -254,13 +258,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
// Stale and saturated are independent facts; a cached response that also
|
||||
// hit the cap must still warn about coverage, not just about freshness.
|
||||
renderRecords();
|
||||
setAlprStatus(
|
||||
state.dataSource.entities.values.length
|
||||
? stale
|
||||
? 'stale'
|
||||
: 'ready'
|
||||
: 'empty',
|
||||
);
|
||||
setAlprStatus(state.markers.size ? (stale ? 'stale' : 'ready') : 'empty');
|
||||
} catch (error) {
|
||||
if (
|
||||
error?.name === 'AbortError' ||
|
||||
@@ -297,16 +295,17 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
init(viewer) {
|
||||
if (state.viewer) throw new Error('ALPR layer is already initialized');
|
||||
state.viewer = viewer;
|
||||
state.dataSource = new Cesium.CustomDataSource('alpr-cameras');
|
||||
const creditMarkup = alprCreditMarkup(source.attribution);
|
||||
state.credit = creditMarkup
|
||||
? new Cesium.Credit(creditMarkup, true)
|
||||
: null;
|
||||
viewer.dataSources.add(state.dataSource);
|
||||
state.moveEndRemove =
|
||||
viewer.camera.moveEnd.addEventListener(scheduleLoad);
|
||||
state.markers.attach(
|
||||
drawOf(viewer).icons({
|
||||
id: `${LAYER_ID}:${++instances}:markers`,
|
||||
show: state.enabled,
|
||||
}),
|
||||
);
|
||||
state.credit = alprCredit(source.attribution);
|
||||
state.moveEndRemove = cameraOf(viewer).on('moveEnd', scheduleLoad);
|
||||
state.postRenderRemove =
|
||||
viewer.scene.postRender?.addEventListener(updateSelectedAnchor);
|
||||
findFrame(viewer)?.on('postRender', () => updateSelectedAnchor()) ??
|
||||
null;
|
||||
initOverlay();
|
||||
installInteraction(viewer);
|
||||
},
|
||||
@@ -315,7 +314,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.enabled = true;
|
||||
state.creditPresented = false;
|
||||
registerPickOwner(LAYER_ID, (id) => state.recordById.has(id));
|
||||
state.dataSource.show = true;
|
||||
state.markers.icons.show = true;
|
||||
// DataLayerManager calls update() right after enable(); it owns the first fetch.
|
||||
},
|
||||
disable() {
|
||||
@@ -329,7 +328,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.pendingQueryBox = null;
|
||||
state.loading = false;
|
||||
state.retrying = false;
|
||||
if (state.dataSource) state.dataSource.show = false;
|
||||
if (state.markers.icons) state.markers.icons.show = false;
|
||||
clearSelection();
|
||||
clearRendered();
|
||||
setAlprStatus('idle');
|
||||
@@ -345,12 +344,10 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.moveEndRemove = null;
|
||||
state.postRenderRemove?.();
|
||||
state.postRenderRemove = null;
|
||||
state.clickHandler?.destroy();
|
||||
state.clickHandler = null;
|
||||
state.clickSubscription?.();
|
||||
state.clickSubscription = null;
|
||||
clearRendered();
|
||||
if (state.dataSource && viewer)
|
||||
viewer.dataSources.remove(state.dataSource, true);
|
||||
state.dataSource = null;
|
||||
state.markers.dispose();
|
||||
state.credit = null;
|
||||
state.creditPresented = false;
|
||||
state.records = [];
|
||||
@@ -365,19 +362,18 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.viewer = null;
|
||||
},
|
||||
getRowControls() {
|
||||
const count = state.dataSource?.entities.values.length || 0;
|
||||
const count = state.markers.size;
|
||||
return {
|
||||
chips: [
|
||||
{
|
||||
id: 'find-camera',
|
||||
label: t('SHOW NEAREST'),
|
||||
title: state.viewer?.trackedEntity
|
||||
title: isFollowing(state.viewer)
|
||||
? t(
|
||||
'Stop following the current object before navigating to a camera',
|
||||
)
|
||||
: t('Move to the nearest loaded camera and show its details'),
|
||||
disabled:
|
||||
!state.enabled || !count || Boolean(state.viewer?.trackedEntity),
|
||||
disabled: !state.enabled || !count || isFollowing(state.viewer),
|
||||
onClick: focusNearest,
|
||||
},
|
||||
],
|
||||
@@ -426,21 +422,17 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
},
|
||||
getStats() {
|
||||
return {
|
||||
count: state.dataSource?.entities.values.length || 0,
|
||||
count: state.markers.size,
|
||||
countLabel:
|
||||
state.enabled && !state.noCoverage && state.status !== 'zoom-in'
|
||||
? Number.isInteger(state.onScreen)
|
||||
? tn(
|
||||
state.dataSource?.entities.values.length || 0,
|
||||
state.markers.size,
|
||||
'{count} nearby · {onScreen} on screen',
|
||||
'{count} nearby · {onScreen} on screen',
|
||||
{ onScreen: state.onScreen },
|
||||
)
|
||||
: tn(
|
||||
state.dataSource?.entities.values.length || 0,
|
||||
'{count} nearby',
|
||||
'{count} nearby',
|
||||
)
|
||||
: tn(state.markers.size, '{count} nearby', '{count} nearby')
|
||||
: '',
|
||||
noCoverage: Boolean(state.noCoverage),
|
||||
lastUpdate: state.lastUpdate,
|
||||
@@ -448,7 +440,7 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
saturated: state.saturated || state.renderSaturated,
|
||||
renderRevision: state.renderRevision,
|
||||
onScreen: state.onScreen ?? null,
|
||||
shown: state.dataSource?.entities.values.length || 0,
|
||||
shown: state.markers.size,
|
||||
error: state.error,
|
||||
status: state.status,
|
||||
loading: state.loading,
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* @module alpr/markerState
|
||||
* @description The ALPR layer's markers: one icon per camera in a draw set,
|
||||
* and the layer's own per-marker state, held in the layer. Each marker is a
|
||||
* plain carrier object (`{ id, show }`) that the layer registers as the
|
||||
* camera's context entity; its state lives in `alprMarkers`:
|
||||
* - `record`: the camera record the marker shows.
|
||||
* - `position`, `clamped`: where the badge is drawn natively, and whether it
|
||||
* follows the ground there rather than sitting at its height.
|
||||
* - `selected`: drawn with the selected badge.
|
||||
* - `canvasPosition`, `displayPosition`: the canvas anchor and the position the card reads.
|
||||
* - `wedge`: the direction wedge's positions, plain ECEF.
|
||||
* - `canvasOwned`: the overlay canvas draws the badge; the icon stays as a
|
||||
* faint pick target at the canvas anchor.
|
||||
* - `shown`, `surfaceCheckedFor`: whether the icon shows and the anchor last checked.
|
||||
*/
|
||||
import { createEntityStore } from '../../data/entityRecords.js';
|
||||
import {
|
||||
MARKER_ICON_SIZE,
|
||||
MARKER_SCALE_BY_DISTANCE,
|
||||
SELECTED_MARKER_ICON_SIZE,
|
||||
} from './policy.js';
|
||||
import { MARKER_IMAGE, SELECTED_IMAGE } from './visuals.js';
|
||||
|
||||
export const alprMarkers = createEntityStore();
|
||||
|
||||
const [NEAR, NEAR_SCALE, FAR, FAR_SCALE] = MARKER_SCALE_BY_DISTANCE;
|
||||
/** City-wide views hold hundreds of badges; they shrink with distance. */
|
||||
const SCALE_BY_DISTANCE = Object.freeze({
|
||||
near: NEAR,
|
||||
nearValue: NEAR_SCALE,
|
||||
far: FAR,
|
||||
farValue: FAR_SCALE,
|
||||
});
|
||||
/** Under the canvas badge: faint, but still picked. */
|
||||
const PICK_TARGET_COLOR = Object.freeze([1, 1, 1, 0.01]);
|
||||
|
||||
/**
|
||||
* Where a marker's icon is drawn: the canvas anchor while the canvas owns
|
||||
* it, else its native position.
|
||||
* @param {{id: string}} carrier
|
||||
* @returns {import('../../render/contract/common').Ecef|null|undefined}
|
||||
*/
|
||||
export function alprIconPosition(carrier) {
|
||||
const marker = alprMarkers.read(carrier);
|
||||
if (!marker) return null;
|
||||
return marker.canvasOwned && marker.canvasPosition
|
||||
? marker.canvasPosition
|
||||
: marker.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* The icon a marker draws now.
|
||||
* @param {{id: string}} carrier
|
||||
* @returns {import('../../render/contract/draw').IconItem}
|
||||
*/
|
||||
export function alprIconItem(carrier) {
|
||||
const marker = alprMarkers.read(carrier) ?? {};
|
||||
const canvas = Boolean(marker.canvasOwned && marker.canvasPosition);
|
||||
const size = marker.selected ? SELECTED_MARKER_ICON_SIZE : MARKER_ICON_SIZE;
|
||||
return {
|
||||
id: carrier.id,
|
||||
pos: canvas ? marker.canvasPosition : marker.position,
|
||||
// Ground clamping is the placeholder until a marker's floor resolves.
|
||||
height: !canvas && marker.clamped ? 'clampGround' : 'absolute',
|
||||
image: marker.selected ? SELECTED_IMAGE : MARKER_IMAGE,
|
||||
size: [size, size],
|
||||
disableDepthTest: Number.POSITIVE_INFINITY,
|
||||
show: marker.shown !== false,
|
||||
// The context carrier: what a pick hands to point-and-ask.
|
||||
meta: carrier,
|
||||
...(canvas
|
||||
? { color: PICK_TARGET_COLOR }
|
||||
: { scaleByDistance: SCALE_BY_DISTANCE }),
|
||||
};
|
||||
}
|
||||
|
||||
/** What tells one drawn icon from another, so unchanged ones are not sent again. */
|
||||
function itemKey(item) {
|
||||
const { pos } = item;
|
||||
return [
|
||||
pos?.x,
|
||||
pos?.y,
|
||||
pos?.z,
|
||||
item.height,
|
||||
item.image,
|
||||
item.size[0],
|
||||
item.show,
|
||||
item.color ? 'pick' : 'badge',
|
||||
].join('|');
|
||||
}
|
||||
|
||||
/**
|
||||
* The layer's markers, drawn as one icon set: carriers by camera id, and
|
||||
* the writes to the set, batched until `flush`.
|
||||
* @returns {object}
|
||||
*/
|
||||
export function createAlprMarkerSet() {
|
||||
const carriers = new Map();
|
||||
/** The key of each icon last sent to the set, by id. */
|
||||
const sent = new Map();
|
||||
const dirty = new Set();
|
||||
let icons = null;
|
||||
|
||||
function flush() {
|
||||
if (!icons || !dirty.size) return;
|
||||
const items = [];
|
||||
for (const carrier of dirty) {
|
||||
if (carriers.get(carrier.id) !== carrier) continue;
|
||||
const item = alprIconItem(carrier);
|
||||
if (!item.pos) continue;
|
||||
const key = itemKey(item);
|
||||
if (sent.get(carrier.id) === key) continue;
|
||||
sent.set(carrier.id, key);
|
||||
items.push(item);
|
||||
}
|
||||
dirty.clear();
|
||||
if (items.length) icons.upsert(items);
|
||||
}
|
||||
|
||||
return {
|
||||
/** Draw the markers into `set`, an icon set made for them. */
|
||||
attach(set) {
|
||||
icons = set;
|
||||
},
|
||||
/** The icon set, while attached. */
|
||||
get icons() {
|
||||
return icons;
|
||||
},
|
||||
get size() {
|
||||
return carriers.size;
|
||||
},
|
||||
get(id) {
|
||||
return carriers.get(id) ?? null;
|
||||
},
|
||||
values() {
|
||||
return carriers.values();
|
||||
},
|
||||
/** A new marker for `id`, drawn at the next `flush`. */
|
||||
add(id) {
|
||||
const carrier = { id, show: true };
|
||||
carriers.set(id, carrier);
|
||||
dirty.add(carrier);
|
||||
return carrier;
|
||||
},
|
||||
/** Remove the markers with these ids now. */
|
||||
remove(ids) {
|
||||
const gone = [];
|
||||
for (const id of ids) {
|
||||
if (!carriers.delete(id)) continue;
|
||||
sent.delete(id);
|
||||
gone.push(id);
|
||||
}
|
||||
if (gone.length) icons?.remove(gone);
|
||||
},
|
||||
/** Redraw `carrier` at the next `flush`, if how it draws changed. */
|
||||
changed(carrier) {
|
||||
if (carrier) dirty.add(carrier);
|
||||
},
|
||||
flush,
|
||||
clear() {
|
||||
carriers.clear();
|
||||
sent.clear();
|
||||
dirty.clear();
|
||||
icons?.clear();
|
||||
},
|
||||
dispose() {
|
||||
carriers.clear();
|
||||
sent.clear();
|
||||
dirty.clear();
|
||||
icons?.dispose();
|
||||
icons = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
+13
-21
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { toDegrees, toRadians } from '../../geo/index.js';
|
||||
import { EARTH_MEAN_RADIUS_M } from './policy.js';
|
||||
export * from './records.js';
|
||||
|
||||
@@ -12,9 +12,9 @@ export * from './records.js';
|
||||
*/
|
||||
export function destinationPointDeg(latDeg, lonDeg, bearingDeg, distanceM) {
|
||||
const angularDistance = distanceM / EARTH_MEAN_RADIUS_M;
|
||||
const bearing = Cesium.Math.toRadians(bearingDeg);
|
||||
const lat1 = Cesium.Math.toRadians(latDeg);
|
||||
const lon1 = Cesium.Math.toRadians(lonDeg);
|
||||
const bearing = toRadians(bearingDeg);
|
||||
const lat1 = toRadians(latDeg);
|
||||
const lon1 = toRadians(lonDeg);
|
||||
const lat2 = Math.asin(
|
||||
Math.sin(lat1) * Math.cos(angularDistance) +
|
||||
Math.cos(lat1) * Math.sin(angularDistance) * Math.cos(bearing),
|
||||
@@ -26,29 +26,21 @@ export function destinationPointDeg(latDeg, lonDeg, bearingDeg, distanceM) {
|
||||
Math.cos(angularDistance) - Math.sin(lat1) * Math.sin(lat2),
|
||||
);
|
||||
return {
|
||||
latitude: Cesium.Math.toDegrees(lat2),
|
||||
longitude: Cesium.Math.toDegrees(lon2),
|
||||
latitude: toDegrees(lat2),
|
||||
longitude: toDegrees(lon2),
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a linked attribution from plain text and an HTTPS URL only. */
|
||||
export function alprCreditMarkup(attribution) {
|
||||
/**
|
||||
* The on-map credit for the renderer's credits port, from plain text and an
|
||||
* HTTPS URL only; the port escapes it as it shows it.
|
||||
* @returns {{text: string, href: string, inline: true}|null}
|
||||
*/
|
||||
export function alprCredit(attribution) {
|
||||
if (!attribution?.text || !attribution?.href) return null;
|
||||
const href = new URL(attribution.href);
|
||||
if (href.protocol !== 'https:' || href.username || href.password) {
|
||||
throw new TypeError('Camera attribution requires a public HTTPS link');
|
||||
}
|
||||
const escape = (value) =>
|
||||
String(value).replace(
|
||||
/[&<>"']/g,
|
||||
(char) =>
|
||||
({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
})[char],
|
||||
);
|
||||
return `<span class="gev-alpr-credit">ALPR: <a href="${escape(href.href)}" target="_blank" rel="noopener">${escape(attribution.text)}</a></span>`;
|
||||
return { text: `ALPR: ${attribution.text}`, href: href.href, inline: true };
|
||||
}
|
||||
+145
-163
@@ -1,4 +1,3 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
MAX_CANVAS_FRUSTUMS,
|
||||
MARKER_ICON_SIZE,
|
||||
@@ -18,8 +17,19 @@ import {
|
||||
paintDirectionWedge,
|
||||
validAlprGroundHeight,
|
||||
} from './visuals.js';
|
||||
import { alprMarkers } from './markerState.js';
|
||||
import { distance, fromDegrees, toLonLatH } from '../../geo/index.js';
|
||||
import { cameraOf, findQuery, rendererOf } from '../../render/rendererOf.js';
|
||||
|
||||
/** Per-layer presentation on a caller-owned overlay; Cesium remains the fallback. */
|
||||
let lanes = 0;
|
||||
|
||||
/** Within `epsilon` on every axis. */
|
||||
const near = (a, b, epsilon) =>
|
||||
Math.abs(a.x - b.x) <= epsilon &&
|
||||
Math.abs(a.y - b.y) <= epsilon &&
|
||||
Math.abs(a.z - b.z) <= epsilon;
|
||||
|
||||
/** Per-layer presentation on a caller-owned overlay; the icon set remains the fallback. */
|
||||
export function createAlprOverlay({
|
||||
state,
|
||||
services,
|
||||
@@ -38,72 +48,55 @@ export function createAlprOverlay({
|
||||
if (!destroyed && state.enabled) lane?.requestPaint();
|
||||
};
|
||||
|
||||
function nativeVisible(entity, visible) {
|
||||
if (!entity) return;
|
||||
canvasOwned(entity, !visible);
|
||||
setShown(entity, visible);
|
||||
const markers = state.markers;
|
||||
|
||||
function nativeVisible(carrier, visible) {
|
||||
if (!carrier) return;
|
||||
canvasOwned(carrier, !visible);
|
||||
setShown(carrier, visible);
|
||||
}
|
||||
|
||||
/** Swap a marker between its native look and a faint canvas pick target. */
|
||||
function canvasOwned(entity, owned) {
|
||||
const visible = !owned;
|
||||
const billboard = entity.billboard;
|
||||
// Keep a faint native pick target under the canvas badge so sibling layer
|
||||
// handlers recognize ALPR ownership instead of treating the click as empty.
|
||||
if (!visible && !entity.gevAlprNativeAppearance) {
|
||||
entity.gevAlprNativeAppearance = {
|
||||
position: entity.position,
|
||||
heightReference: billboard.heightReference,
|
||||
scaleByDistance: billboard.scaleByDistance,
|
||||
color: billboard.color,
|
||||
};
|
||||
entity.position = entity.gevAlprCanvasPosition;
|
||||
entity.gevAlprPickPosition = entity.position;
|
||||
billboard.heightReference = Cesium.HeightReference.NONE;
|
||||
billboard.scaleByDistance = undefined;
|
||||
billboard.color = Cesium.Color.WHITE.withAlpha(0.01);
|
||||
} else if (visible && entity.gevAlprNativeAppearance) {
|
||||
const saved = entity.gevAlprNativeAppearance;
|
||||
if (entity.position === entity.gevAlprPickPosition)
|
||||
entity.position = saved.position;
|
||||
billboard.heightReference = saved.heightReference;
|
||||
billboard.scaleByDistance = saved.scaleByDistance;
|
||||
billboard.color = saved.color;
|
||||
entity.gevAlprNativeAppearance = null;
|
||||
entity.gevAlprPickPosition = null;
|
||||
}
|
||||
/**
|
||||
* Swap a marker between its native look and a faint canvas pick target.
|
||||
* The faint icon stays under the canvas badge, at its anchor, so sibling
|
||||
* layer handlers recognize ALPR ownership instead of treating the click
|
||||
* as empty.
|
||||
*/
|
||||
function canvasOwned(carrier, owned) {
|
||||
const marker = alprMarkers.write(carrier);
|
||||
if (Boolean(marker.canvasOwned) === owned) return;
|
||||
marker.canvasOwned = owned;
|
||||
markers.changed(carrier);
|
||||
}
|
||||
|
||||
// Assign only on change: each Entity property write mints a new property
|
||||
// and raises definitionChanged, which paint used to do for every overlay
|
||||
// camera on every frame.
|
||||
function setShown(entity, visible) {
|
||||
if (entity.gevAlprShown === visible) return;
|
||||
entity.gevAlprShown = visible;
|
||||
entity.billboard.show = visible;
|
||||
if (entity.polyline) entity.polyline.show = visible;
|
||||
if (entity.polygon) entity.polygon.show = visible;
|
||||
// Changed only on change: the icon is sent again only when it draws
|
||||
// differently.
|
||||
function setShown(carrier, visible) {
|
||||
const marker = alprMarkers.write(carrier);
|
||||
if ((marker.shown ?? true) === visible) return;
|
||||
marker.shown = visible;
|
||||
markers.changed(carrier);
|
||||
}
|
||||
|
||||
function resetAnchors() {
|
||||
for (const entity of state.dataSource.entities.values) {
|
||||
entity.gevAlprCanvasPosition = null;
|
||||
entity.gevAlprWedge = null;
|
||||
entity.gevAlprDisplayPosition = null;
|
||||
nativeVisible(entity, true);
|
||||
for (const carrier of markers.values()) {
|
||||
const marker = alprMarkers.write(carrier);
|
||||
marker.canvasPosition = null;
|
||||
marker.wedge = null;
|
||||
marker.displayPosition = null;
|
||||
nativeVisible(carrier, true);
|
||||
}
|
||||
markers.flush();
|
||||
state.lastAnchorSampleAt = 0;
|
||||
retryUntil = Date.now() + 15000;
|
||||
requestPaint();
|
||||
}
|
||||
|
||||
function anchorFor(record, entity, budget) {
|
||||
if (entity.gevAlprCanvasPosition) return entity.gevAlprCanvasPosition;
|
||||
const scene = state.viewer.scene;
|
||||
const location = Cesium.Cartographic.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
);
|
||||
function anchorFor(record, carrier, budget) {
|
||||
const cached = alprMarkers.read(carrier)?.canvasPosition;
|
||||
if (cached) return cached;
|
||||
const query = findQuery(state.viewer);
|
||||
const point = { lon: record.longitude, lat: record.latitude };
|
||||
// A floor-placed marker anchors where its native badge sits; only a
|
||||
// marker still waiting for its floor samples the rendered surface, and
|
||||
// each paint samples a few at most (each sample is a depth render).
|
||||
@@ -113,20 +106,34 @@ export function createAlprOverlay({
|
||||
record.longitude,
|
||||
);
|
||||
if (validAlprGroundHeight(floor)) height = floor + MARKER_FLOOR_LIFT_M;
|
||||
else if (scene.sampleHeightSupported) {
|
||||
else if (query && canSampleHeight()) {
|
||||
if (budget.samples <= 0) return null;
|
||||
budget.samples -= 1;
|
||||
try {
|
||||
height = scene.sampleHeight(location, [entity]);
|
||||
} catch {
|
||||
/* streaming tiles */
|
||||
}
|
||||
// A miss is tiles still streaming.
|
||||
height = query.sampleHeightNow(point, { exclude: [markers.icons?.id] });
|
||||
}
|
||||
if (!validAlprGroundHeight(height) && scene.globe.show)
|
||||
height = scene.globe.getHeight?.(location);
|
||||
// The globe's terrain, while the globe is drawn (hidden under photoreal
|
||||
// tiles, its height is not what shows).
|
||||
if (!validAlprGroundHeight(height) && globeShown())
|
||||
height = query?.sampleHeightNow(point, { against: 'terrain' });
|
||||
if (!validAlprGroundHeight(height)) return null;
|
||||
setAnchor(record, entity, height);
|
||||
return entity.gevAlprCanvasPosition;
|
||||
setAnchor(record, carrier, height);
|
||||
return alprMarkers.read(carrier)?.canvasPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the renderer samples the drawn surface's height (Cesium needs
|
||||
* depth textures). Without, nothing is sampled or spent from the budget,
|
||||
* and a marker with no floor yet anchors on the terrain.
|
||||
*/
|
||||
function canSampleHeight() {
|
||||
const capabilities = rendererOf(state.viewer)?.capabilities;
|
||||
return !capabilities || capabilities.has('sampleHeight');
|
||||
}
|
||||
|
||||
/** Whether the globe surface is drawn; true where the renderer cannot say. */
|
||||
function globeShown() {
|
||||
return rendererOf(state.viewer)?.globe?.isGlobeVisible?.() !== false;
|
||||
}
|
||||
|
||||
function floorHeightAt(latitude, longitude) {
|
||||
@@ -134,27 +141,24 @@ export function createAlprOverlay({
|
||||
return validAlprGroundHeight(floor) ? floor + MARKER_FLOOR_LIFT_M : null;
|
||||
}
|
||||
|
||||
function setAnchor(record, entity, height) {
|
||||
entity.gevAlprCanvasPosition = Cesium.Cartesian3.fromDegrees(
|
||||
function setAnchor(record, carrier, height) {
|
||||
const marker = alprMarkers.write(carrier);
|
||||
marker.canvasPosition = fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
height,
|
||||
);
|
||||
entity.gevAlprWedge = directionWedgePositions(
|
||||
record,
|
||||
height,
|
||||
floorHeightAt,
|
||||
);
|
||||
marker.wedge = directionWedgePositions(record, height, floorHeightAt);
|
||||
if (marker.canvasOwned) markers.changed(carrier);
|
||||
}
|
||||
|
||||
/** Whether the visible photoreal tiles (or globe) have finished streaming. */
|
||||
function surfaceSettled(scene) {
|
||||
if (scene.globe?.show) return scene.globe.tilesLoaded !== false;
|
||||
for (let i = 0; i < (scene.primitives?.length || 0); i++) {
|
||||
const primitive = scene.primitives.get(i);
|
||||
if (primitive?.show && primitive.tilesLoaded === false) return false;
|
||||
}
|
||||
return true;
|
||||
function surfaceSettled() {
|
||||
const globe = rendererOf(state.viewer)?.globe;
|
||||
// The globe's terrain while it is shown, otherwise the shown 3D tiles.
|
||||
// A viewer with no renderer of its own cannot say; its samples are
|
||||
// still checked against the floor.
|
||||
return !globe || globe.isSettled('surface');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,50 +169,34 @@ export function createAlprOverlay({
|
||||
* samples far outside the floor prior (a roof or a streaming tile) are
|
||||
* rejected. Returns whether anchors remain to check.
|
||||
*/
|
||||
function refineAnchors(budget) {
|
||||
const camera = state.viewer.camera;
|
||||
const scene = state.viewer.scene;
|
||||
function refineAnchors(budget, pose) {
|
||||
const still =
|
||||
lastCamera &&
|
||||
camera.positionWC &&
|
||||
Cesium.Cartesian3.equalsEpsilon(
|
||||
camera.positionWC,
|
||||
lastCamera.position,
|
||||
0,
|
||||
0.05,
|
||||
) &&
|
||||
Cesium.Cartesian3.equalsEpsilon(
|
||||
camera.directionWC,
|
||||
lastCamera.direction,
|
||||
0,
|
||||
1e-6,
|
||||
);
|
||||
if (camera.positionWC && camera.directionWC)
|
||||
lastCamera = {
|
||||
position: Cesium.Cartesian3.clone(camera.positionWC),
|
||||
direction: Cesium.Cartesian3.clone(camera.directionWC),
|
||||
};
|
||||
if (!scene.sampleHeightSupported) return false;
|
||||
near(pose.position, lastCamera.position, 0.05) &&
|
||||
near(pose.direction, lastCamera.direction, 1e-6);
|
||||
lastCamera = {
|
||||
position: { ...pose.position },
|
||||
direction: { ...pose.direction },
|
||||
};
|
||||
const query = findQuery(state.viewer);
|
||||
if (!query || !canSampleHeight()) return false;
|
||||
let pending = false;
|
||||
for (const record of records) {
|
||||
const entity = state.dataSource.entities.getById(record.id);
|
||||
const anchor = entity?.gevAlprCanvasPosition;
|
||||
if (!anchor || entity.gevAlprSurfaceCheckedFor === anchor) continue;
|
||||
if (!still || !surfaceSettled(scene) || budget.samples <= 0) {
|
||||
const carrier = markers.get(record.id);
|
||||
const marker = alprMarkers.read(carrier);
|
||||
const anchor = marker?.canvasPosition;
|
||||
if (!anchor || marker.surfaceCheckedFor === anchor) continue;
|
||||
if (!still || !surfaceSettled() || budget.samples <= 0) {
|
||||
pending = true;
|
||||
continue;
|
||||
}
|
||||
budget.samples -= 1;
|
||||
let sample;
|
||||
try {
|
||||
sample = scene.sampleHeight(
|
||||
Cesium.Cartographic.fromDegrees(record.longitude, record.latitude),
|
||||
[entity],
|
||||
);
|
||||
} catch {
|
||||
/* streaming tiles */
|
||||
}
|
||||
const current = Cesium.Cartographic.fromCartesian(anchor).height;
|
||||
// A miss is tiles still streaming.
|
||||
const sample = query.sampleHeightNow(
|
||||
{ lon: record.longitude, lat: record.latitude },
|
||||
{ exclude: [markers.icons?.id] },
|
||||
);
|
||||
const current = toLonLatH(anchor)?.height;
|
||||
const floor = services.groundFloor.cachedGroundFloor(
|
||||
record.latitude,
|
||||
record.longitude,
|
||||
@@ -219,10 +207,11 @@ export function createAlprOverlay({
|
||||
(sample >= floor - SURFACE_BELOW_FLOOR_M &&
|
||||
sample <= floor + SURFACE_ABOVE_FLOOR_M));
|
||||
if (accepted && Math.abs(sample + MARKER_FLOOR_LIFT_M - current) > 1)
|
||||
setAnchor(record, entity, sample + MARKER_FLOOR_LIFT_M);
|
||||
entity.gevAlprSurfaceCheckedFor = entity.gevAlprCanvasPosition;
|
||||
if (entity.id === state.selectedId)
|
||||
entity.gevAlprDisplayPosition = entity.gevAlprCanvasPosition;
|
||||
setAnchor(record, carrier, sample + MARKER_FLOOR_LIFT_M);
|
||||
// setAnchor rewrote the same record, so this is the new anchor.
|
||||
marker.surfaceCheckedFor = marker.canvasPosition;
|
||||
if (carrier.id === state.selectedId)
|
||||
marker.displayPosition = marker.canvasPosition;
|
||||
}
|
||||
return pending;
|
||||
}
|
||||
@@ -233,9 +222,11 @@ export function createAlprOverlay({
|
||||
let unresolved = false;
|
||||
const painted = [];
|
||||
const budget = { samples: ANCHOR_SAMPLES_PER_PAINT };
|
||||
const pose = cameraOf(state.viewer).pose();
|
||||
const query = findQuery(state.viewer);
|
||||
for (const record of records) {
|
||||
const entity = state.dataSource.entities.getById(record.id);
|
||||
if (!entity) continue;
|
||||
const carrier = markers.get(record.id);
|
||||
if (!carrier) continue;
|
||||
const selected = record.id === state.selectedId;
|
||||
const image = images[selected ? 1 : 0];
|
||||
if (
|
||||
@@ -243,45 +234,35 @@ export function createAlprOverlay({
|
||||
!image.naturalWidth ||
|
||||
(selected && !images[2]?.naturalWidth)
|
||||
) {
|
||||
nativeVisible(entity, true);
|
||||
nativeVisible(carrier, true);
|
||||
continue;
|
||||
}
|
||||
const anchor = anchorFor(record, entity, budget);
|
||||
const anchor = anchorFor(record, carrier, budget);
|
||||
if (!anchor) {
|
||||
nativeVisible(entity, true);
|
||||
nativeVisible(carrier, true);
|
||||
unresolved = true;
|
||||
continue;
|
||||
}
|
||||
canvasOwned(entity, true);
|
||||
canvasOwned(carrier, true);
|
||||
if (occluder && !occluder.isPointVisible(anchor)) {
|
||||
setShown(entity, false);
|
||||
setShown(carrier, false);
|
||||
continue;
|
||||
}
|
||||
const scene = state.viewer.scene;
|
||||
const origin = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
anchor,
|
||||
);
|
||||
const origin = query?.project(anchor);
|
||||
if (!origin) {
|
||||
setShown(entity, false);
|
||||
setShown(carrier, false);
|
||||
continue;
|
||||
}
|
||||
const alpha =
|
||||
services.overlays.keyholeAlpha?.(origin.x, origin.y, keyhole) ?? 1;
|
||||
if (!(alpha > 0)) {
|
||||
setShown(entity, false);
|
||||
setShown(carrier, false);
|
||||
continue;
|
||||
}
|
||||
const wedge = entity.gevAlprWedge;
|
||||
const wedge = alprMarkers.read(carrier)?.wedge;
|
||||
if (wedge) {
|
||||
const left = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
wedge[1],
|
||||
);
|
||||
const right = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
wedge[2],
|
||||
);
|
||||
const left = query.project(wedge[1]);
|
||||
const right = query.project(wedge[2]);
|
||||
if (left && right) {
|
||||
ctx.save();
|
||||
ctx.globalAlpha *= alpha;
|
||||
@@ -295,21 +276,19 @@ export function createAlprOverlay({
|
||||
origin.y < -60 ||
|
||||
origin.y > height + 60
|
||||
) {
|
||||
setShown(entity, false);
|
||||
setShown(carrier, false);
|
||||
continue;
|
||||
}
|
||||
setShown(entity, true);
|
||||
setShown(carrier, true);
|
||||
painted.push({
|
||||
record,
|
||||
origin,
|
||||
selected,
|
||||
image,
|
||||
alpha,
|
||||
scale: markerScale(
|
||||
Cesium.Cartesian3.distance(state.viewer.camera.positionWC, anchor),
|
||||
),
|
||||
scale: markerScale(distance(pose.position, anchor)),
|
||||
});
|
||||
if (selected) entity.gevAlprDisplayPosition = anchor;
|
||||
if (selected) alprMarkers.write(carrier).displayPosition = anchor;
|
||||
}
|
||||
// Paint all glyphs after the wedges so one camera's cone cannot wash out another.
|
||||
for (const { record, origin, selected, image, alpha, scale } of painted) {
|
||||
@@ -335,9 +314,11 @@ export function createAlprOverlay({
|
||||
ctx.restore();
|
||||
hits.push({ id: record.id, x: origin.x, y: origin.y, radius: size / 2 });
|
||||
}
|
||||
const refining = refineAnchors({
|
||||
samples: Math.min(budget.samples, SURFACE_SAMPLES_PER_PAINT),
|
||||
});
|
||||
const refining = refineAnchors(
|
||||
{ samples: Math.min(budget.samples, SURFACE_SAMPLES_PER_PAINT) },
|
||||
pose,
|
||||
);
|
||||
markers.flush();
|
||||
if ((unresolved || refining) && !retryTimer && Date.now() < retryUntil) {
|
||||
retryTimer = setTimeout(() => {
|
||||
retryTimer = null;
|
||||
@@ -358,7 +339,7 @@ export function createAlprOverlay({
|
||||
if (!services.overlays?.registerPaintLane || typeof Image === 'undefined')
|
||||
return;
|
||||
lane = services.overlays.registerPaintLane('selected', paint, {
|
||||
id: `alpr-${Cesium.createGuid()}`,
|
||||
id: `alpr-${++lanes}`,
|
||||
active: false,
|
||||
});
|
||||
images = [MARKER_IMAGE, SELECTED_IMAGE, BRACKETS_IMAGE].map((src) => {
|
||||
@@ -371,9 +352,8 @@ export function createAlprOverlay({
|
||||
},
|
||||
sync(visible) {
|
||||
if (!lane) return;
|
||||
for (const record of records)
|
||||
nativeVisible(state.dataSource.entities.getById(record.id), true);
|
||||
const position = state.viewer.camera.positionWC;
|
||||
const previous = records;
|
||||
const position = cameraOf(state.viewer).pose().position;
|
||||
records = visible
|
||||
.filter(
|
||||
(record) =>
|
||||
@@ -383,13 +363,10 @@ export function createAlprOverlay({
|
||||
.map((record) => ({
|
||||
record,
|
||||
distance: position
|
||||
? Cesium.Cartesian3.distanceSquared(
|
||||
? distance(
|
||||
position,
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
),
|
||||
)
|
||||
fromDegrees(record.longitude, record.latitude),
|
||||
) ** 2
|
||||
: 0,
|
||||
}))
|
||||
.sort((a, b) => a.distance - b.distance)
|
||||
@@ -400,6 +377,11 @@ export function createAlprOverlay({
|
||||
if (records.length >= MAX_CANVAS_FRUSTUMS) records.pop();
|
||||
records.push(selected);
|
||||
}
|
||||
// Cameras that leave the cohort go native; those that stay keep the
|
||||
// canvas until the next paint, so their icons are not written twice.
|
||||
const kept = new Set(records.map((record) => record.id));
|
||||
for (const record of previous)
|
||||
if (!kept.has(record.id)) nativeVisible(markers.get(record.id), true);
|
||||
hits = [];
|
||||
retryUntil = Date.now() + 15000;
|
||||
lane.setActive(state.enabled && records.length > 0);
|
||||
@@ -421,8 +403,8 @@ export function createAlprOverlay({
|
||||
clear() {
|
||||
clearTimeout(retryTimer);
|
||||
retryTimer = null;
|
||||
for (const record of records)
|
||||
nativeVisible(state.dataSource?.entities.getById(record.id), true);
|
||||
for (const record of records) nativeVisible(markers.get(record.id), true);
|
||||
markers.flush();
|
||||
records = [];
|
||||
hits = [];
|
||||
lane?.setActive(false);
|
||||
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
alprLabelDetails,
|
||||
markerScale,
|
||||
} from './visuals.js';
|
||||
import { alprMarkers, createAlprMarkerSet } from './markerState.js';
|
||||
import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
import { rendererOf } from '../../render/rendererOf.js';
|
||||
|
||||
function harness(t, count = 2, { floor = null } = {}) {
|
||||
const previousImage = globalThis.Image;
|
||||
@@ -23,23 +27,29 @@ function harness(t, count = 2, { floor = null } = {}) {
|
||||
longitude: -97,
|
||||
directionDeg: 90,
|
||||
}));
|
||||
const entities = new Cesium.EntityCollection();
|
||||
const drawPort = fakeDrawPort();
|
||||
const markers = createAlprMarkerSet();
|
||||
markers.attach(drawPort.icons({ id: 'alpr-cameras:test:markers' }));
|
||||
const iconSet = drawPort.set('alpr-cameras:test:markers');
|
||||
for (const record of records)
|
||||
entities.add({
|
||||
id: record.id,
|
||||
billboard: { image: 'fallback', show: true },
|
||||
polyline: { show: true },
|
||||
polygon: { show: true },
|
||||
Object.assign(alprMarkers.write(markers.add(record.id)), {
|
||||
record,
|
||||
position: Cesium.Cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
),
|
||||
});
|
||||
markers.flush();
|
||||
const state = {
|
||||
enabled: true,
|
||||
selectedId: null,
|
||||
dataSource: { entities },
|
||||
markers,
|
||||
viewer: {
|
||||
camera: { positionWC: Cesium.Cartesian3.fromDegrees(-97, 30, 500) },
|
||||
scene: { globe: { show: true, getHeight: () => 150 } },
|
||||
},
|
||||
};
|
||||
const { unbind } = bindFakeCesiumScene(state.viewer, { draw: drawPort });
|
||||
let paint,
|
||||
mapListener,
|
||||
active,
|
||||
@@ -80,6 +90,7 @@ function harness(t, count = 2, { floor = null } = {}) {
|
||||
if (previousImage === undefined) delete globalThis.Image;
|
||||
else globalThis.Image = previousImage;
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = project;
|
||||
unbind();
|
||||
});
|
||||
const draw = [];
|
||||
const ctx = {
|
||||
@@ -103,7 +114,11 @@ function harness(t, count = 2, { floor = null } = {}) {
|
||||
state,
|
||||
records,
|
||||
overlay,
|
||||
entities,
|
||||
markers,
|
||||
iconSet,
|
||||
/** A marker's carrier, and the icon last sent for it. */
|
||||
carrier: (id) => markers.get(id),
|
||||
icon: (id) => iconSet.items.get(id),
|
||||
draw,
|
||||
paint: (occluder) => paint({ ctx, width: 800, height: 600, occluder }),
|
||||
mapChanged() {
|
||||
@@ -131,20 +146,25 @@ test('a selected camera without a bearing gets its badge and brackets, never a f
|
||||
assert.ok(h.draw[0].endsWith('alpr-marker-selected.png'));
|
||||
assert.ok(h.draw[1].endsWith('alpr-marker-selected-brackets.png'));
|
||||
assert.equal(h.overlay.pick({ x: 100, y: 100 }), 'camera:0');
|
||||
assert.equal(h.entities.getById('camera:0').billboard.show.getValue(), true);
|
||||
assert.equal(h.icon('camera:0').show, true);
|
||||
assert.equal(h.icon('camera:0').color[3], 0.01, 'a faint pick target');
|
||||
assert.equal(
|
||||
h.entities.getById('camera:0').billboard.color.getValue().alpha,
|
||||
0.01,
|
||||
h.icon('camera:0').meta,
|
||||
h.carrier('camera:0'),
|
||||
'a pick hands point-and-ask the context carrier',
|
||||
);
|
||||
assert.equal(directionWedgePositions(h.records[0]), null);
|
||||
});
|
||||
|
||||
test('the overlay bounds its cohort and promotes selection while leaving farther cameras native', (t) => {
|
||||
const h = harness(t, 70);
|
||||
// Floor anchors, so every camera anchors in one paint.
|
||||
const h = harness(t, 70, { floor: 150 });
|
||||
h.state.selectedId = 'camera:69';
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
const hidden = h.entities.values.filter((e) => e.gevAlprNativeAppearance);
|
||||
const hidden = [...h.markers.values()].filter(
|
||||
(carrier) => alprMarkers.read(carrier)?.canvasOwned,
|
||||
);
|
||||
assert.equal(hidden.length, 64);
|
||||
assert.ok(hidden.some((e) => e.id === 'camera:69'));
|
||||
assert.equal(
|
||||
@@ -160,24 +180,25 @@ test('surface changes invalidate cached anchors, and disable/disposal release pa
|
||||
const h = harness(t, 1);
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
const entity = h.entities.getById('camera:0');
|
||||
const first = entity.gevAlprCanvasPosition;
|
||||
const carrier = h.carrier('camera:0');
|
||||
const first = alprMarkers.read(carrier)?.canvasPosition;
|
||||
h.paint();
|
||||
assert.equal(
|
||||
entity.gevAlprCanvasPosition,
|
||||
alprMarkers.read(carrier)?.canvasPosition,
|
||||
first,
|
||||
'stable anchor across frames',
|
||||
);
|
||||
h.state.viewer.scene.globe.show = false;
|
||||
h.mapChanged();
|
||||
assert.equal(entity.gevAlprCanvasPosition, null);
|
||||
assert.equal(alprMarkers.read(carrier)?.canvasPosition, null);
|
||||
h.state.enabled = false;
|
||||
h.overlay.clear();
|
||||
assert.equal(h.active, false);
|
||||
assert.equal(h.overlay.pick({ x: 100, y: 100 }), null);
|
||||
assert.equal(entity.billboard.show.getValue(), true);
|
||||
assert.equal(entity.billboard.color, undefined);
|
||||
assert.equal(entity.position, undefined);
|
||||
const icon = h.icon('camera:0');
|
||||
assert.equal(icon.show, true);
|
||||
assert.equal(icon.color, undefined, 'the native badge again');
|
||||
assert.equal(icon.pos, alprMarkers.read(carrier).position);
|
||||
h.overlay.destroy();
|
||||
assert.equal(h.removed, 1);
|
||||
});
|
||||
@@ -187,7 +208,8 @@ test('an unresolved surface preserves the native marker; the horizon removes ove
|
||||
h.state.viewer.scene.globe.getHeight = () => -15000;
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
assert.equal(h.entities.getById('camera:0').billboard.show.getValue(), true);
|
||||
assert.equal(h.icon('camera:0').show, true);
|
||||
assert.equal(h.icon('camera:0').color, undefined);
|
||||
assert.equal(h.draw.length, 0);
|
||||
h.state.viewer.scene.globe.getHeight = () => 150;
|
||||
h.paint({ isPointVisible: () => false });
|
||||
@@ -195,18 +217,37 @@ test('an unresolved surface preserves the native marker; the horizon removes ove
|
||||
assert.equal(h.draw.length, 0);
|
||||
});
|
||||
|
||||
test('repeated paints of a still view never rewrite marker properties', (t) => {
|
||||
// Each Entity write raises definitionChanged; paint used to hide then show
|
||||
// every overlay camera's native marker on every frame.
|
||||
test('repeated paints of a still view never rewrite markers', (t) => {
|
||||
// Paint used to hide then show every overlay camera's native marker on
|
||||
// every frame.
|
||||
const h = harness(t, 3);
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
let changes = 0;
|
||||
for (const entity of h.entities.values)
|
||||
entity.definitionChanged.addEventListener(() => changes++);
|
||||
h.paint();
|
||||
const writes = h.iconSet.writes;
|
||||
for (let i = 0; i < 5; i++) h.paint();
|
||||
assert.equal(changes, 0);
|
||||
assert.equal(h.entities.getById('camera:0').billboard.show.getValue(), true);
|
||||
assert.equal(h.iconSet.writes, writes);
|
||||
assert.equal(h.icon('camera:0').show, true);
|
||||
});
|
||||
|
||||
test('a resync hands back only the cameras that leave the overlay', (t) => {
|
||||
const h = harness(t, 2, { floor: 150 });
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
assert.equal(h.icon('camera:0').color[3], 0.01);
|
||||
assert.equal(h.icon('camera:1').color[3], 0.01);
|
||||
const writes = h.iconSet.writes;
|
||||
h.overlay.sync([h.records[0]]);
|
||||
h.markers.flush();
|
||||
assert.equal(h.icon('camera:1').color, undefined, 'native again');
|
||||
assert.equal(h.icon('camera:0').color[3], 0.01, 'still under the canvas');
|
||||
assert.equal(
|
||||
h.iconSet.writes,
|
||||
writes + 1,
|
||||
'one write, for the camera that left',
|
||||
);
|
||||
h.paint();
|
||||
assert.equal(h.iconSet.writes, writes + 1, 'the next paint writes nothing');
|
||||
});
|
||||
|
||||
test('adapter labels never claim a custom source is public OSM data', () => {
|
||||
@@ -260,7 +301,7 @@ test('a still view replaces floor anchors with the rendered surface, within the
|
||||
h.paint();
|
||||
const height = (id) =>
|
||||
Cesium.Cartographic.fromCartesian(
|
||||
h.entities.getById(id).gevAlprCanvasPosition,
|
||||
alprMarkers.read(h.carrier(id))?.canvasPosition,
|
||||
).height;
|
||||
assert.equal(
|
||||
samples,
|
||||
@@ -281,3 +322,66 @@ test('a still view replaces floor anchors with the rendered surface, within the
|
||||
h.paint();
|
||||
assert.equal(samples, taken, 'each anchor is checked once');
|
||||
});
|
||||
|
||||
test('a bearing wedge is plain ECEF at the apex and its two far corners', () => {
|
||||
const record = { latitude: 30.26, longitude: -97.74, directionDeg: 90 };
|
||||
const wedge = directionWedgePositions(record, 150, (lat) =>
|
||||
lat > 30.26 ? 160 : null,
|
||||
);
|
||||
assert.equal(wedge.length, 3);
|
||||
const apex = Cesium.Cartesian3.fromDegrees(-97.74, 30.26, 150);
|
||||
assert.deepEqual({ ...wedge[0] }, { x: apex.x, y: apex.y, z: apex.z });
|
||||
const heights = wedge.map(
|
||||
(p) =>
|
||||
Cesium.Cartographic.fromCartesian(new Cesium.Cartesian3(p.x, p.y, p.z))
|
||||
.height,
|
||||
);
|
||||
// The corner north of the apex takes the sampled height; the other falls back.
|
||||
assert.ok(heights.some((h) => Math.abs(h - 160) < 1e-6));
|
||||
assert.ok(heights.slice(1).some((h) => Math.abs(h - 150) < 1e-6));
|
||||
});
|
||||
|
||||
test('anchors wait for the surface heights answer from: the globe’s terrain while shown, else the shown 3D tiles', (t) => {
|
||||
const h = harness(t, 1, { floor: 150 });
|
||||
const scene = h.state.viewer.scene;
|
||||
h.state.viewer.camera.directionWC = Cesium.Cartesian3.UNIT_X;
|
||||
scene.sampleHeightSupported = true;
|
||||
scene.primitives = { length: 0, get: () => null };
|
||||
let samples = 0;
|
||||
scene.sampleHeight = () => (samples++, 172);
|
||||
// The renderer's own `surface` rule; a non-base tileset still streaming
|
||||
// over a hidden globe leaves it unsettled.
|
||||
let surface = false;
|
||||
const asked = new Set();
|
||||
rendererOf(h.state.viewer).globe = {
|
||||
isSettled: (kind) => (asked.add(kind), kind === 'surface' ? surface : true),
|
||||
};
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
h.paint();
|
||||
assert.equal(samples, 0, 'no samples while the surface streams');
|
||||
assert.deepEqual([...asked], ['surface']);
|
||||
surface = true;
|
||||
h.paint();
|
||||
assert.ok(samples > 0, 'sampled once it has loaded');
|
||||
});
|
||||
|
||||
test('without height sampling no sample is spent, and the terrain anchors only while the globe is drawn', (t) => {
|
||||
for (const shown of [true, false]) {
|
||||
const h = harness(t, 1);
|
||||
let samples = 0;
|
||||
h.state.viewer.scene.sampleHeight = () => (samples++, 172);
|
||||
const renderer = rendererOf(h.state.viewer);
|
||||
renderer.capabilities = new Set();
|
||||
renderer.globe = { isSettled: () => true, isGlobeVisible: () => shown };
|
||||
h.overlay.sync(h.records);
|
||||
h.paint();
|
||||
h.paint();
|
||||
assert.equal(samples, 0, 'nothing sampled without the capability');
|
||||
assert.equal(
|
||||
Boolean(alprMarkers.read(h.carrier('camera:0'))?.canvasPosition),
|
||||
shown,
|
||||
shown ? 'anchored on the terrain' : 'no terrain under hidden globe',
|
||||
);
|
||||
}
|
||||
});
|
||||
+205
-244
@@ -1,16 +1,16 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { isUnderOtherCard } from '../../data/pickRegistry.js';
|
||||
import { distance, fromDegrees, toLonLatH } from '../../geo/index.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
MAX_VIEWPORT_DEGREES,
|
||||
MAX_RENDERED,
|
||||
ALPR_COLOR,
|
||||
ALPR_SELECTED_COLOR,
|
||||
MARKER_ICON_SIZE,
|
||||
SELECTED_MARKER_ICON_SIZE,
|
||||
CREDIT_DISPLAY_MS,
|
||||
MARKER_FLOOR_LIFT_M,
|
||||
MARKER_SCALE_BY_DISTANCE,
|
||||
} from './policy.js';
|
||||
import { boxContains } from './model.js';
|
||||
import { msg } from '../../i18n/index.js';
|
||||
@@ -19,12 +19,25 @@ import { createAlprOverlay } from './overlay.js';
|
||||
import { lookupAlprModelSpec } from './modelSpecs.js';
|
||||
import { specSummary } from '../cctv/modelSpecs.js';
|
||||
import {
|
||||
MARKER_IMAGE,
|
||||
SELECTED_IMAGE,
|
||||
alprDisplayId,
|
||||
alprLabelDetails,
|
||||
validAlprGroundHeight,
|
||||
} from './visuals.js';
|
||||
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
||||
import { alprIconPosition, alprMarkers } from './markerState.js';
|
||||
import { horizonFrom } from '../../geo/horizon.js';
|
||||
import {
|
||||
cameraOf,
|
||||
canvasOf,
|
||||
findCredits,
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
|
||||
/** A `#rrggbb` colour as `rgb(r,g,b)`, the form the readout card has always had. */
|
||||
function cssRgb(hex) {
|
||||
const n = Number.parseInt(hex.slice(1), 16);
|
||||
return `rgb(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255})`;
|
||||
}
|
||||
|
||||
export function createAlprPresentation({ state, services, source }) {
|
||||
const { governorRequestRender } = services.render;
|
||||
@@ -37,6 +50,7 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
} = services.context;
|
||||
|
||||
const { cachedGroundFloor } = services.groundFloor;
|
||||
const markers = state.markers;
|
||||
const overlay = createAlprOverlay({
|
||||
state,
|
||||
services,
|
||||
@@ -44,11 +58,35 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
});
|
||||
let visibleRecords = [];
|
||||
let selectionStartedAt = 0;
|
||||
/** Markers still clamped while their floor cell resolves (id -> entity). */
|
||||
/** Markers still clamped while their floor cell resolves (id -> carrier). */
|
||||
const clampedMarkers = new Map();
|
||||
let floorResolve = null;
|
||||
const floors = createAlprFloorResolver(services.groundFloor);
|
||||
|
||||
/** Heights under a camera now, through the renderer's query port. */
|
||||
function heightNow(record, against) {
|
||||
const query = findQuery(state.viewer);
|
||||
if (!query) return null;
|
||||
const point = { lon: record.longitude, lat: record.latitude };
|
||||
// A miss is tiles still streaming. The markers are no ground: the
|
||||
// height sees through them.
|
||||
return against === 'terrain'
|
||||
? query.sampleHeightNow(point, { against: 'terrain' })
|
||||
: query.sampleHeightNow(point, { exclude: [markers.icons?.id] });
|
||||
}
|
||||
|
||||
/**
|
||||
* The ground under a camera: the rendered surface, else the terrain,
|
||||
* else the cached floor; null when none is plausible.
|
||||
*/
|
||||
function groundHeight(record) {
|
||||
let height = heightNow(record);
|
||||
if (!validAlprGroundHeight(height)) height = heightNow(record, 'terrain');
|
||||
if (!validAlprGroundHeight(height))
|
||||
height = cachedGroundFloor(record.latitude, record.longitude);
|
||||
return validAlprGroundHeight(height) ? height : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marker placement from the cached ground floor (validated mesh or DEM, the
|
||||
* ellipsoidal datum every layer shares). Ground clamping on photoreal tiles
|
||||
@@ -56,14 +94,14 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
* whole-city view stutter while zooming, so it is only the placeholder for
|
||||
* a cell that has not resolved yet.
|
||||
* @param {{latitude:number, longitude:number}} record Camera.
|
||||
* @returns {{position: Cesium.Cartesian3, clamped: boolean}} Placement.
|
||||
* @returns {{position: {x:number, y:number, z:number}, clamped: boolean}} Placement.
|
||||
*/
|
||||
function markerPlacement(record) {
|
||||
const floor = cachedGroundFloor(record.latitude, record.longitude);
|
||||
const clamped = !validAlprGroundHeight(floor);
|
||||
return {
|
||||
clamped,
|
||||
position: Cesium.Cartesian3.fromDegrees(
|
||||
position: fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
clamped ? 0 : floor + MARKER_FLOOR_LIFT_M,
|
||||
@@ -132,25 +170,18 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
* @returns {number|null} Count, or null without a scene to project into.
|
||||
*/
|
||||
function countOnScreen() {
|
||||
const scene = state.viewer?.scene;
|
||||
const canvas = scene?.canvas;
|
||||
const canvas = canvasOf(state.viewer);
|
||||
const width = canvas?.clientWidth || canvas?.width;
|
||||
const height = canvas?.clientHeight || canvas?.height;
|
||||
const camera = state.viewer?.camera;
|
||||
if (!scene || !width || !height || !camera?.positionWC) return null;
|
||||
const occluder = new Cesium.EllipsoidalOccluder(
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
camera.positionWC,
|
||||
);
|
||||
const query = findQuery(state.viewer);
|
||||
if (!query || !width || !height) return null;
|
||||
let count = 0;
|
||||
try {
|
||||
for (const entity of state.dataSource.entities.values) {
|
||||
const position = entity.position?.getValue?.(Cesium.JulianDate.now());
|
||||
if (!position || !occluder.isPointVisible(position)) continue;
|
||||
const point = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
position,
|
||||
);
|
||||
const horizon = horizonFrom(cameraOf(state.viewer).pose().position);
|
||||
for (const carrier of markers.values()) {
|
||||
const position = alprIconPosition(carrier);
|
||||
if (!position || !horizon.isPointVisible(position)) continue;
|
||||
const point = query.project(position);
|
||||
if (
|
||||
point &&
|
||||
point.x >= 0 &&
|
||||
@@ -167,31 +198,26 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
return count;
|
||||
}
|
||||
|
||||
/** Write a marker position, respecting the overlay's pick-target swap. */
|
||||
function setMarkerPosition(entity, position, clamped) {
|
||||
const heightReference = clamped
|
||||
? Cesium.HeightReference.CLAMP_TO_GROUND
|
||||
: Cesium.HeightReference.NONE;
|
||||
const saved = entity.gevAlprNativeAppearance;
|
||||
if (saved) {
|
||||
saved.position = position;
|
||||
saved.heightReference = heightReference;
|
||||
} else {
|
||||
entity.position = position;
|
||||
entity.billboard.heightReference = heightReference;
|
||||
}
|
||||
entity.gevAlprClamped = clamped;
|
||||
/** Write a marker's native placement; the canvas anchor is left alone. */
|
||||
function setMarkerPosition(carrier, position, clamped) {
|
||||
const marker = alprMarkers.write(carrier);
|
||||
marker.position = position;
|
||||
marker.clamped = clamped;
|
||||
markers.changed(carrier);
|
||||
}
|
||||
|
||||
/** Refresh all native placements, including the appearances held by the canvas. */
|
||||
/** Refresh all native placements, including those under canvas badges. */
|
||||
function refreshMarkerPlacements() {
|
||||
if (!state.enabled || !state.dataSource) return;
|
||||
if (!state.enabled || !markers.icons) return;
|
||||
clampedMarkers.clear();
|
||||
for (const entity of state.dataSource.entities.values) {
|
||||
const { position, clamped } = markerPlacement(entity.gevAlprRecord);
|
||||
setMarkerPosition(entity, position, clamped);
|
||||
if (clamped) clampedMarkers.set(entity.id, entity);
|
||||
for (const carrier of markers.values()) {
|
||||
const { position, clamped } = markerPlacement(
|
||||
alprMarkers.read(carrier)?.record,
|
||||
);
|
||||
setMarkerPosition(carrier, position, clamped);
|
||||
if (clamped) clampedMarkers.set(carrier.id, carrier);
|
||||
}
|
||||
markers.flush();
|
||||
resolveClampedFloors();
|
||||
governorRequestRender('alpr-surface');
|
||||
}
|
||||
@@ -204,74 +230,65 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
const batch = [...clampedMarkers.values()];
|
||||
const request = Promise.resolve(
|
||||
floors.resolve(
|
||||
batch.map((entity) => ({
|
||||
lat: entity.gevAlprRecord.latitude,
|
||||
lon: entity.gevAlprRecord.longitude,
|
||||
})),
|
||||
batch.map((carrier) => {
|
||||
const { record } = alprMarkers.read(carrier);
|
||||
return { lat: record.latitude, lon: record.longitude };
|
||||
}),
|
||||
),
|
||||
)
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
if (floorResolve !== request) return;
|
||||
floorResolve = null;
|
||||
if (!state.enabled || !state.dataSource) return;
|
||||
if (!state.enabled || !markers.icons) return;
|
||||
let moved = false;
|
||||
for (const entity of batch) {
|
||||
if (clampedMarkers.get(entity.id) !== entity) continue;
|
||||
clampedMarkers.delete(entity.id);
|
||||
const { position, clamped } = markerPlacement(entity.gevAlprRecord);
|
||||
for (const carrier of batch) {
|
||||
if (clampedMarkers.get(carrier.id) !== carrier) continue;
|
||||
clampedMarkers.delete(carrier.id);
|
||||
const { position, clamped } = markerPlacement(
|
||||
alprMarkers.read(carrier)?.record,
|
||||
);
|
||||
if (clamped) continue;
|
||||
setMarkerPosition(entity, position, false);
|
||||
setMarkerPosition(carrier, position, false);
|
||||
moved = true;
|
||||
}
|
||||
markers.flush();
|
||||
if (moved) governorRequestRender('alpr-floor');
|
||||
// Cells that never resolved stay clamped; later renders retry them.
|
||||
});
|
||||
floorResolve = request;
|
||||
}
|
||||
|
||||
function updateAppearance(entity, selected) {
|
||||
const color = Cesium.Color.fromCssColorString(
|
||||
selected ? ALPR_SELECTED_COLOR : ALPR_COLOR,
|
||||
);
|
||||
entity.billboard.image = selected ? SELECTED_IMAGE : MARKER_IMAGE;
|
||||
entity.billboard.width = entity.billboard.height = selected
|
||||
? SELECTED_MARKER_ICON_SIZE
|
||||
: MARKER_ICON_SIZE;
|
||||
if (entity.gevLabelModel) {
|
||||
entity.gevLabelModel.accent = color.toCssColorString();
|
||||
entity.gevLabelModel.leaderAnimationStartedAt = selected
|
||||
? selectionStartedAt
|
||||
: 0;
|
||||
function updateAppearance(carrier, selected) {
|
||||
alprMarkers.write(carrier).selected = selected;
|
||||
markers.changed(carrier);
|
||||
const labelModel = readEntityRecord(carrier)?.labelModel;
|
||||
if (labelModel) {
|
||||
labelModel.accent = cssRgb(selected ? ALPR_SELECTED_COLOR : ALPR_COLOR);
|
||||
labelModel.leaderAnimationStartedAt = selected ? selectionStartedAt : 0;
|
||||
}
|
||||
}
|
||||
|
||||
function markerColor() {
|
||||
return Cesium.Color.fromCssColorString(ALPR_COLOR);
|
||||
}
|
||||
|
||||
// The horizon rectangle is unstable during low-angle orbits and can exclude
|
||||
// the ground point in the center of the screen. Bound nearby coverage around
|
||||
// that point instead; the camera-to-ground range keeps zoom-out queries capped.
|
||||
function viewportBox(viewer) {
|
||||
const camera = viewer?.camera;
|
||||
const canvas = viewer?.scene.canvas;
|
||||
if (typeof camera?.pickEllipsoid === 'function' && canvas) {
|
||||
const query = findQuery(viewer);
|
||||
const canvas = canvasOf(viewer);
|
||||
if (typeof query?.pickEllipsoid === 'function' && canvas) {
|
||||
const width = canvas.clientWidth || canvas.width;
|
||||
const height = canvas.clientHeight || canvas.height;
|
||||
if (!width || !height) return null;
|
||||
const focus = camera.pickEllipsoid(
|
||||
new Cesium.Cartesian2(width / 2, height / 2),
|
||||
viewer.scene.globe.ellipsoid,
|
||||
);
|
||||
const focus = query.pickEllipsoid(width / 2, height / 2);
|
||||
if (!focus) return null;
|
||||
const location = Cesium.Cartographic.fromCartesian(focus);
|
||||
const range = Cesium.Cartesian3.distance(camera.positionWC, focus);
|
||||
const location = toLonLatH(focus);
|
||||
if (!location) return null;
|
||||
const range = distance(cameraOf(viewer).pose().position, focus);
|
||||
const radius = Math.max(1000, 2 * range);
|
||||
const latitude = Cesium.Math.toDegrees(location.latitude);
|
||||
const longitude = Cesium.Math.toDegrees(location.longitude);
|
||||
const latitude = location.lat;
|
||||
const longitude = location.lon;
|
||||
const latSpan = radius / 111000;
|
||||
const lonSpan = latSpan / Math.cos(location.latitude);
|
||||
const lonSpan = latSpan / Math.cos((latitude * Math.PI) / 180);
|
||||
if (
|
||||
!Number.isFinite(latSpan + lonSpan) ||
|
||||
2 * Math.max(latSpan, lonSpan) > MAX_VIEWPORT_DEGREES ||
|
||||
@@ -287,14 +304,9 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
};
|
||||
}
|
||||
// Rectangle-only viewers retain the same bounded-area contract.
|
||||
const rectangle = viewer?.camera?.computeViewRectangle(
|
||||
viewer.scene.globe.ellipsoid,
|
||||
);
|
||||
const rectangle = viewer ? cameraOf(viewer).viewRectangle() : null;
|
||||
if (!rectangle) return null;
|
||||
const south = Cesium.Math.toDegrees(rectangle.south);
|
||||
const north = Cesium.Math.toDegrees(rectangle.north);
|
||||
const west = Cesium.Math.toDegrees(rectangle.west);
|
||||
const east = Cesium.Math.toDegrees(rectangle.east);
|
||||
const { south, north, west, east } = rectangle;
|
||||
if (
|
||||
!Number.isFinite(south + north + west + east) ||
|
||||
east <= west ||
|
||||
@@ -312,7 +324,7 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
overlay.clear();
|
||||
visibleRecords = [];
|
||||
clampedMarkers.clear();
|
||||
if (state.dataSource?.entities) state.dataSource.entities.removeAll();
|
||||
markers.clear();
|
||||
removeEntityContextsForLayer(LAYER_ID);
|
||||
}
|
||||
|
||||
@@ -320,8 +332,8 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
services.credits?.hideOsmCredit?.(state.viewer, LAYER_ID);
|
||||
clearTimeout(state.creditTimer);
|
||||
state.creditTimer = null;
|
||||
if (state.credit)
|
||||
state.viewer?.creditDisplay?.removeStaticCredit(state.credit);
|
||||
state.creditOff?.();
|
||||
state.creditOff = null;
|
||||
governorRequestRender('alpr-credit');
|
||||
}
|
||||
|
||||
@@ -336,7 +348,8 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
}
|
||||
if (!state.enabled || state.creditPresented || !state.credit) return;
|
||||
state.creditPresented = true;
|
||||
state.viewer.creditDisplay?.addStaticCredit(state.credit);
|
||||
state.creditOff =
|
||||
findCredits(state.viewer)?.addStatic(state.credit) ?? null;
|
||||
state.creditTimer = setTimeout(hideOnMapCredit, CREDIT_DISPLAY_MS);
|
||||
governorRequestRender('alpr-credit');
|
||||
}
|
||||
@@ -361,82 +374,68 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
governorRequestRender('alpr-render');
|
||||
const visibleIds = new Set(visible.map((record) => record.id));
|
||||
let changed = false;
|
||||
state.dataSource.entities.suspendEvents();
|
||||
for (const entity of [...state.dataSource.entities.values]) {
|
||||
if (!visibleIds.has(entity.id)) {
|
||||
state.dataSource.entities.remove(entity);
|
||||
clampedMarkers.delete(entity.id);
|
||||
changed = true;
|
||||
}
|
||||
const gone = [];
|
||||
for (const carrier of markers.values())
|
||||
if (!visibleIds.has(carrier.id)) gone.push(carrier.id);
|
||||
if (gone.length) {
|
||||
markers.remove(gone);
|
||||
for (const id of gone) clampedMarkers.delete(id);
|
||||
changed = true;
|
||||
}
|
||||
removeEntityContextsForLayer(LAYER_ID, { retainIds: visibleIds });
|
||||
for (const record of visible) {
|
||||
const existing = state.dataSource.entities.getById(record.id);
|
||||
if (existing?.gevAlprRecord === record) {
|
||||
const existing = markers.get(record.id);
|
||||
if (alprMarkers.read(existing)?.record === record) {
|
||||
updateAppearance(existing, record.id === state.selectedId);
|
||||
continue;
|
||||
}
|
||||
const color = markerColor();
|
||||
const selected = record.id === state.selectedId;
|
||||
const { position, clamped } = markerPlacement(record);
|
||||
// Direction wedges are painted by the overlay for the nearest cameras.
|
||||
// Native ground-clamped wedges (a ground polyline plus a classification
|
||||
// polygon per camera) cost ~40 ms per frame for 200 downtown cameras on
|
||||
// photoreal tiles, so markers stay billboards only.
|
||||
const entityDef = {
|
||||
id: record.id,
|
||||
position,
|
||||
billboard: {
|
||||
image: selected ? SELECTED_IMAGE : MARKER_IMAGE,
|
||||
width: selected ? SELECTED_MARKER_ICON_SIZE : MARKER_ICON_SIZE,
|
||||
height: selected ? SELECTED_MARKER_ICON_SIZE : MARKER_ICON_SIZE,
|
||||
heightReference: clamped
|
||||
? Cesium.HeightReference.CLAMP_TO_GROUND
|
||||
: Cesium.HeightReference.NONE,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
// City-wide views hold hundreds of badges; let them shrink.
|
||||
scaleByDistance: new Cesium.NearFarScalar(
|
||||
...MARKER_SCALE_BY_DISTANCE,
|
||||
),
|
||||
},
|
||||
};
|
||||
let entity = existing;
|
||||
// Keep the Cesium entity and its ground-clamping subscription while its
|
||||
// geometry is unchanged. Updating metadata must not rebuild the marker.
|
||||
const previous = entity?.gevAlprRecord;
|
||||
if (!entity) {
|
||||
entity = state.dataSource.entities.add(entityDef);
|
||||
entity.gevAlprClamped = clamped;
|
||||
// photoreal tiles, so markers stay icons only.
|
||||
let carrier = existing;
|
||||
// Keep the marker and its icon while its geometry is unchanged.
|
||||
// Updating metadata must not rebuild the marker.
|
||||
const previous = alprMarkers.read(carrier)?.record;
|
||||
if (!carrier) {
|
||||
carrier = markers.add(record.id);
|
||||
changed = true;
|
||||
}
|
||||
const marker = alprMarkers.write(carrier);
|
||||
if (!existing) {
|
||||
marker.position = position;
|
||||
marker.clamped = clamped;
|
||||
} else {
|
||||
if (
|
||||
previous.latitude !== record.latitude ||
|
||||
previous.longitude !== record.longitude
|
||||
) {
|
||||
setMarkerPosition(entity, position, clamped);
|
||||
entity.gevAlprCanvasPosition = null;
|
||||
entity.gevAlprDisplayPosition = null;
|
||||
setMarkerPosition(carrier, position, clamped);
|
||||
marker.canvasPosition = null;
|
||||
marker.displayPosition = null;
|
||||
}
|
||||
if (
|
||||
previous.latitude !== record.latitude ||
|
||||
previous.longitude !== record.longitude ||
|
||||
previous.directionDeg !== record.directionDeg
|
||||
) {
|
||||
entity.gevAlprCanvasPosition = null;
|
||||
entity.gevAlprWedge = null;
|
||||
marker.canvasPosition = null;
|
||||
marker.wedge = null;
|
||||
}
|
||||
}
|
||||
entity.gevAlprRecord = record;
|
||||
entity.gevTrackedId = record.id;
|
||||
marker.record = record;
|
||||
entityRecord(carrier).trackedId = record.id;
|
||||
// The mapped camera datum has no elevation; it is not the clamped marker's
|
||||
// visual anchor. Only the selected marker samples the rendered surface,
|
||||
// at most once per second, through Cesium's public height APIs.
|
||||
entity.gevAlprDisplayPosition ??= null;
|
||||
entity.gevDisplayPosition = () => entity.gevAlprDisplayPosition;
|
||||
entity.gevLabelModel = {
|
||||
// at most once per second, through the renderer's height queries.
|
||||
marker.displayPosition ??= null;
|
||||
entityRecord(carrier).displayPosition = () => marker.displayPosition;
|
||||
entityRecord(carrier).labelModel = {
|
||||
title: alprDisplayId(record),
|
||||
details: alprLabelDetails(record, source),
|
||||
accent: color.toCssColorString(),
|
||||
accent: cssRgb(ALPR_COLOR),
|
||||
cardStyle: 'tactical',
|
||||
selected: true,
|
||||
leaderStyle: 'elbow',
|
||||
@@ -446,11 +445,12 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
anchorRadiusPx: SELECTED_MARKER_ICON_SIZE / 2,
|
||||
anchorRadiusScale: null,
|
||||
};
|
||||
updateAppearance(entity, selected);
|
||||
registerEntityContext(entity, {
|
||||
updateAppearance(carrier, selected);
|
||||
registerEntityContext(carrier, {
|
||||
id: record.id,
|
||||
layerId: LAYER_ID,
|
||||
dataSource: state.dataSource,
|
||||
// Hidden with the layer: the context store reads its `show`.
|
||||
dataSource: markers.icons,
|
||||
layerName: 'ALPR Cameras',
|
||||
source:
|
||||
source.attribution?.description || source.label || 'Camera source',
|
||||
@@ -474,101 +474,85 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
},
|
||||
});
|
||||
}
|
||||
state.dataSource.entities.resumeEvents();
|
||||
if (changed) state.renderRevision += 1;
|
||||
state.onScreen = countOnScreen();
|
||||
for (const entity of state.dataSource.entities.values)
|
||||
if (entity.gevAlprClamped) clampedMarkers.set(entity.id, entity);
|
||||
for (const carrier of markers.values())
|
||||
if (alprMarkers.read(carrier)?.clamped)
|
||||
clampedMarkers.set(carrier.id, carrier);
|
||||
resolveClampedFloors();
|
||||
const selectedEntity = state.selectedId
|
||||
? state.dataSource.entities.getById(state.selectedId)
|
||||
const selectedCarrier = state.selectedId
|
||||
? markers.get(state.selectedId)
|
||||
: null;
|
||||
if (!selectedEntity) state.selectedId = null;
|
||||
if (!selectedCarrier) state.selectedId = null;
|
||||
updateSelectedAnchor();
|
||||
overlay.sync(visible);
|
||||
if (selectedEntity) services.overlays?.refreshReadout?.(selectedEntity);
|
||||
markers.flush();
|
||||
if (selectedCarrier) services.overlays?.refreshReadout?.(selectedCarrier);
|
||||
// Keep the on-map credit tied to displayed data, not loading or zoom prompts.
|
||||
if (visible.length) presentOnMapCredit();
|
||||
else hideOnMapCredit();
|
||||
}
|
||||
|
||||
function focusNearest() {
|
||||
const camera = state.viewer?.camera;
|
||||
if (!state.enabled || !camera?.positionWC || state.viewer.trackedEntity)
|
||||
if (!state.enabled || !state.viewer || isFollowing(state.viewer))
|
||||
return false;
|
||||
const port = cameraOf(state.viewer);
|
||||
const eye = port.pose().position;
|
||||
let nearest = null,
|
||||
distance = Infinity;
|
||||
for (const entity of state.dataSource.entities.values) {
|
||||
const position = entity.position.getValue(Cesium.JulianDate.now());
|
||||
const candidate = Cesium.Cartesian3.distanceSquared(
|
||||
camera.positionWC,
|
||||
position,
|
||||
);
|
||||
if (candidate < distance) {
|
||||
nearest = entity;
|
||||
distance = candidate;
|
||||
best = Infinity;
|
||||
for (const carrier of markers.values()) {
|
||||
const position = alprIconPosition(carrier);
|
||||
if (!position) continue;
|
||||
const candidate = distance(eye, position);
|
||||
if (candidate < best) {
|
||||
nearest = carrier;
|
||||
best = candidate;
|
||||
}
|
||||
}
|
||||
if (!nearest) return false;
|
||||
const record = state.recordById.get(nearest.id);
|
||||
const location = Cesium.Cartographic.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
);
|
||||
let height;
|
||||
if (state.viewer.scene.sampleHeightSupported) {
|
||||
try {
|
||||
height = state.viewer.scene.sampleHeight(location, [nearest]);
|
||||
} catch {
|
||||
/* tiles may still be streaming */
|
||||
}
|
||||
}
|
||||
if (!validAlprGroundHeight(height) && state.viewer.scene.globe.show)
|
||||
height = state.viewer.scene.globe.getHeight?.(location);
|
||||
if (!validAlprGroundHeight(height))
|
||||
height = cachedGroundFloor(record.latitude, record.longitude);
|
||||
const center = Cesium.Cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
validAlprGroundHeight(height) ? height : 0,
|
||||
);
|
||||
const height = groundHeight(record);
|
||||
const center = fromDegrees(record.longitude, record.latitude, height ?? 0);
|
||||
if (!selectRecord(nearest.id)) return false;
|
||||
camera.flyToBoundingSphere(new Cesium.BoundingSphere(center, 30), {
|
||||
duration: 1.2,
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
camera.heading || 0,
|
||||
-Math.PI / 4,
|
||||
800,
|
||||
),
|
||||
});
|
||||
port.flyToBounds(
|
||||
{ center, radius: 30 },
|
||||
{
|
||||
durationS: 1.2,
|
||||
offset: {
|
||||
heading: port.pose().heading || 0,
|
||||
pitch: -Math.PI / 4,
|
||||
range: 800,
|
||||
},
|
||||
},
|
||||
);
|
||||
governorRequestRender('alpr-focus');
|
||||
return true;
|
||||
}
|
||||
|
||||
function selectRecord(id) {
|
||||
const entity = state.dataSource?.entities.getById(id);
|
||||
if (!entity || !state.recordById.has(id)) return false;
|
||||
const carrier = markers.get(id);
|
||||
if (!carrier || !state.recordById.has(id)) return false;
|
||||
clearSelection();
|
||||
state.selectedId = id;
|
||||
selectionStartedAt = globalThis.performance?.now?.() ?? Date.now();
|
||||
updateAppearance(entity, true);
|
||||
updateAppearance(carrier, true);
|
||||
state.lastAnchorSampleAt = 0;
|
||||
selectEntityContext(entity);
|
||||
selectEntityContext(carrier);
|
||||
updateSelectedAnchor();
|
||||
overlay.sync(visibleRecords);
|
||||
markers.flush();
|
||||
governorRequestRender('alpr-selection');
|
||||
return true;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
const entity = state.selectedId
|
||||
? state.dataSource?.entities.getById(state.selectedId)
|
||||
: null;
|
||||
const carrier = state.selectedId ? markers.get(state.selectedId) : null;
|
||||
const record = state.recordById.get(state.selectedId);
|
||||
if (entity && record) updateAppearance(entity, false);
|
||||
if (carrier && record) updateAppearance(carrier, false);
|
||||
state.selectedId = null;
|
||||
selectionStartedAt = 0;
|
||||
overlay.sync(visibleRecords);
|
||||
markers.flush();
|
||||
clearSelectedEntityContextForLayer(LAYER_ID);
|
||||
governorRequestRender('alpr-selection');
|
||||
}
|
||||
@@ -580,60 +564,38 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
clearSelection();
|
||||
return;
|
||||
}
|
||||
const entity = state.dataSource?.entities.getById(state.selectedId);
|
||||
const carrier = markers.get(state.selectedId);
|
||||
const record = state.recordById.get(state.selectedId);
|
||||
if (entity?.gevAlprCanvasPosition) {
|
||||
entity.gevAlprDisplayPosition = entity.gevAlprCanvasPosition;
|
||||
const marker = alprMarkers.read(carrier);
|
||||
if (marker?.canvasPosition) {
|
||||
marker.displayPosition = marker.canvasPosition;
|
||||
return;
|
||||
}
|
||||
if (!entity || !record || Date.now() - state.lastAnchorSampleAt < 1000)
|
||||
if (!carrier || !record || Date.now() - state.lastAnchorSampleAt < 1000)
|
||||
return;
|
||||
state.lastAnchorSampleAt = Date.now();
|
||||
const scene = state.viewer.scene;
|
||||
const location = Cesium.Cartographic.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
);
|
||||
let height;
|
||||
if (scene.sampleHeightSupported) {
|
||||
try {
|
||||
height = scene.sampleHeight(location, [entity]);
|
||||
} catch {
|
||||
/* tiles may still be streaming */
|
||||
}
|
||||
}
|
||||
if (!validAlprGroundHeight(height) && scene.globe.show)
|
||||
height = scene.globe.getHeight?.(location);
|
||||
if (!validAlprGroundHeight(height))
|
||||
height = cachedGroundFloor(record.latitude, record.longitude);
|
||||
if (!validAlprGroundHeight(height)) return;
|
||||
const next = Cesium.Cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
height,
|
||||
);
|
||||
if (
|
||||
!entity.gevAlprDisplayPosition ||
|
||||
Cesium.Cartesian3.distance(next, entity.gevAlprDisplayPosition) > 0.1
|
||||
) {
|
||||
entity.gevAlprDisplayPosition = next;
|
||||
const height = groundHeight(record);
|
||||
if (height === null) return;
|
||||
const next = fromDegrees(record.longitude, record.latitude, height);
|
||||
const shown = marker?.displayPosition;
|
||||
if (!shown || distance(next, shown) > 0.1) {
|
||||
alprMarkers.write(carrier).displayPosition = next;
|
||||
governorRequestRender('alpr-anchor');
|
||||
}
|
||||
}
|
||||
|
||||
function installInteraction(viewer) {
|
||||
if (state.clickHandler) return;
|
||||
state.clickHandler = new Cesium.ScreenSpaceEventHandler(
|
||||
viewer.scene.canvas,
|
||||
);
|
||||
state.clickHandler.setInputAction((click) => {
|
||||
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
||||
if (!isPointerFree()) return;
|
||||
if (state.clickSubscription) return;
|
||||
state.clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!state.enabled) return;
|
||||
const picked = viewer.scene.pick(click.position);
|
||||
// Another layer's card or label painted on top takes the click: the item
|
||||
// under it does not act, and the click is not empty space either.
|
||||
if (isUnderOtherCard(event)) return;
|
||||
// The painted overlay answers first; the scene is picked only if not.
|
||||
const hit = event.drawHit;
|
||||
const id =
|
||||
overlay.pick(click.position) ||
|
||||
(typeof picked?.id?.id === 'string' ? picked.id.id : null);
|
||||
overlay.pick(event.screenPosition) ||
|
||||
(hit && hit.set === markers.icons?.id ? hit.id : null);
|
||||
if (
|
||||
id &&
|
||||
state.recordById.has(id) &&
|
||||
@@ -641,12 +603,11 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
)
|
||||
selectRecord(id);
|
||||
else if (state.selectedId) clearSelection();
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
});
|
||||
}
|
||||
return {
|
||||
initOverlay: () => overlay.init(),
|
||||
destroyOverlay: () => overlay.destroy(),
|
||||
markerColor,
|
||||
viewportBox,
|
||||
clearRendered,
|
||||
hideOnMapCredit,
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { fakeInput, fakeInputUnderLabel } from '../../input/testDoubles.mjs';
|
||||
import { setClickCardHitTest } from '../../data/pickRegistry.js';
|
||||
import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
import { createAlprMarkerSet } from './markerState.js';
|
||||
import { createAlprPresentation } from './presentation.js';
|
||||
|
||||
/** One camera drawn and painted at (100, 100), over a viewer whose clicks a
|
||||
* label may take. */
|
||||
function harness(t) {
|
||||
const previousImage = globalThis.Image;
|
||||
const project = Cesium.SceneTransforms.worldToWindowCoordinates;
|
||||
globalThis.Image = class {
|
||||
complete = true;
|
||||
naturalWidth = 128;
|
||||
};
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = () => ({ x: 100, y: 100 });
|
||||
const record = {
|
||||
id: 'camera:0',
|
||||
latitude: 30,
|
||||
longitude: -97,
|
||||
directionDeg: 90,
|
||||
};
|
||||
const drawPort = fakeDrawPort();
|
||||
const markers = createAlprMarkerSet();
|
||||
markers.attach(drawPort.icons({ id: 'alpr-cameras:test:markers' }));
|
||||
const viewer = {
|
||||
camera: {
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(-97, 30, 500),
|
||||
pickEllipsoid: () => Cesium.Cartesian3.fromDegrees(-97, 30),
|
||||
},
|
||||
scene: {
|
||||
canvas: { clientWidth: 800, clientHeight: 600 },
|
||||
globe: { show: true, getHeight: () => 150 },
|
||||
pick: () => null,
|
||||
},
|
||||
};
|
||||
const { unbind } = bindFakeCesiumScene(viewer, { draw: drawPort });
|
||||
const fake = fakeInputUnderLabel(viewer);
|
||||
const state = {
|
||||
viewer,
|
||||
enabled: true,
|
||||
selectedId: null,
|
||||
markers,
|
||||
records: [record],
|
||||
recordById: new Map([[record.id, record]]),
|
||||
renderRevision: 0,
|
||||
lastAnchorSampleAt: 0,
|
||||
};
|
||||
let selected = null;
|
||||
let paint;
|
||||
const presentation = createAlprPresentation({
|
||||
state,
|
||||
source: { label: 'Test cameras' },
|
||||
services: {
|
||||
render: { governorRequestRender() {} },
|
||||
context: {
|
||||
clearSelectedEntityContextForLayer() {
|
||||
selected = null;
|
||||
},
|
||||
getSelectedEntityContext: () => selected,
|
||||
registerEntityContext() {},
|
||||
removeEntityContextsForLayer() {},
|
||||
selectEntityContext(carrier) {
|
||||
selected = { id: carrier.id, layerId: 'alpr-cameras' };
|
||||
},
|
||||
},
|
||||
groundFloor: { cachedGroundFloor: () => 150 },
|
||||
overlays: {
|
||||
registerPaintLane(_lane, painter) {
|
||||
paint = painter;
|
||||
return { setActive() {}, requestPaint() {}, unregister() {} };
|
||||
},
|
||||
keyholeAlpha: () => 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
presentation.initOverlay();
|
||||
presentation.installInteraction(viewer);
|
||||
t.after(() => {
|
||||
presentation.destroyOverlay();
|
||||
fake.destroy();
|
||||
unbind();
|
||||
if (previousImage === undefined) delete globalThis.Image;
|
||||
else globalThis.Image = previousImage;
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = project;
|
||||
});
|
||||
presentation.renderRecords();
|
||||
const ctx = {
|
||||
globalAlpha: 1,
|
||||
save() {},
|
||||
restore() {},
|
||||
beginPath() {},
|
||||
moveTo() {},
|
||||
lineTo() {},
|
||||
closePath() {},
|
||||
stroke() {},
|
||||
fill() {},
|
||||
createLinearGradient: () => ({ addColorStop() {} }),
|
||||
drawImage() {},
|
||||
};
|
||||
paint({ ctx, width: 800, height: 600 });
|
||||
return { state, fake, at: { x: 100, y: 100 } };
|
||||
}
|
||||
|
||||
test('a click on a mission label over a camera never selects it, and keeps the selected camera', (t) => {
|
||||
const h = harness(t);
|
||||
h.fake.label.over = true;
|
||||
h.fake.click(h.at);
|
||||
assert.equal(h.state.selectedId, null, 'the camera under the label');
|
||||
|
||||
// Off the label, the same click selects the camera.
|
||||
h.fake.label.over = false;
|
||||
h.fake.click(h.at);
|
||||
assert.equal(h.state.selectedId, 'camera:0');
|
||||
|
||||
// The label on top is its own click: the selection stays.
|
||||
h.fake.label.over = true;
|
||||
h.fake.click(h.at);
|
||||
assert.equal(h.state.selectedId, 'camera:0', 'the selection stays');
|
||||
});
|
||||
|
||||
// The card or label painted on top takes the click: ALPR does not even pick
|
||||
// under another layer's card, so no camera is selected or released there.
|
||||
test("another layer's card over an ALPR camera keeps the click", (t) => {
|
||||
let picks = 0;
|
||||
const viewer = {
|
||||
scene: {
|
||||
canvas: new EventTarget(),
|
||||
pick: () => {
|
||||
picks++;
|
||||
return null;
|
||||
},
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
const noop = () => {};
|
||||
const state = {
|
||||
enabled: true,
|
||||
viewer,
|
||||
clickSubscription: null,
|
||||
markers: { icons: null },
|
||||
recordById: new Map(),
|
||||
selectedId: null,
|
||||
};
|
||||
const presentation = createAlprPresentation({
|
||||
state,
|
||||
services: {
|
||||
render: { governorRequestRender: noop },
|
||||
context: {
|
||||
clearSelectedEntityContextForLayer: noop,
|
||||
getSelectedEntityContext: () => null,
|
||||
registerEntityContext: noop,
|
||||
removeEntityContextsForLayer: noop,
|
||||
selectEntityContext: noop,
|
||||
},
|
||||
groundFloor: { cachedGroundFloor: () => null },
|
||||
},
|
||||
});
|
||||
presentation.installInteraction(viewer);
|
||||
let top = { sourceId: 'earthquake-card', entryId: 'earthquake-card:ak1' };
|
||||
setClickCardHitTest(() => top);
|
||||
t.after(() => {
|
||||
setClickCardHitTest(null);
|
||||
state.clickSubscription?.();
|
||||
input.destroy();
|
||||
});
|
||||
input.tap({ x: 10, y: 10 });
|
||||
assert.equal(picks, 0, 'covered: the scene under the card is not picked');
|
||||
top = null;
|
||||
input.tap({ x: 10, y: 10 });
|
||||
assert.ok(picks > 0, 'open map: the click reaches the scene');
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
createOverpassAlprSource,
|
||||
buildOverpassQuery,
|
||||
} from './source.js';
|
||||
import { validateAlprSnapshot, alprCreditMarkup } from './model.js';
|
||||
import { validateAlprSnapshot, alprCredit } from './model.js';
|
||||
const box = { south: 30, west: -98, north: 30.1, east: -97.9 };
|
||||
test('the source rejects invalid and unbounded queries before fetching', async () => {
|
||||
let calls = 0;
|
||||
@@ -130,19 +130,28 @@ test('source snapshots reject malformed coordinates and duplicate identities', (
|
||||
);
|
||||
});
|
||||
|
||||
test('provider attribution escapes markup and rejects executable links', () => {
|
||||
assert.equal(alprCreditMarkup(null), null);
|
||||
test('provider attribution is plain text with a public HTTPS link only', () => {
|
||||
assert.equal(alprCredit(null), null);
|
||||
assert.throws(
|
||||
() => alprCreditMarkup({ text: 'test', href: 'javascript:alert(1)' }),
|
||||
() => alprCredit({ text: 'test', href: 'javascript:alert(1)' }),
|
||||
/HTTPS/,
|
||||
);
|
||||
const html = alprCreditMarkup({
|
||||
text: '<img onerror=alert(1)>',
|
||||
href: 'https://example.org/?a=1&b=2',
|
||||
});
|
||||
assert.ok(html.includes('<img onerror=alert(1)>'));
|
||||
assert.ok(html.includes('?a=1&b=2'));
|
||||
assert.ok(!html.includes('<img'));
|
||||
assert.throws(
|
||||
() => alprCredit({ text: 'test', href: 'https://user:[email protected]/' }),
|
||||
/HTTPS/,
|
||||
);
|
||||
assert.deepEqual(
|
||||
alprCredit({
|
||||
text: '<img onerror=alert(1)>',
|
||||
href: 'https://example.org/?a=1&b=2',
|
||||
}),
|
||||
{
|
||||
text: 'ALPR: <img onerror=alert(1)>',
|
||||
href: 'https://example.org/?a=1&b=2',
|
||||
inline: true,
|
||||
},
|
||||
'left as text: the credits port escapes it',
|
||||
);
|
||||
});
|
||||
|
||||
test('wide detail view returns zoom guidance before any fetch and can retry a smaller view', async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { fromDegrees } from '../../geo/index.js';
|
||||
import { destinationPointDeg } from './model.js';
|
||||
import { lookupAlprModelSpec } from './modelSpecs.js';
|
||||
import { specSummary } from '../cctv/modelSpecs.js';
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
|
||||
/**
|
||||
* Badge scale at a camera distance, matching Cesium's NearFarScalar for the
|
||||
* native badges (linear between near and far, clamped outside).
|
||||
* Badge scale at a camera distance, matching the native badges'
|
||||
* scale-by-distance (linear between near and far, clamped outside).
|
||||
* @param {number} distanceM Camera-to-marker distance.
|
||||
* @returns {number} Scale factor.
|
||||
*/
|
||||
@@ -86,7 +86,8 @@ export function alprLabelDetails(record, source) {
|
||||
* @param {function(number, number): (number|null)} [heightAt] Optional height
|
||||
* for the two far corners (degrees lat, lon), so the wedge follows a slope
|
||||
* instead of floating level from the apex; falls back to the apex height.
|
||||
* @returns {Array<Cesium.Cartesian3>|null} Apex, left and right corners.
|
||||
* @returns {Array<{x: number, y: number, z: number}>|null} Apex, left and
|
||||
* right corners, ECEF.
|
||||
*/
|
||||
export function directionWedgePositions(record, heightM = 0, heightAt = null) {
|
||||
if (!Number.isFinite(record.directionDeg)) return null;
|
||||
@@ -107,13 +108,9 @@ export function directionWedgePositions(record, heightM = 0, heightAt = null) {
|
||||
return Number.isFinite(height) ? height : heightM;
|
||||
};
|
||||
return [
|
||||
Cesium.Cartesian3.fromDegrees(record.longitude, record.latitude, heightM),
|
||||
Cesium.Cartesian3.fromDegrees(left.longitude, left.latitude, corner(left)),
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
right.longitude,
|
||||
right.latitude,
|
||||
corner(right),
|
||||
),
|
||||
fromDegrees(record.longitude, record.latitude, heightM),
|
||||
fromDegrees(left.longitude, left.latitude, corner(left)),
|
||||
fromDegrees(right.longitude, right.latitude, corner(right)),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user