mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Draw local ADS-B through the draw port
The local receiver layer draws its aircraft, the 978 MHz rings and the selected aircraft's trail head through draw-port sets, updates them on the frame port each frame, rotates icons from the camera port's screen axes, and leaves the Cesium allow-list. The trail head now dims behind terrain instead of vanishing, as the rest of the trail does.
This commit is contained in:
1 parent
84e6f13725
commit
be5a6f0fe5
5 files changed
+614
-292
No files matched your search
+213
-139
@@ -1,11 +1,12 @@
|
|||||||
import * as Cesium from 'cesium';
|
|
||||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||||
import { aircraftIcon } from '../../data/aircraftIcons.js';
|
import { aircraftIcon } from '../../data/aircraftIcons.js';
|
||||||
import {
|
import {
|
||||||
horizonOccluder,
|
|
||||||
screenProjectedRotation,
|
screenProjectedRotation,
|
||||||
stabilizeScreenRotation,
|
stabilizeScreenRotation,
|
||||||
} from '../../data/iconOrientation.js';
|
} from '../../data/iconOrientation.js';
|
||||||
|
import { fromDegreesInto, toLonLatH } from '../../geo/ellipsoid.js';
|
||||||
|
import { hexColor } from '../../render/color.js';
|
||||||
|
import { drawOf, findCamera, findFrame } from '../../render/rendererOf.js';
|
||||||
import { inputFor } from '../../input/dispatcher.js';
|
import { inputFor } from '../../input/dispatcher.js';
|
||||||
import { pickRenderAltitudeM } from '../../data/renderAltitude.js';
|
import { pickRenderAltitudeM } from '../../data/renderAltitude.js';
|
||||||
import { routePlausible } from '../../data/routePlausible.js';
|
import { routePlausible } from '../../data/routePlausible.js';
|
||||||
@@ -49,8 +50,19 @@ const CLICK_DRILL_LIMIT = 8;
|
|||||||
const MARKER_SPRITE = Object.freeze({
|
const MARKER_SPRITE = Object.freeze({
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 20,
|
height: 20,
|
||||||
scaleByDistance: new Cesium.NearFarScalar(1000, 3.0, 8_000_000, 0.5),
|
scaleByDistance: Object.freeze({
|
||||||
|
near: 1000,
|
||||||
|
nearValue: 3.0,
|
||||||
|
far: 8_000_000,
|
||||||
|
farValue: 0.5,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
/** Markers and rings show within 2,000 km of the eye. */
|
||||||
|
const MARKER_RANGE = Object.freeze([0, 2_000_000]);
|
||||||
|
/** The longest the moving trail head waits to be drawn anew, ms. */
|
||||||
|
const HEAD_REDRAW_MS = 100;
|
||||||
|
/** Draw sets made, so each layer instance's sets have ids of their own. */
|
||||||
|
let instances = 0;
|
||||||
/** Trail lines pass through their aircraft; a click never stops on one. */
|
/** Trail lines pass through their aircraft; a click never stops on one. */
|
||||||
const TRAIL_PICK_PREFIX = 'gev-trail:';
|
const TRAIL_PICK_PREFIX = 'gev-trail:';
|
||||||
/** The DISPLAY rail's first-run 3D preference, used when no reader is wired. */
|
/** The DISPLAY rail's first-run 3D preference, used when no reader is wired. */
|
||||||
@@ -120,13 +132,17 @@ export function createLocalAdsbLayer({
|
|||||||
removeEntityContextsForLayer,
|
removeEntityContextsForLayer,
|
||||||
} = services.context;
|
} = services.context;
|
||||||
const { registerPickOwner, unregisterPickOwner } = services.picking;
|
const { registerPickOwner, unregisterPickOwner } = services.picking;
|
||||||
const color = Cesium.Color.fromCssColorString(LOCAL_ADSB_COLOR);
|
const color = hexColor(LOCAL_ADSB_COLOR);
|
||||||
const uatRingColor = Cesium.Color.fromCssColorString(
|
const uatRingColor = hexColor(LOCAL_ADSB_UAT_RING_COLOR);
|
||||||
LOCAL_ADSB_UAT_RING_COLOR,
|
|
||||||
);
|
|
||||||
|
|
||||||
let viewer = null;
|
let viewer = null;
|
||||||
let dataSource = null;
|
/**
|
||||||
|
* The layer's draw sets on its viewer's renderer (`drawOf`), made at
|
||||||
|
* `init`: the markers, the 978 MHz rings and the selected aircraft's live
|
||||||
|
* trail head. Shown while the layer is enabled.
|
||||||
|
* @type {{markers: object, rings: object, head: object}|null}
|
||||||
|
*/
|
||||||
|
let sets = null;
|
||||||
let enabled = false;
|
let enabled = false;
|
||||||
let unsubscribe = null;
|
let unsubscribe = null;
|
||||||
let unsubscribeFeeds = null;
|
let unsubscribeFeeds = null;
|
||||||
@@ -176,15 +192,21 @@ export function createLocalAdsbLayer({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function markerVisible(marker) {
|
/**
|
||||||
if (!viewer?.camera?.positionWC || !marker.position) return true;
|
* The camera's screen axes, as the course projection reads them, from the
|
||||||
return horizonOccluder(viewer.camera).isPointVisible(marker.position);
|
* camera port's pose; null without a camera.
|
||||||
|
*/
|
||||||
|
function cameraBasis() {
|
||||||
|
const pose = viewer ? findCamera(viewer)?.pose() : null;
|
||||||
|
return pose?.right && pose?.up
|
||||||
|
? { camera: { rightWC: pose.right, upWC: pose.up } }
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function markerRotation(marker) {
|
function markerRotation(marker, basis = cameraBasis()) {
|
||||||
if (!viewer?.scene || !marker.position) return marker.lastRotation;
|
if (!basis || !marker.position) return marker.lastRotation;
|
||||||
const projected = screenProjectedRotation(
|
const projected = screenProjectedRotation(
|
||||||
viewer.scene,
|
basis,
|
||||||
marker.position,
|
marker.position,
|
||||||
marker.courseDeg ?? 0,
|
marker.courseDeg ?? 0,
|
||||||
marker.lastRotation,
|
marker.lastRotation,
|
||||||
@@ -222,10 +244,11 @@ export function createLocalAdsbLayer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fixPosition(marker, fix) {
|
function fixPosition(marker, fix) {
|
||||||
return Cesium.Cartesian3.fromDegrees(
|
return fromDegreesInto(
|
||||||
fix.lon,
|
fix.lon,
|
||||||
fix.lat,
|
fix.lat,
|
||||||
renderHeightM(marker, fix.altitudeFt, fix.lat, fix.lon),
|
renderHeightM(marker, fix.altitudeFt, fix.lat, fix.lon),
|
||||||
|
{ x: 0, y: 0, z: 0 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,12 +257,11 @@ export function createLocalAdsbLayer({
|
|||||||
if (!display) return;
|
if (!display) return;
|
||||||
marker.lat = display.lat;
|
marker.lat = display.lat;
|
||||||
marker.lon = display.lon;
|
marker.lon = display.lon;
|
||||||
marker.position = Cesium.Cartesian3.fromDegrees(
|
marker.position = fromDegreesInto(
|
||||||
display.lon,
|
display.lon,
|
||||||
display.lat,
|
display.lat,
|
||||||
renderHeightM(marker, display.altitudeFt, display.lat, display.lon),
|
renderHeightM(marker, display.altitudeFt, display.lat, display.lon),
|
||||||
Cesium.Ellipsoid.WGS84,
|
marker.position || { x: 0, y: 0, z: 0 },
|
||||||
marker.position || new Cesium.Cartesian3(),
|
|
||||||
);
|
);
|
||||||
if (display.courseDeg !== null) marker.courseDeg = display.courseDeg;
|
if (display.courseDeg !== null) marker.courseDeg = display.courseDeg;
|
||||||
}
|
}
|
||||||
@@ -258,17 +280,12 @@ export function createLocalAdsbLayer({
|
|||||||
);
|
);
|
||||||
marker.evidence = evidence;
|
marker.evidence = evidence;
|
||||||
marker.klass = klass;
|
marker.klass = klass;
|
||||||
const billboard = marker.entity?.billboard;
|
if (!marker.carrier) return;
|
||||||
if (!billboard) return;
|
marker.iconKind = klass;
|
||||||
if (marker.iconKind !== klass) {
|
|
||||||
marker.iconKind = klass;
|
|
||||||
billboard.image = aircraftIcon(klass);
|
|
||||||
}
|
|
||||||
const scale = billboardScale(marker);
|
const scale = billboardScale(marker);
|
||||||
if (marker.iconScale !== scale) {
|
if (marker.iconScale !== scale) {
|
||||||
marker.iconScale = scale;
|
marker.iconScale = scale;
|
||||||
billboard.scale = scale;
|
entityRecord(marker.carrier).sprite.scale = scale;
|
||||||
entityRecord(marker.entity).sprite.scale = scale;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +323,8 @@ export function createLocalAdsbLayer({
|
|||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
layerId: LAYER_ID,
|
layerId: LAYER_ID,
|
||||||
dataSource,
|
// Hidden with the layer: the context store reads its `show`.
|
||||||
|
dataSource: sets?.markers ?? null,
|
||||||
layerName: LAYER_NAME,
|
layerName: LAYER_NAME,
|
||||||
source: localAdsbSourceText(record),
|
source: localAdsbSourceText(record),
|
||||||
label: localAdsbTitle(record),
|
label: localAdsbTitle(record),
|
||||||
@@ -331,20 +349,56 @@ export function createLocalAdsbLayer({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function uatRing(marker) {
|
/** A marker's icon, where and how it now draws. */
|
||||||
return new Cesium.PointGraphics({
|
function markerItem(marker, basis) {
|
||||||
|
return {
|
||||||
|
id: marker.id,
|
||||||
|
pos: marker.position,
|
||||||
|
image: aircraftIcon(marker.iconKind ?? 'airliner'),
|
||||||
|
size: [MARKER_SPRITE.width, MARKER_SPRITE.height],
|
||||||
|
scale: marker.iconScale ?? 1,
|
||||||
|
color,
|
||||||
|
scaleByDistance: MARKER_SPRITE.scaleByDistance,
|
||||||
|
rotationMode: 'screen',
|
||||||
|
rotation: markerRotation(marker, basis),
|
||||||
|
// The 3D model, once loaded and placed, is the visual instead.
|
||||||
|
show: !marker.modelOwnsVisual,
|
||||||
|
disableDepthTest: Number.POSITIVE_INFINITY,
|
||||||
|
displayRange: MARKER_RANGE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The thin ring around an aircraft heard only on 978 MHz UAT. */
|
||||||
|
function ringItem(marker) {
|
||||||
|
return {
|
||||||
|
id: marker.id,
|
||||||
|
pos: marker.position,
|
||||||
pixelSize: 24,
|
pixelSize: 24,
|
||||||
color: Cesium.Color.TRANSPARENT,
|
color: [0, 0, 0, 0],
|
||||||
outlineColor: uatRingColor,
|
outlineColor: uatRingColor,
|
||||||
outlineWidth: 1.5,
|
outlineWidth: 1.5,
|
||||||
scaleByDistance: new Cesium.NearFarScalar(1000, 3.0, 8_000_000, 0.5),
|
scaleByDistance: MARKER_SPRITE.scaleByDistance,
|
||||||
show: new Cesium.CallbackProperty(() => markerVisible(marker), false),
|
disableDepthTest: Number.POSITIVE_INFINITY,
|
||||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
displayRange: MARKER_RANGE,
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
// Rings pass picks through to their aircraft.
|
||||||
0,
|
pickable: false,
|
||||||
2_000_000,
|
};
|
||||||
),
|
}
|
||||||
});
|
|
||||||
|
/** Draw every marker, ring and the trail head as they now are. */
|
||||||
|
function drawMarkers() {
|
||||||
|
if (!sets) return;
|
||||||
|
const basis = cameraBasis();
|
||||||
|
const icons = [];
|
||||||
|
const rings = [];
|
||||||
|
for (const marker of markers.values()) {
|
||||||
|
if (!marker.position) continue;
|
||||||
|
icons.push(markerItem(marker, basis));
|
||||||
|
if (marker.uat) rings.push(ringItem(marker));
|
||||||
|
}
|
||||||
|
if (icons.length) sets.markers.upsert(icons);
|
||||||
|
if (rings.length) sets.rings.upsert(rings);
|
||||||
|
drawTrailHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Trail of the selected aircraft ──────────────────────────────────────
|
// ── Trail of the selected aircraft ──────────────────────────────────────
|
||||||
@@ -352,16 +406,51 @@ export function createLocalAdsbLayer({
|
|||||||
function releaseTrail() {
|
function releaseTrail() {
|
||||||
if (!selectedTrail) return;
|
if (!selectedTrail) return;
|
||||||
selectedTrail.trail?.destroy();
|
selectedTrail.trail?.destroy();
|
||||||
if (selectedTrail.head && viewer && !viewer.isDestroyed?.()) {
|
sets?.head.clear();
|
||||||
try {
|
|
||||||
viewer.entities.remove(selectedTrail.head);
|
|
||||||
} catch {
|
|
||||||
/* torn down */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selectedTrail = null;
|
selectedTrail = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The live head: the last heard fix to the extrapolated marker, dimmed
|
||||||
|
* where the surface hides it. Nothing while either end is unknown.
|
||||||
|
*
|
||||||
|
* A line dimmed behind the surface is built anew when it moves, so the
|
||||||
|
* head is redrawn when its fix changes, and otherwise at most
|
||||||
|
* `HEAD_REDRAW_MS` apart while the aircraft flies on; a still aircraft
|
||||||
|
* costs nothing a frame.
|
||||||
|
*/
|
||||||
|
function drawTrailHead() {
|
||||||
|
if (!sets || !selectedTrail?.headId) return;
|
||||||
|
const current = markers.get(selectedTrail.id);
|
||||||
|
const from = selectedTrail.lastFix;
|
||||||
|
const positions =
|
||||||
|
current?.position && from ? [from, { ...current.position }] : [];
|
||||||
|
const key = positions.map(({ x, y, z }) => `${x},${y},${z}`).join(';');
|
||||||
|
if (key === selectedTrail.drawnKey) return;
|
||||||
|
const at = now();
|
||||||
|
if (
|
||||||
|
from === selectedTrail.drawnFrom &&
|
||||||
|
at - selectedTrail.drawnAt < HEAD_REDRAW_MS
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
selectedTrail.drawnKey = key;
|
||||||
|
selectedTrail.drawnFrom = from;
|
||||||
|
selectedTrail.drawnAt = at;
|
||||||
|
sets.head.upsert([
|
||||||
|
{
|
||||||
|
// 'gev-trail' namespace: claimed by the trail pick owner so a click
|
||||||
|
// on the head segment never reads as empty space.
|
||||||
|
id: selectedTrail.headId,
|
||||||
|
positions,
|
||||||
|
widthPx: 2.5,
|
||||||
|
// Metres to a few km: straight is the ellipsoid's arc to the pixel.
|
||||||
|
mode: '3d',
|
||||||
|
style: { kind: 'solid', color: hexColor(LOCAL_ADSB_COLOR, 0.9) },
|
||||||
|
depthFailColor: hexColor(LOCAL_ADSB_COLOR, 0.45),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
function refreshTrail() {
|
function refreshTrail() {
|
||||||
const marker = selectedId ? markers.get(selectedId) : null;
|
const marker = selectedId ? markers.get(selectedId) : null;
|
||||||
if (!marker || !selectedTrail?.trail) return;
|
if (!marker || !selectedTrail?.trail) return;
|
||||||
@@ -375,32 +464,20 @@ export function createLocalAdsbLayer({
|
|||||||
function startTrail(marker) {
|
function startTrail(marker) {
|
||||||
releaseTrail();
|
releaseTrail();
|
||||||
const createTrail = services.trails?.createTrail;
|
const createTrail = services.trails?.createTrail;
|
||||||
if (typeof createTrail !== 'function' || !viewer?.entities) return;
|
if (typeof createTrail !== 'function' || !viewer || !sets) return;
|
||||||
selectedTrail = {
|
selectedTrail = {
|
||||||
id: marker.id,
|
id: marker.id,
|
||||||
trail: createTrail(viewer, { color: LOCAL_ADSB_COLOR, width: 2.5 }),
|
trail: createTrail(viewer, { color: LOCAL_ADSB_COLOR, width: 2.5 }),
|
||||||
head: null,
|
// Live head: last heard fix → the extrapolated marker, every frame.
|
||||||
|
headId: `gev-trail:local-adsb-head-${++trailHeadSeq}`,
|
||||||
lastFix: null,
|
lastFix: null,
|
||||||
|
// Where, from which fix and when the head was last drawn.
|
||||||
|
drawnKey: null,
|
||||||
|
drawnFrom: null,
|
||||||
|
drawnAt: -Infinity,
|
||||||
};
|
};
|
||||||
// Live head: last heard fix → the extrapolated marker, every frame.
|
|
||||||
selectedTrail.head = viewer.entities.add({
|
|
||||||
// 'gev-trail' namespace: claimed by the trail pick owner so a click on
|
|
||||||
// the head segment never reads as empty space.
|
|
||||||
id: `gev-trail:local-adsb-head-${++trailHeadSeq}`,
|
|
||||||
polyline: {
|
|
||||||
positions: new Cesium.CallbackProperty(() => {
|
|
||||||
const current = markers.get(selectedTrail?.id);
|
|
||||||
const from = selectedTrail?.lastFix;
|
|
||||||
if (!current?.position || !from) return [];
|
|
||||||
return [from, Cesium.Cartesian3.clone(current.position)];
|
|
||||||
}, false),
|
|
||||||
width: 2.5,
|
|
||||||
material: color.withAlpha(0.9),
|
|
||||||
depthFailMaterial: color.withAlpha(0.45),
|
|
||||||
arcType: Cesium.ArcType.GEODESIC,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
refreshTrail();
|
refreshTrail();
|
||||||
|
drawTrailHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Markers ─────────────────────────────────────────────────────────────
|
// ── Markers ─────────────────────────────────────────────────────────────
|
||||||
@@ -411,7 +488,10 @@ export function createLocalAdsbLayer({
|
|||||||
if (!marker) {
|
if (!marker) {
|
||||||
marker = {
|
marker = {
|
||||||
id,
|
id,
|
||||||
entity: null,
|
// What stands for the aircraft in the shared context store and the
|
||||||
|
// readout card.
|
||||||
|
carrier: null,
|
||||||
|
uat: false,
|
||||||
record,
|
record,
|
||||||
motion: new LocalAdsbMotion(),
|
motion: new LocalAdsbMotion(),
|
||||||
position: null,
|
position: null,
|
||||||
@@ -435,45 +515,19 @@ export function createLocalAdsbLayer({
|
|||||||
const newFix = marker.motion.observe(record, at);
|
const newFix = marker.motion.observe(record, at);
|
||||||
rejectedFixes += marker.motion.rejectedFixes - rejectedBefore;
|
rejectedFixes += marker.motion.rejectedFixes - rejectedBefore;
|
||||||
updateDisplay(marker, at);
|
updateDisplay(marker, at);
|
||||||
if (!marker.entity) {
|
if (!marker.carrier) {
|
||||||
marker.entity = dataSource.entities.add({
|
marker.carrier = { id };
|
||||||
id,
|
entityRecord(marker.carrier).trackedId = id;
|
||||||
position: new Cesium.CallbackProperty(() => marker.position, false),
|
// Sized from the record when the marker is followed (screen annotations).
|
||||||
billboard: {
|
entityRecord(marker.carrier).sprite = { ...MARKER_SPRITE, scale: 1 };
|
||||||
image: aircraftIcon('airliner'),
|
entityRecord(marker.carrier).displayPosition = () => marker.position;
|
||||||
width: MARKER_SPRITE.width,
|
|
||||||
height: MARKER_SPRITE.height,
|
|
||||||
scale: 1,
|
|
||||||
color,
|
|
||||||
sizeInMeters: false,
|
|
||||||
scaleByDistance: MARKER_SPRITE.scaleByDistance,
|
|
||||||
alignedAxis: Cesium.Cartesian3.ZERO,
|
|
||||||
rotation: new Cesium.CallbackProperty(
|
|
||||||
() => markerRotation(marker),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
show: new Cesium.CallbackProperty(
|
|
||||||
() => !marker.modelOwnsVisual && markerVisible(marker),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
|
||||||
0,
|
|
||||||
2_000_000,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
entityRecord(marker.entity).trackedId = id;
|
|
||||||
// Sized from the app when Cesium tracks the marker (screen annotations).
|
|
||||||
entityRecord(marker.entity).sprite = { ...MARKER_SPRITE, scale: 1 };
|
|
||||||
entityRecord(marker.entity).displayPosition = () => marker.position;
|
|
||||||
}
|
}
|
||||||
refreshClass(marker);
|
refreshClass(marker);
|
||||||
const uat = localAdsbIsUat(record);
|
const uat = localAdsbIsUat(record);
|
||||||
if (uat !== Boolean(marker.entity.point))
|
if (marker.uat && !uat) sets?.rings.remove([id]);
|
||||||
marker.entity.point = uat ? uatRing(marker) : undefined;
|
marker.uat = uat;
|
||||||
entityRecord(marker.entity).labelModel = cardModel(marker, at);
|
entityRecord(marker.carrier).labelModel = cardModel(marker, at);
|
||||||
registerEntityContext(marker.entity, contextMetadata(id, marker));
|
registerEntityContext(marker.carrier, contextMetadata(id, marker));
|
||||||
if (newFix && id === selectedId) refreshTrail();
|
if (newFix && id === selectedId) refreshTrail();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -488,8 +542,12 @@ export function createLocalAdsbLayer({
|
|||||||
function refreshSelectedCard() {
|
function refreshSelectedCard() {
|
||||||
const marker = selectedId ? markers.get(selectedId) : null;
|
const marker = selectedId ? markers.get(selectedId) : null;
|
||||||
if (!marker) return;
|
if (!marker) return;
|
||||||
entityRecord(marker.entity).labelModel = cardModel(marker, now());
|
entityRecord(marker.carrier).labelModel = cardModel(marker, now());
|
||||||
services.overlays?.refreshReadout?.(marker.entity);
|
services.overlays?.refreshReadout?.(marker.carrier);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSets(show) {
|
||||||
|
if (sets) for (const set of Object.values(sets)) set.show = show;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRenderHold() {
|
function updateRenderHold() {
|
||||||
@@ -512,7 +570,7 @@ export function createLocalAdsbLayer({
|
|||||||
function sync() {
|
function sync() {
|
||||||
clearTimeout(syncTimer);
|
clearTimeout(syncTimer);
|
||||||
syncTimer = null;
|
syncTimer = null;
|
||||||
if (!dataSource) return;
|
if (!sets) return;
|
||||||
const at = now();
|
const at = now();
|
||||||
const live = new Set();
|
const live = new Set();
|
||||||
let added = false;
|
let added = false;
|
||||||
@@ -523,13 +581,18 @@ export function createLocalAdsbLayer({
|
|||||||
live.add(upsertMarker(record, at));
|
live.add(upsertMarker(record, at));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let removed = false;
|
const gone = [];
|
||||||
|
const ringsGone = [];
|
||||||
for (const [id, marker] of markers) {
|
for (const [id, marker] of markers) {
|
||||||
if (live.has(id)) continue;
|
if (live.has(id)) continue;
|
||||||
if (marker.entity) dataSource.entities.remove(marker.entity);
|
|
||||||
markers.delete(id);
|
markers.delete(id);
|
||||||
removed = true;
|
gone.push(id);
|
||||||
|
if (marker.uat) ringsGone.push(id);
|
||||||
}
|
}
|
||||||
|
const removed = gone.length > 0;
|
||||||
|
if (removed) sets.markers.remove(gone);
|
||||||
|
// A points set redraws on removal: only when a ring goes.
|
||||||
|
if (ringsGone.length) sets.rings.remove(ringsGone);
|
||||||
// Expired aircraft take their 3D models (and pending loads) with them.
|
// Expired aircraft take their 3D models (and pending loads) with them.
|
||||||
if (removed) models?.retain(markers);
|
if (removed) models?.retain(markers);
|
||||||
if (selectedId && !live.has(selectedId))
|
if (selectedId && !live.has(selectedId))
|
||||||
@@ -540,8 +603,9 @@ export function createLocalAdsbLayer({
|
|||||||
if (getSelectedEntityContext()?.id !== selectedId) {
|
if (getSelectedEntityContext()?.id !== selectedId) {
|
||||||
selectedId = null;
|
selectedId = null;
|
||||||
releaseTrail();
|
releaseTrail();
|
||||||
} else services.overlays?.refreshReadout?.(selected.entity);
|
} else services.overlays?.refreshReadout?.(selected.carrier);
|
||||||
}
|
}
|
||||||
|
drawMarkers();
|
||||||
requestEnrichment();
|
requestEnrichment();
|
||||||
updateRenderHold();
|
updateRenderHold();
|
||||||
if (live.size || removed) governorRequestRender('local-adsb-update');
|
if (live.size || removed) governorRequestRender('local-adsb-update');
|
||||||
@@ -556,6 +620,7 @@ export function createLocalAdsbLayer({
|
|||||||
const at = now();
|
const at = now();
|
||||||
for (const marker of markers.values()) updateDisplay(marker, at);
|
for (const marker of markers.values()) updateDisplay(marker, at);
|
||||||
models?.frame(markers, displayPreferences(), at);
|
models?.frame(markers, displayPreferences(), at);
|
||||||
|
drawMarkers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function scheduleSync(nextState) {
|
function scheduleSync(nextState) {
|
||||||
@@ -574,21 +639,19 @@ export function createLocalAdsbLayer({
|
|||||||
const reselect = id === selectedId && selectedTrail?.id === id;
|
const reselect = id === selectedId && selectedTrail?.id === id;
|
||||||
selectedId = id;
|
selectedId = id;
|
||||||
enrichment.request(marker.record, { selected: true });
|
enrichment.request(marker.record, { selected: true });
|
||||||
entityRecord(marker.entity).labelModel = cardModel(marker, now());
|
entityRecord(marker.carrier).labelModel = cardModel(marker, now());
|
||||||
selectEntityContext(marker.entity);
|
selectEntityContext(marker.carrier);
|
||||||
if (!reselect) startTrail(marker);
|
if (!reselect) startTrail(marker);
|
||||||
governorRequestRender('local-adsb-selection');
|
governorRequestRender('local-adsb-selection');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id under a pick, through the shared pick-id resolver: a draw-set
|
||||||
|
* item's id (markers, the trail head) or a model's.
|
||||||
|
*/
|
||||||
function pickedId(picked) {
|
function pickedId(picked) {
|
||||||
const resolved = services.picking.resolvePickId?.(picked);
|
return services.picking.resolvePickId?.(picked) ?? null;
|
||||||
if (resolved !== undefined) return resolved;
|
|
||||||
if (typeof picked?.id === 'string') return picked.id;
|
|
||||||
if (typeof picked?.id?.id === 'string') return picked.id.id;
|
|
||||||
return typeof picked?.primitive?.id === 'string'
|
|
||||||
? picked.primitive.id
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ownedElsewhere(id) {
|
function ownedElsewhere(id) {
|
||||||
@@ -626,7 +689,7 @@ export function createLocalAdsbLayer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function installInteraction() {
|
function installInteraction() {
|
||||||
if (clickSubscription || !viewer?.scene?.canvas) return;
|
if (clickSubscription || !viewer) return;
|
||||||
clickSubscription = inputFor(viewer).onClick((event) => {
|
clickSubscription = inputFor(viewer).onClick((event) => {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
const target = clickTarget(event);
|
const target = clickTarget(event);
|
||||||
@@ -652,8 +715,8 @@ export function createLocalAdsbLayer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function installFrame() {
|
function installFrame() {
|
||||||
if (removePreRender || !viewer?.scene?.preRender?.addEventListener) return;
|
if (removePreRender || !viewer) return;
|
||||||
removePreRender = viewer.scene.preRender.addEventListener(frame);
|
removePreRender = findFrame(viewer)?.on('preRender', frame) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function releaseFrame() {
|
function releaseFrame() {
|
||||||
@@ -667,12 +730,12 @@ export function createLocalAdsbLayer({
|
|||||||
for (const marker of markers.values()) {
|
for (const marker of markers.values()) {
|
||||||
if (rows.length >= maxCount) break;
|
if (rows.length >= maxCount) break;
|
||||||
if (!marker.position) continue;
|
if (!marker.position) continue;
|
||||||
const carto = Cesium.Cartographic.fromCartesian(marker.position);
|
const carto = toLonLatH(marker.position);
|
||||||
rows.push({
|
rows.push({
|
||||||
id: marker.record.icao,
|
id: marker.record.icao,
|
||||||
label: localAdsbTitle(marker.record),
|
label: localAdsbTitle(marker.record),
|
||||||
callsign: marker.record.callsign,
|
callsign: marker.record.callsign,
|
||||||
position: Cesium.Cartesian3.clone(marker.position),
|
position: { ...marker.position },
|
||||||
latitude: marker.lat,
|
latitude: marker.lat,
|
||||||
longitude: marker.lon,
|
longitude: marker.lon,
|
||||||
altitudeM: carto?.height ?? 0,
|
altitudeM: carto?.height ?? 0,
|
||||||
@@ -695,18 +758,29 @@ export function createLocalAdsbLayer({
|
|||||||
|
|
||||||
init(nextViewer) {
|
init(nextViewer) {
|
||||||
viewer = nextViewer;
|
viewer = nextViewer;
|
||||||
dataSource = new Cesium.CustomDataSource(LAYER_ID);
|
const draw = drawOf(viewer);
|
||||||
dataSource.show = false;
|
const prefix = `${LAYER_ID}:${++instances}`;
|
||||||
viewer.dataSources.add(dataSource);
|
sets = {
|
||||||
if (viewer.scene?.primitives) {
|
markers: draw.icons({
|
||||||
models = createLocalAdsbModels({
|
id: `${prefix}:markers`,
|
||||||
viewer,
|
horizonCull: true,
|
||||||
color,
|
show: false,
|
||||||
resolveAsset,
|
}),
|
||||||
groundSnap: services.groundSnap?.createGroundSnap?.() || null,
|
rings: draw.points({
|
||||||
...(loadModel ? { loadModel } : {}),
|
id: `${prefix}:rings`,
|
||||||
});
|
horizonCull: true,
|
||||||
}
|
show: false,
|
||||||
|
pickable: false,
|
||||||
|
}),
|
||||||
|
head: draw.lines({ id: `${prefix}:trail-head`, show: false }),
|
||||||
|
};
|
||||||
|
models = createLocalAdsbModels({
|
||||||
|
viewer,
|
||||||
|
color: LOCAL_ADSB_COLOR,
|
||||||
|
resolveAsset,
|
||||||
|
groundSnap: services.groundSnap?.createGroundSnap?.() || null,
|
||||||
|
...(loadModel ? { loadModel } : {}),
|
||||||
|
});
|
||||||
services.geoid
|
services.geoid
|
||||||
?.ensureGeoidReady?.()
|
?.ensureGeoidReady?.()
|
||||||
?.then(() => {
|
?.then(() => {
|
||||||
@@ -723,7 +797,7 @@ export function createLocalAdsbLayer({
|
|||||||
|
|
||||||
async enable() {
|
async enable() {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
if (dataSource) dataSource.show = true;
|
showSets(true);
|
||||||
registerPickOwner(LAYER_ID, (pickedValue) => markers.has(pickedValue));
|
registerPickOwner(LAYER_ID, (pickedValue) => markers.has(pickedValue));
|
||||||
installInteraction();
|
installInteraction();
|
||||||
installFrame();
|
installFrame();
|
||||||
@@ -749,7 +823,7 @@ export function createLocalAdsbLayer({
|
|||||||
unregisterPickOwner(LAYER_ID);
|
unregisterPickOwner(LAYER_ID);
|
||||||
sync();
|
sync();
|
||||||
models?.clear();
|
models?.clear();
|
||||||
if (dataSource) dataSource.show = false;
|
showSets(false);
|
||||||
markSourcesChanged('local-adsb-disabled');
|
markSourcesChanged('local-adsb-disabled');
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -782,8 +856,8 @@ export function createLocalAdsbLayer({
|
|||||||
updateRenderHold();
|
updateRenderHold();
|
||||||
models?.destroy();
|
models?.destroy();
|
||||||
models = null;
|
models = null;
|
||||||
if (viewer && dataSource) viewer.dataSources.remove(dataSource, true);
|
if (sets) for (const set of Object.values(sets)) set.dispose();
|
||||||
dataSource = null;
|
sets = null;
|
||||||
viewer = null;
|
viewer = null;
|
||||||
void receiver.destroy?.();
|
void receiver.destroy?.();
|
||||||
},
|
},
|
||||||
|
|||||||
+266
-147
@@ -13,7 +13,31 @@ import {
|
|||||||
localAdsbStatus,
|
localAdsbStatus,
|
||||||
} from './index.js';
|
} from './index.js';
|
||||||
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
||||||
|
import { resolvePickId } from '../../data/pickRegistry.js';
|
||||||
|
import { toLonLatH } from '../../geo/ellipsoid.js';
|
||||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||||
|
import { hexColor } from '../../render/color.js';
|
||||||
|
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
|
||||||
|
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||||
|
|
||||||
|
const MAGENTA = hexColor('#ff4fd8');
|
||||||
|
|
||||||
|
/** The layer's live draw set whose id ends with `suffix`. */
|
||||||
|
function layerSet(draw, suffix) {
|
||||||
|
return [...draw.sets.values()].find(
|
||||||
|
(record) =>
|
||||||
|
!record.disposed &&
|
||||||
|
record.spec.id.startsWith('local-adsb:') &&
|
||||||
|
record.spec.id.endsWith(suffix),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The icon drawn for an aircraft, or undefined. */
|
||||||
|
const iconOf = (draw, id) => layerSet(draw, ':markers')?.items.get(id);
|
||||||
|
/** The 978 MHz ring drawn for an aircraft, or undefined. */
|
||||||
|
const ringOf = (draw, id) => layerSet(draw, ':rings')?.items.get(id);
|
||||||
|
/** Degrees of latitude where an aircraft's icon now is. */
|
||||||
|
const latitudeOf = (draw, id) => toLonLatH(iconOf(draw, id).pos).lat;
|
||||||
|
|
||||||
function fakeReceiver(initial = {}) {
|
function fakeReceiver(initial = {}) {
|
||||||
const state = {
|
const state = {
|
||||||
@@ -49,7 +73,13 @@ function fakeReceiver(initial = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fakeServices() {
|
function fakeServices() {
|
||||||
const calls = { registered: [], selected: [], cleared: [], removed: [] };
|
const calls = {
|
||||||
|
registered: [],
|
||||||
|
selected: [],
|
||||||
|
cleared: [],
|
||||||
|
removed: [],
|
||||||
|
carriers: new Map(),
|
||||||
|
};
|
||||||
let selected = null;
|
let selected = null;
|
||||||
return {
|
return {
|
||||||
calls,
|
calls,
|
||||||
@@ -59,6 +89,7 @@ function fakeServices() {
|
|||||||
registerEntityContext(entity, metadata) {
|
registerEntityContext(entity, metadata) {
|
||||||
entityRecord(entity).contextId = metadata.id;
|
entityRecord(entity).contextId = metadata.id;
|
||||||
calls.registered.push(metadata);
|
calls.registered.push(metadata);
|
||||||
|
calls.carriers.set(metadata.id, entity);
|
||||||
},
|
},
|
||||||
selectEntityContext(entity) {
|
selectEntityContext(entity) {
|
||||||
selected = { id: readEntityRecord(entity)?.contextId, entity };
|
selected = { id: readEntityRecord(entity)?.contextId, entity };
|
||||||
@@ -74,36 +105,29 @@ function fakeServices() {
|
|||||||
calls.removed.push({ layerId, retainIds: options?.retainIds });
|
calls.removed.push({ layerId, retainIds: options?.retainIds });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
picking: { registerPickOwner() {}, unregisterPickOwner() {} },
|
picking: {
|
||||||
|
registerPickOwner() {},
|
||||||
|
unregisterPickOwner() {},
|
||||||
|
resolvePickId,
|
||||||
|
},
|
||||||
detection: { markSourcesChanged() {} },
|
detection: { markSourcesChanged() {} },
|
||||||
overlays: { refreshReadout() {} },
|
overlays: { refreshReadout() {} },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function fakeViewer() {
|
/**
|
||||||
const sources = [];
|
* A viewer with a fake draw port and a camera port whose screen axes are
|
||||||
const camera = {
|
* east and north at (0°, 0°); `viewer` adds the Cesium-shaped members the
|
||||||
rightWC: new Cesium.Cartesian3(0, 1, 0),
|
* 3D models read.
|
||||||
upWC: new Cesium.Cartesian3(0, 0, 1),
|
*/
|
||||||
};
|
function fakeViewer(viewer = { scene: {} }) {
|
||||||
return {
|
const camera = fakeCameraPort({
|
||||||
sources,
|
pose: { right: { x: 0, y: 1, z: 0 }, up: { x: 0, y: 0, z: 1 } },
|
||||||
viewer: {
|
});
|
||||||
camera,
|
const { draw } = bindFakeDraw(viewer, { camera: camera.port });
|
||||||
scene: { camera },
|
const input = fakeInput(viewer);
|
||||||
entities: {
|
return { draw, viewer, input };
|
||||||
add: (entity) => entity,
|
|
||||||
remove() {},
|
|
||||||
},
|
|
||||||
dataSources: {
|
|
||||||
add(source) {
|
|
||||||
sources.push(source);
|
|
||||||
},
|
|
||||||
remove() {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function record(overrides = {}) {
|
function record(overrides = {}) {
|
||||||
@@ -160,9 +184,7 @@ function fakeFeeds(initial = {}) {
|
|||||||
|
|
||||||
/** A viewer whose camera looks down on (0°, 0°) from 50 km, with primitives. */
|
/** A viewer whose camera looks down on (0°, 0°) from 50 km, with primitives. */
|
||||||
function modelViewer(primitives) {
|
function modelViewer(primitives) {
|
||||||
const base = fakeViewer();
|
|
||||||
const camera = {
|
const camera = {
|
||||||
...base.viewer.camera,
|
|
||||||
positionWC: new Cesium.Cartesian3(6_378_137 + 50_000, 0, 0),
|
positionWC: new Cesium.Cartesian3(6_378_137 + 50_000, 0, 0),
|
||||||
positionCartographic: new Cesium.Cartographic(0, 0, 50_000),
|
positionCartographic: new Cesium.Cartographic(0, 0, 50_000),
|
||||||
directionWC: new Cesium.Cartesian3(-1, 0, 0),
|
directionWC: new Cesium.Cartesian3(-1, 0, 0),
|
||||||
@@ -172,28 +194,24 @@ function modelViewer(primitives) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return {
|
return fakeViewer({
|
||||||
...base,
|
camera,
|
||||||
viewer: {
|
scene: {
|
||||||
...base.viewer,
|
|
||||||
camera,
|
camera,
|
||||||
scene: {
|
primitives: {
|
||||||
camera,
|
add(collection) {
|
||||||
primitives: {
|
primitives.push(collection);
|
||||||
add(collection) {
|
return collection;
|
||||||
primitives.push(collection);
|
|
||||||
return collection;
|
|
||||||
},
|
|
||||||
remove() {},
|
|
||||||
},
|
},
|
||||||
|
remove() {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function enabledLayer(receiver, clock, feeds = null, options = {}) {
|
async function enabledLayer(receiver, clock, feeds = null, options = {}) {
|
||||||
const { services, calls } = fakeServices();
|
const { services, calls } = fakeServices();
|
||||||
const { sources, viewer } = options.viewer || fakeViewer();
|
const { draw, viewer } = options.viewer || fakeViewer();
|
||||||
const layer = createLocalAdsbLayer({
|
const layer = createLocalAdsbLayer({
|
||||||
receiver,
|
receiver,
|
||||||
feeds,
|
feeds,
|
||||||
@@ -203,7 +221,7 @@ async function enabledLayer(receiver, clock, feeds = null, options = {}) {
|
|||||||
});
|
});
|
||||||
layer.init(viewer);
|
layer.init(viewer);
|
||||||
await layer.enable();
|
await layer.enable();
|
||||||
return { layer, calls, sources };
|
return { layer, calls, draw };
|
||||||
}
|
}
|
||||||
|
|
||||||
test('enabling Local ADS-B asks the shared tuner for 1090 MHz; disabling leaves it alone', async (t) => {
|
test('enabling Local ADS-B asks the shared tuner for 1090 MHz; disabling leaves it alone', async (t) => {
|
||||||
@@ -225,47 +243,39 @@ test('enabling Local ADS-B asks the shared tuner for 1090 MHz; disabling leaves
|
|||||||
test('local aircraft use their class silhouette and scale in magenta', async (t) => {
|
test('local aircraft use their class silhouette and scale in magenta', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock);
|
const { layer, draw, calls } = await enabledLayer(receiver, clock);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
receiver.set({
|
receiver.set({
|
||||||
aircraft: [record(), record({ icao: 'a0b702', category: 'A7' })],
|
aircraft: [record(), record({ icao: 'a0b702', category: 'A7' })],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
|
|
||||||
const entity = sources[0].entities.getById('local-adsb:abc123');
|
const icon = iconOf(draw, 'local-adsb:abc123');
|
||||||
assert.ok(entity);
|
assert.ok(icon);
|
||||||
assert.equal(entity.point, undefined);
|
assert.equal(ringOf(draw, 'local-adsb:abc123'), undefined);
|
||||||
assert.equal(entity.label, undefined);
|
assert.equal(icon.image, aircraftIcon('airliner'));
|
||||||
assert.equal(entity.billboard.image.getValue(), aircraftIcon('airliner'));
|
assert.deepEqual(icon.size, [20, 20]);
|
||||||
assert.equal(entity.billboard.width.getValue(), 20);
|
assert.deepEqual(icon.color, MAGENTA);
|
||||||
assert.ok(
|
assert.equal(icon.rotationMode, 'screen', 'upright on screen, turned');
|
||||||
Cesium.Color.equals(
|
assert.equal(icon.rotation, 0);
|
||||||
entity.billboard.color.getValue(),
|
assert.deepEqual(icon.displayRange, [0, 2_000_000]);
|
||||||
Cesium.Color.fromCssColorString('#ff4fd8'),
|
assert.equal(icon.disableDepthTest, Number.POSITIVE_INFINITY);
|
||||||
),
|
assert.equal(layerSet(draw, ':markers').spec.horizonCull, true);
|
||||||
);
|
const carrier = calls.carriers.get('local-adsb:abc123');
|
||||||
assert.ok(
|
assert.equal(readEntityRecord(carrier)?.labelModel.title, 'LOCAL1');
|
||||||
Cesium.Cartesian3.equals(
|
assert.equal(typeof readEntityRecord(carrier)?.displayPosition, 'function');
|
||||||
entity.billboard.alignedAxis.getValue(),
|
|
||||||
Cesium.Cartesian3.ZERO,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
assert.equal(entity.billboard.rotation.getValue(), 0);
|
|
||||||
assert.equal(readEntityRecord(entity)?.labelModel.title, 'LOCAL1');
|
|
||||||
assert.equal(typeof readEntityRecord(entity)?.displayPosition, 'function');
|
|
||||||
|
|
||||||
const heli = sources[0].entities.getById('local-adsb:a0b702');
|
const heli = () => iconOf(draw, 'local-adsb:a0b702');
|
||||||
assert.equal(heli.billboard.image.getValue(), aircraftIcon('helicopter'));
|
assert.equal(heli().image, aircraftIcon('helicopter'));
|
||||||
assert.equal(heli.billboard.scale.getValue(), CLASS_SCALE_2D.helicopter);
|
assert.equal(heli().scale, CLASS_SCALE_2D.helicopter);
|
||||||
assert.ok(
|
assert.deepEqual(
|
||||||
Cesium.Color.equals(
|
heli().color,
|
||||||
heli.billboard.color.getValue(),
|
MAGENTA,
|
||||||
Cesium.Color.fromCssColorString('#ff4fd8'),
|
|
||||||
),
|
|
||||||
'the helicopter keeps the local magenta',
|
'the helicopter keeps the local magenta',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
readEntityRecord(heli)?.labelModel.details[1],
|
readEntityRecord(calls.carriers.get('local-adsb:a0b702'))?.labelModel
|
||||||
|
.details[1],
|
||||||
'Helicopter · A7',
|
'Helicopter · A7',
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -281,10 +291,7 @@ test('local aircraft use their class silhouette and scale in magenta', async (t)
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
assert.equal(
|
assert.equal(heli().scale, CLASS_SCALE_2D.helicopter * 0.8);
|
||||||
heli.billboard.scale.getValue(),
|
|
||||||
CLASS_SCALE_2D.helicopter * 0.8,
|
|
||||||
);
|
|
||||||
|
|
||||||
const [detectable] = layer.getDetectableObjects();
|
const [detectable] = layer.getDetectableObjects();
|
||||||
assert.equal(detectable.sourceId, 'a0b702');
|
assert.equal(detectable.sourceId, 'a0b702');
|
||||||
@@ -294,12 +301,12 @@ test('local aircraft use their class silhouette and scale in magenta', async (t)
|
|||||||
test('the heading slews toward a new track instead of snapping', async (t) => {
|
test('the heading slews toward a new track instead of snapping', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock);
|
const { layer, draw } = await enabledLayer(receiver, clock);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
receiver.set({ aircraft: [record()] });
|
receiver.set({ aircraft: [record()] });
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const entity = sources[0].entities.getById('local-adsb:abc123');
|
const rotation = () => iconOf(draw, 'local-adsb:abc123').rotation;
|
||||||
assert.equal(entity.billboard.rotation.getValue(), 0);
|
assert.equal(rotation(), 0);
|
||||||
|
|
||||||
clock.now = 101_000;
|
clock.now = 101_000;
|
||||||
receiver.set({
|
receiver.set({
|
||||||
@@ -313,7 +320,7 @@ test('the heading slews toward a new track instead of snapping', async (t) => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const first = entity.billboard.rotation.getValue();
|
const first = rotation();
|
||||||
assert.ok(
|
assert.ok(
|
||||||
first > -Cesium.Math.PI_OVER_TWO && first <= 0,
|
first > -Cesium.Math.PI_OVER_TWO && first <= 0,
|
||||||
'one frame does not swing the nose 90°',
|
'one frame does not swing the nose 90°',
|
||||||
@@ -323,8 +330,7 @@ test('the heading slews toward a new track instead of snapping', async (t) => {
|
|||||||
await layer.update();
|
await layer.update();
|
||||||
}
|
}
|
||||||
assert.ok(
|
assert.ok(
|
||||||
Math.abs(entity.billboard.rotation.getValue() + Cesium.Math.PI_OVER_TWO) <
|
Math.abs(rotation() + Cesium.Math.PI_OVER_TWO) < 1e-6,
|
||||||
1e-6,
|
|
||||||
'the nose settles on the new track',
|
'the nose settles on the new track',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -332,14 +338,9 @@ test('the heading slews toward a new track instead of snapping', async (t) => {
|
|||||||
test('markers move in real time between fixes and never jump on a new fix', async (t) => {
|
test('markers move in real time between fixes and never jump on a new fix', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock);
|
const { layer, draw } = await enabledLayer(receiver, clock);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
const latitude = () =>
|
const latitude = () => latitudeOf(draw, 'local-adsb:abc123');
|
||||||
Cesium.Math.toDegrees(
|
|
||||||
Cesium.Cartographic.fromCartesian(
|
|
||||||
sources[0].entities.getById('local-adsb:abc123').position.getValue(),
|
|
||||||
).latitude,
|
|
||||||
);
|
|
||||||
// 180 kt due north: 1 s covers 92.6 m, 0.000833° of latitude.
|
// 180 kt due north: 1 s covers 92.6 m, 0.000833° of latitude.
|
||||||
const degPerSecond = (180 * 1852) / 3600 / 111_195;
|
const degPerSecond = (180 * 1852) / 3600 / 111_195;
|
||||||
receiver.set({ aircraft: [record({ lastPositionAt: 99_000 })] });
|
receiver.set({ aircraft: [record({ lastPositionAt: 99_000 })] });
|
||||||
@@ -376,7 +377,7 @@ test('markers move in real time between fixes and never jump on a new fix', asyn
|
|||||||
test('an implausible jump in a feed record is ignored by the display', async (t) => {
|
test('an implausible jump in a feed record is ignored by the display', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock);
|
const { layer, draw } = await enabledLayer(receiver, clock);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
receiver.set({ aircraft: [record({ groundSpeedKt: 120, trackDeg: 0 })] });
|
receiver.set({ aircraft: [record({ groundSpeedKt: 120, trackDeg: 0 })] });
|
||||||
await layer.update();
|
await layer.update();
|
||||||
@@ -392,11 +393,7 @@ test('an implausible jump in a feed record is ignored by the display', async (t)
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const lat = Cesium.Math.toDegrees(
|
const lat = latitudeOf(draw, 'local-adsb:abc123');
|
||||||
Cesium.Cartographic.fromCartesian(
|
|
||||||
sources[0].entities.getById('local-adsb:abc123').position.getValue(),
|
|
||||||
).latitude,
|
|
||||||
);
|
|
||||||
assert.ok(lat < 0.001, `stayed on its track (${lat})`);
|
assert.ok(lat < 0.001, `stayed on its track (${lat})`);
|
||||||
assert.equal(layer.getStats().rejectedPositions, 1);
|
assert.equal(layer.getStats().rejectedPositions, 1);
|
||||||
});
|
});
|
||||||
@@ -447,11 +444,81 @@ test('selecting an aircraft draws a magenta trail of the fixes the receiver hear
|
|||||||
assert.equal(trails[0].destroyed, true, 'the trail leaves with the aircraft');
|
assert.equal(trails[0].destroyed, true, 'the trail leaves with the aircraft');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the trail head runs from the last fix to the marker every frame, dimmed behind the surface', async (t) => {
|
||||||
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
|
const clock = { now: 100_000 };
|
||||||
|
const listeners = new Map();
|
||||||
|
const frame = {
|
||||||
|
on(event, callback) {
|
||||||
|
listeners.set(event, callback);
|
||||||
|
return () => listeners.delete(event);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const viewer = { scene: {} };
|
||||||
|
const camera = fakeCameraPort({
|
||||||
|
pose: { right: { x: 0, y: 1, z: 0 }, up: { x: 0, y: 0, z: 1 } },
|
||||||
|
});
|
||||||
|
const { draw } = bindFakeDraw(viewer, { camera: camera.port, frame });
|
||||||
|
const input = fakeInput(viewer);
|
||||||
|
const { layer } = await enabledLayer(receiver, clock, null, {
|
||||||
|
viewer: { draw, viewer, input },
|
||||||
|
services: {
|
||||||
|
trails: {
|
||||||
|
createTrail: () => ({ setPositions() {}, destroy() {} }),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
t.after(() => layer.destroy());
|
||||||
|
receiver.set({ aircraft: [record()] });
|
||||||
|
await layer.update();
|
||||||
|
assert.equal(layer.selectAircraft('abc123'), true);
|
||||||
|
const heads = () => [...layerSet(draw, ':trail-head').items.values()];
|
||||||
|
const [head] = heads();
|
||||||
|
assert.match(head.id, /^gev-trail:local-adsb-head-\d+$/);
|
||||||
|
assert.equal(head.mode, '3d');
|
||||||
|
assert.equal(head.widthPx, 2.5);
|
||||||
|
assert.deepEqual(head.style, {
|
||||||
|
kind: 'solid',
|
||||||
|
color: hexColor('#ff4fd8', 0.9),
|
||||||
|
});
|
||||||
|
assert.deepEqual(
|
||||||
|
head.depthFailColor,
|
||||||
|
hexColor('#ff4fd8', 0.45),
|
||||||
|
'dimmed, not hidden, behind the surface',
|
||||||
|
);
|
||||||
|
assert.equal(head.positions.length, 2);
|
||||||
|
assert.deepEqual(
|
||||||
|
head.positions[1],
|
||||||
|
iconOf(draw, 'local-adsb:abc123').pos,
|
||||||
|
'it ends at the marker',
|
||||||
|
);
|
||||||
|
|
||||||
|
// A frame alone moves the marker, its icon and the head's end.
|
||||||
|
const before = latitudeOf(draw, 'local-adsb:abc123');
|
||||||
|
clock.now = 101_000;
|
||||||
|
listeners.get('preRender')();
|
||||||
|
const after = latitudeOf(draw, 'local-adsb:abc123');
|
||||||
|
assert.ok(after > before, `the marker flew north (${before} → ${after})`);
|
||||||
|
assert.ok(
|
||||||
|
Math.abs(toLonLatH(heads()[0].positions[1]).lat - after) < 1e-9,
|
||||||
|
'the head follows the marker',
|
||||||
|
);
|
||||||
|
|
||||||
|
// A frame where nothing moved leaves the head alone.
|
||||||
|
const writes = layerSet(draw, ':trail-head').writes;
|
||||||
|
listeners.get('preRender')();
|
||||||
|
assert.equal(layerSet(draw, ':trail-head').writes, writes);
|
||||||
|
|
||||||
|
await layer.disable();
|
||||||
|
assert.equal(listeners.has('preRender'), false, 'frames stop when off');
|
||||||
|
assert.equal(heads().length, 0, 'the head leaves with the selection');
|
||||||
|
});
|
||||||
|
|
||||||
test('adsbdb type, operator and route reach the card for the selected aircraft only', async (t) => {
|
test('adsbdb type, operator and route reach the card for the selected aircraft only', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const queries = [];
|
const queries = [];
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock, null, {
|
const { layer, calls } = await enabledLayer(receiver, clock, null, {
|
||||||
services: {
|
services: {
|
||||||
enrichment: {
|
enrichment: {
|
||||||
async getEnrichment(query) {
|
async getEnrichment(query) {
|
||||||
@@ -480,7 +547,7 @@ test('adsbdb type, operator and route reach the card for the selected aircraft o
|
|||||||
assert.equal(layer.selectAircraft('a0b702'), true);
|
assert.equal(layer.selectAircraft('a0b702'), true);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||||
assert.deepEqual([...queries].sort(), ['route:EVC145', 'type:a0b702']);
|
assert.deepEqual([...queries].sort(), ['route:EVC145', 'type:a0b702']);
|
||||||
const entity = sources[0].entities.getById('local-adsb:a0b702');
|
const entity = calls.carriers.get('local-adsb:a0b702');
|
||||||
assert.deepEqual(readEntityRecord(entity)?.labelModel.details.slice(0, 4), [
|
assert.deepEqual(readEntityRecord(entity)?.labelModel.details.slice(0, 4), [
|
||||||
'ICAO A0B702 · EVC145',
|
'ICAO A0B702 · EVC145',
|
||||||
'Helicopter · A7',
|
'Helicopter · A7',
|
||||||
@@ -502,7 +569,7 @@ test('the DISPLAY 3D toggle gives local aircraft magenta class models', async (t
|
|||||||
const loads = [];
|
const loads = [];
|
||||||
const display = { models3d: true, models3dMode: 'proximity' };
|
const display = { models3d: true, models3dMode: 'proximity' };
|
||||||
const primitives = [];
|
const primitives = [];
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock, null, {
|
const { layer, draw } = await enabledLayer(receiver, clock, null, {
|
||||||
services: { display: { getParams: () => display } },
|
services: { display: { getParams: () => display } },
|
||||||
viewer: modelViewer(primitives),
|
viewer: modelViewer(primitives),
|
||||||
loadModel: async (options) => {
|
loadModel: async (options) => {
|
||||||
@@ -547,28 +614,24 @@ test('the DISPLAY 3D toggle gives local aircraft magenta class models', async (t
|
|||||||
assert.equal(model.colorBlendMode, Cesium.ColorBlendMode.MIX);
|
assert.equal(model.colorBlendMode, Cesium.ColorBlendMode.MIX);
|
||||||
assert.equal(model.colorBlendAmount, 0.94);
|
assert.equal(model.colorBlendAmount, 0.94);
|
||||||
assert.equal(model.show, true);
|
assert.equal(model.show, true);
|
||||||
const heli = sources[0].entities.getById('local-adsb:a0b702');
|
const heli = () => iconOf(draw, 'local-adsb:a0b702');
|
||||||
assert.equal(
|
assert.equal(heli().show, false, 'the model is the visual');
|
||||||
heli.billboard.show.getValue(),
|
|
||||||
false,
|
|
||||||
'the model is the visual',
|
|
||||||
);
|
|
||||||
const origin = Cesium.Matrix4.getTranslation(
|
const origin = Cesium.Matrix4.getTranslation(
|
||||||
model.modelMatrix,
|
model.modelMatrix,
|
||||||
new Cesium.Cartesian3(),
|
new Cesium.Cartesian3(),
|
||||||
);
|
);
|
||||||
assert.ok(Cesium.Cartesian3.distance(origin, heli.position.getValue()) < 1);
|
assert.ok(Cesium.Cartesian3.distance(origin, heli().pos) < 1);
|
||||||
|
|
||||||
display.models3d = false;
|
display.models3d = false;
|
||||||
await layer.update();
|
await layer.update();
|
||||||
assert.equal(model.destroyed || !primitives[0].contains(model), true);
|
assert.equal(model.destroyed || !primitives[0].contains(model), true);
|
||||||
assert.equal(heli.billboard.show.getValue(), true, 'the billboard is back');
|
assert.equal(heli().show, true, 'the icon is back');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('markers drop when the position is 60 s old and records when silent 60 s', async (t) => {
|
test('markers drop when the position is 60 s old and records when silent 60 s', async (t) => {
|
||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock);
|
const { layer, draw } = await enabledLayer(receiver, clock);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
receiver.set({
|
receiver.set({
|
||||||
aircraft: [
|
aircraft: [
|
||||||
@@ -583,7 +646,7 @@ test('markers drop when the position is 60 s old and records when silent 60 s',
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const entities = () => sources[0].entities.values.map((entity) => entity.id);
|
const entities = () => [...layerSet(draw, ':markers').items.keys()];
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
entities(),
|
entities(),
|
||||||
['local-adsb:abc123'],
|
['local-adsb:abc123'],
|
||||||
@@ -731,7 +794,7 @@ test('feed records merge with browser SDR records by ICAO and UAT-only aircraft
|
|||||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
const feeds = fakeFeeds();
|
const feeds = fakeFeeds();
|
||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const { layer, sources } = await enabledLayer(receiver, clock, feeds);
|
const { layer, draw, calls } = await enabledLayer(receiver, clock, feeds);
|
||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
assert.deepEqual(feeds.calls, ['start'], 'the feeds poll while enabled');
|
assert.deepEqual(feeds.calls, ['start'], 'the feeds poll while enabled');
|
||||||
|
|
||||||
@@ -750,31 +813,37 @@ test('feed records merge with browser SDR records by ICAO and UAT-only aircraft
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const shared = sources[0].entities.getById('local-adsb:abc123');
|
const shared = calls.carriers.get('local-adsb:abc123');
|
||||||
const uat = sources[0].entities.getById('local-adsb:a1b2c3');
|
const uat = calls.carriers.get('local-adsb:a1b2c3');
|
||||||
assert.equal(sources[0].entities.values.length, 2);
|
assert.equal(layerSet(draw, ':markers').items.size, 2);
|
||||||
assert.equal(
|
assert.ok(
|
||||||
Cesium.Cartographic.fromCartesian(
|
Math.abs(latitudeOf(draw, 'local-adsb:abc123') - 1) < 0.002,
|
||||||
shared.position.getValue(),
|
|
||||||
).latitude.toFixed(4),
|
|
||||||
Cesium.Math.toRadians(1).toFixed(4),
|
|
||||||
'the newer feed position wins',
|
'the newer feed position wins',
|
||||||
);
|
);
|
||||||
assert.equal(shared.point, undefined, 'heard on 1090 too: no UAT ring');
|
assert.equal(
|
||||||
|
ringOf(draw, 'local-adsb:abc123'),
|
||||||
|
undefined,
|
||||||
|
'heard on 1090 too: no UAT ring',
|
||||||
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
readEntityRecord(shared)?.labelModel.details.at(-1),
|
readEntityRecord(shared)?.labelModel.details.at(-1),
|
||||||
'Heard by your receiver · 1090 MHz + 978 MHz UAT · browser SDR + decoder feed',
|
'Heard by your receiver · 1090 MHz + 978 MHz UAT · browser SDR + decoder feed',
|
||||||
);
|
);
|
||||||
assert.ok(uat.point, 'a UAT-only aircraft carries the ring');
|
const ring = ringOf(draw, 'local-adsb:a1b2c3');
|
||||||
assert.equal(uat.point.outlineWidth.getValue(), 1.5);
|
assert.ok(ring, 'a UAT-only aircraft carries the ring');
|
||||||
assert.ok(
|
assert.equal(ring.outlineWidth, 1.5);
|
||||||
Cesium.Color.equals(uat.point.color.getValue(), Cesium.Color.TRANSPARENT),
|
assert.deepEqual(ring.color, [0, 0, 0, 0]);
|
||||||
|
assert.deepEqual(ring.outlineColor, hexColor('#ffb3ef'));
|
||||||
|
assert.deepEqual(
|
||||||
|
ring.displayRange,
|
||||||
|
[0, 2_000_000],
|
||||||
|
'shown within 2,000 km, as its aircraft is',
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.deepEqual(ring.pos, iconOf(draw, 'local-adsb:a1b2c3').pos);
|
||||||
Cesium.Color.equals(
|
assert.equal(layerSet(draw, ':rings').spec.horizonCull, true);
|
||||||
uat.billboard.color.getValue(),
|
assert.deepEqual(
|
||||||
Cesium.Color.fromCssColorString('#ff4fd8'),
|
iconOf(draw, 'local-adsb:a1b2c3').color,
|
||||||
),
|
MAGENTA,
|
||||||
'same magenta marker family',
|
'same magenta marker family',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -786,8 +855,65 @@ test('feed records merge with browser SDR records by ICAO and UAT-only aircraft
|
|||||||
assert.equal(stats.loadingLabel, '1 feed live · 2 heard');
|
assert.equal(stats.loadingLabel, '1 feed live · 2 heard');
|
||||||
assert.equal(stats.count, 2);
|
assert.equal(stats.count, 2);
|
||||||
|
|
||||||
|
// Heard on 1090 as well later: the ring goes.
|
||||||
|
feeds.set({
|
||||||
|
records: [
|
||||||
|
record({
|
||||||
|
icao: 'a1b2c3',
|
||||||
|
callsign: 'N978UA',
|
||||||
|
band: '1090',
|
||||||
|
source: 'feed',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
await layer.update();
|
||||||
|
assert.equal(ringOf(draw, 'local-adsb:a1b2c3'), undefined);
|
||||||
|
|
||||||
await layer.disable();
|
await layer.disable();
|
||||||
assert.deepEqual(feeds.calls, ['start', 'stop']);
|
assert.deepEqual(feeds.calls, ['start', 'stop']);
|
||||||
|
assert.equal(layerSet(draw, ':markers').show, false, 'hidden with the layer');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the layer draws into sets of its own, shown while it is enabled and let go when destroyed', async (t) => {
|
||||||
|
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||||
|
const feeds = fakeFeeds();
|
||||||
|
const clock = { now: 100_000 };
|
||||||
|
const first = fakeViewer();
|
||||||
|
const { layer, draw } = await enabledLayer(receiver, clock, feeds, {
|
||||||
|
viewer: first,
|
||||||
|
});
|
||||||
|
const other = await enabledLayer(fakeReceiver(), clock);
|
||||||
|
t.after(() => other.layer.destroy());
|
||||||
|
const ids = (port) =>
|
||||||
|
[...port.sets.values()]
|
||||||
|
.filter((record) => !record.disposed)
|
||||||
|
.map((record) => record.spec.id);
|
||||||
|
const mine = ids(draw);
|
||||||
|
assert.equal(mine.length, 3, 'markers, rings and the trail head');
|
||||||
|
assert.ok(
|
||||||
|
ids(other.draw).every((id) => !mine.includes(id)),
|
||||||
|
'a second layer has ids of its own',
|
||||||
|
);
|
||||||
|
for (const id of mine) assert.equal(draw.set(id).show, true, id);
|
||||||
|
|
||||||
|
feeds.set({
|
||||||
|
configured: true,
|
||||||
|
records: [record({ icao: 'a1b2c3', band: '978', source: 'feed' })],
|
||||||
|
});
|
||||||
|
await layer.update();
|
||||||
|
assert.ok(ringOf(draw, 'local-adsb:a1b2c3'));
|
||||||
|
// Silent long enough to expire: its ring goes with it.
|
||||||
|
clock.now = 200_000;
|
||||||
|
await layer.update();
|
||||||
|
assert.equal(iconOf(draw, 'local-adsb:a1b2c3'), undefined);
|
||||||
|
assert.equal(ringOf(draw, 'local-adsb:a1b2c3'), undefined);
|
||||||
|
|
||||||
|
await layer.disable();
|
||||||
|
for (const id of mine) assert.equal(draw.set(id).show, false, id);
|
||||||
|
await layer.enable();
|
||||||
|
for (const id of mine) assert.equal(draw.set(id).show, true, id);
|
||||||
|
layer.destroy();
|
||||||
|
assert.deepEqual(ids(draw), [], 'every set disposed');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('row status reflects decoder feeds and the browser SDR together', () => {
|
test('row status reflects decoder feeds and the browser SDR together', () => {
|
||||||
@@ -1053,11 +1179,14 @@ test('the last aircraft expiring removes its 3D model and cancels a pending load
|
|||||||
assert.equal(late.destroyed, true);
|
assert.equal(late.destroyed, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** A pick on a draw-port icon of the layer's, as the renderer reports it. */
|
||||||
|
function iconPick(id) {
|
||||||
|
return { primitive: {}, id: { set: 'local-adsb:1:markers', id } };
|
||||||
|
}
|
||||||
|
|
||||||
/** A viewer with a canvas and scripted picks, plus the layer's click action. */
|
/** A viewer with a canvas and scripted picks, plus the layer's click action. */
|
||||||
function clickHarness() {
|
function clickHarness() {
|
||||||
const base = fakeViewer();
|
|
||||||
const scene = {
|
const scene = {
|
||||||
...base.viewer.scene,
|
|
||||||
canvas: {},
|
canvas: {},
|
||||||
pickResult: null,
|
pickResult: null,
|
||||||
drillResult: [],
|
drillResult: [],
|
||||||
@@ -1068,13 +1197,12 @@ function clickHarness() {
|
|||||||
return scene.drillResult;
|
return scene.drillResult;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const viewer = { ...base.viewer, scene };
|
const base = fakeViewer({ scene });
|
||||||
const input = fakeInput(viewer);
|
|
||||||
return {
|
return {
|
||||||
scene,
|
scene,
|
||||||
viewer: { ...base, viewer },
|
viewer: base,
|
||||||
click() {
|
click() {
|
||||||
input.click(new Cesium.Cartesian2(10, 10));
|
base.input.click(new Cesium.Cartesian2(10, 10));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1089,9 +1217,7 @@ test('clicking the selected aircraft keeps it selected and republishes its card'
|
|||||||
t.after(() => layer.destroy());
|
t.after(() => layer.destroy());
|
||||||
receiver.set({ aircraft: [record()] });
|
receiver.set({ aircraft: [record()] });
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const entity =
|
harness.scene.pickResult = iconPick('local-adsb:abc123');
|
||||||
harness.viewer.sources[0].entities.getById('local-adsb:abc123');
|
|
||||||
harness.scene.pickResult = { id: entity, primitive: {} };
|
|
||||||
harness.click();
|
harness.click();
|
||||||
assert.deepEqual(calls.selected, ['local-adsb:abc123']);
|
assert.deepEqual(calls.selected, ['local-adsb:abc123']);
|
||||||
// Its card may have been displaced (another readout, a camera move): a
|
// Its card may have been displaced (another readout, a camera move): a
|
||||||
@@ -1106,7 +1232,6 @@ test('a click on a local aircraft under an unowned or trail pick still selects i
|
|||||||
const clock = { now: 100_000 };
|
const clock = { now: 100_000 };
|
||||||
const harness = clickHarness();
|
const harness = clickHarness();
|
||||||
const owners = new Map();
|
const owners = new Map();
|
||||||
const { resolvePickId } = await import('../../data/pickRegistry.js');
|
|
||||||
const { layer, calls } = await enabledLayer(receiver, clock, null, {
|
const { layer, calls } = await enabledLayer(receiver, clock, null, {
|
||||||
viewer: harness.viewer,
|
viewer: harness.viewer,
|
||||||
services: {
|
services: {
|
||||||
@@ -1129,7 +1254,7 @@ test('a click on a local aircraft under an unowned or trail pick still selects i
|
|||||||
});
|
});
|
||||||
await layer.update();
|
await layer.update();
|
||||||
const [first, second] = ['abc123', 'def456'].map((icao) =>
|
const [first, second] = ['abc123', 'def456'].map((icao) =>
|
||||||
harness.viewer.sources[0].entities.getById(`local-adsb:${icao}`),
|
iconPick(`local-adsb:${icao}`),
|
||||||
);
|
);
|
||||||
// A photoreal tile (no pick id) drawn over the 3D model at this pixel.
|
// A photoreal tile (no pick id) drawn over the 3D model at this pixel.
|
||||||
harness.scene.pickResult = { primitive: { tileset: true } };
|
harness.scene.pickResult = { primitive: { tileset: true } };
|
||||||
@@ -1142,19 +1267,13 @@ test('a click on a local aircraft under an unowned or trail pick still selects i
|
|||||||
|
|
||||||
// The selected aircraft's trail crosses another local aircraft's marker.
|
// The selected aircraft's trail crosses another local aircraft's marker.
|
||||||
harness.scene.pickResult = { id: { id: 'gev-trail:local-adsb-head-1' } };
|
harness.scene.pickResult = { id: { id: 'gev-trail:local-adsb-head-1' } };
|
||||||
harness.scene.drillResult = [
|
harness.scene.drillResult = [harness.scene.pickResult, second];
|
||||||
harness.scene.pickResult,
|
|
||||||
{ id: second, primitive: {} },
|
|
||||||
];
|
|
||||||
harness.click();
|
harness.click();
|
||||||
assert.deepEqual(calls.selected, ['local-adsb:abc123', 'local-adsb:def456']);
|
assert.deepEqual(calls.selected, ['local-adsb:abc123', 'local-adsb:def456']);
|
||||||
|
|
||||||
// Another layer's own contact on top is that layer's click.
|
// Another layer's own contact on top is that layer's click.
|
||||||
harness.scene.pickResult = { id: 'abc123', primitive: {} };
|
harness.scene.pickResult = { id: 'abc123', primitive: {} };
|
||||||
harness.scene.drillResult = [
|
harness.scene.drillResult = [harness.scene.pickResult, first];
|
||||||
harness.scene.pickResult,
|
|
||||||
{ id: first, primitive: {} },
|
|
||||||
];
|
|
||||||
harness.click();
|
harness.click();
|
||||||
assert.equal(calls.selected.length, 2, 'the Flights contact is not taken');
|
assert.equal(calls.selected.length, 2, 'the Flights contact is not taken');
|
||||||
});
|
});
|
||||||
@@ -36,11 +36,11 @@ const specKey = (spec) => `${spec.url}@${spec.scale}`;
|
|||||||
* offset, and without a resolved ground it stays a billboard.
|
* offset, and without a resolved ground it stays a billboard.
|
||||||
* @param {object} options
|
* @param {object} options
|
||||||
* @param {object} options.viewer Cesium viewer.
|
* @param {object} options.viewer Cesium viewer.
|
||||||
* @param {Cesium.Color} options.color Model tint.
|
* @param {string} options.color Model tint, a CSS colour.
|
||||||
* @param {(url: string) => string} options.resolveAsset
|
* @param {(url: string) => string} options.resolveAsset
|
||||||
* @param {object|null} [options.groundSnap] `createGroundSnap()` instance.
|
* @param {object|null} [options.groundSnap] `createGroundSnap()` instance.
|
||||||
* @param {(options: object) => Promise<object>} [options.loadModel]
|
* @param {(options: object) => Promise<object>} [options.loadModel]
|
||||||
* @returns {object}
|
* @returns {object|null} Null on a viewer that draws no primitives.
|
||||||
*/
|
*/
|
||||||
export function createLocalAdsbModels({
|
export function createLocalAdsbModels({
|
||||||
viewer,
|
viewer,
|
||||||
@@ -49,6 +49,8 @@ export function createLocalAdsbModels({
|
|||||||
groundSnap = null,
|
groundSnap = null,
|
||||||
loadModel = (options) => Cesium.Model.fromGltfAsync(options),
|
loadModel = (options) => Cesium.Model.fromGltfAsync(options),
|
||||||
}) {
|
}) {
|
||||||
|
if (!viewer.scene?.primitives) return null;
|
||||||
|
const tint = Cesium.Color.fromCssColorString(color);
|
||||||
const collection = new Cesium.PrimitiveCollection();
|
const collection = new Cesium.PrimitiveCollection();
|
||||||
viewer.scene.primitives.add(collection);
|
viewer.scene.primitives.add(collection);
|
||||||
/** @type {Map<string, import('../../data/modelRecord.js').ModelRecord>} id -> admitted model */
|
/** @type {Map<string, import('../../data/modelRecord.js').ModelRecord>} id -> admitted model */
|
||||||
@@ -97,7 +99,7 @@ export function createLocalAdsbModels({
|
|||||||
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
|
environmentMapOptions: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS,
|
||||||
minimumPixelSize: MODEL_MIN_PX,
|
minimumPixelSize: MODEL_MIN_PX,
|
||||||
scale: spec.scale,
|
scale: spec.scale,
|
||||||
color,
|
color: tint,
|
||||||
colorBlendMode: Cesium.ColorBlendMode.MIX,
|
colorBlendMode: Cesium.ColorBlendMode.MIX,
|
||||||
colorBlendAmount: spec.blendAmount,
|
colorBlendAmount: spec.blendAmount,
|
||||||
id,
|
id,
|
||||||
@@ -177,9 +179,9 @@ export function createLocalAdsbModels({
|
|||||||
if (!marker.onGround) return marker.position;
|
if (!marker.onGround) return marker.position;
|
||||||
const record = models.get(id);
|
const record = models.get(id);
|
||||||
// The vertical sample must hit the tile skin, not this aircraft's own
|
// The vertical sample must hit the tile skin, not this aircraft's own
|
||||||
// billboard or model.
|
// model (its icon draws over depth, which height samples pass through).
|
||||||
const height = groundSnap?.heightFor?.(viewer, id, marker.position, () =>
|
const height = groundSnap?.heightFor?.(viewer, id, marker.position, () =>
|
||||||
[marker.entity, record?.model].filter(Boolean),
|
[record?.model].filter(Boolean),
|
||||||
);
|
);
|
||||||
if (!Number.isFinite(height)) return null;
|
if (!Number.isFinite(height)) return null;
|
||||||
const carto = Cesium.Cartographic.fromCartesian(
|
const carto = Cesium.Cartographic.fromCartesian(
|
||||||
|
|||||||
@@ -2695,3 +2695,131 @@ test('the directions layer draws its markers, flowing route and maneuver dots on
|
|||||||
assert.equal(scene.added.length, 0, 'every set let go');
|
assert.equal(scene.added.length, 0, 'every set let go');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the local ADS-B layer draws its aircraft, 978 MHz rings and trail head on a viewer of its own', async (t) => {
|
||||||
|
// Materials check their uniforms against the DOM's image classes.
|
||||||
|
const names = ['HTMLCanvasElement', 'HTMLImageElement', 'ImageBitmap', 'OffscreenCanvas'];
|
||||||
|
const real = names.map((name) => globalThis[name]);
|
||||||
|
for (const name of names) globalThis[name] ??= class {};
|
||||||
|
t.after(() => names.forEach((name, i) => (globalThis[name] = real[i])));
|
||||||
|
await import('./frame.js');
|
||||||
|
const { createLocalAdsbLayer } = await import('../../layers/localAdsb/index.js');
|
||||||
|
const { fakeInput } = await import('../../input/testDoubles.mjs');
|
||||||
|
const { toLonLatH } = await import('../../geo/ellipsoid.js');
|
||||||
|
const scene = fakeScene();
|
||||||
|
// What a frame port over the scene listens to.
|
||||||
|
scene.preUpdate = new Cesium.Event();
|
||||||
|
scene.forceRender = () => {};
|
||||||
|
scene.pick = () => undefined;
|
||||||
|
scene.drillPick = () => [];
|
||||||
|
const viewer = {
|
||||||
|
scene,
|
||||||
|
clock: new Cesium.Clock(),
|
||||||
|
isDestroyed: () => false,
|
||||||
|
};
|
||||||
|
const clicks = fakeInput(viewer);
|
||||||
|
const noop = () => {};
|
||||||
|
const clock = { now: 100_000 };
|
||||||
|
const aircraft = (icao, band, lat) => ({
|
||||||
|
icao,
|
||||||
|
callsign: icao.toUpperCase(),
|
||||||
|
lat,
|
||||||
|
lon: 0,
|
||||||
|
altitudeFt: 10_000,
|
||||||
|
groundSpeedKt: 180,
|
||||||
|
trackDeg: 0,
|
||||||
|
verticalRateFpm: 0,
|
||||||
|
lastPositionAt: clock.now,
|
||||||
|
lastMessageAt: clock.now,
|
||||||
|
messageCount: 3,
|
||||||
|
band,
|
||||||
|
source: 'feed',
|
||||||
|
});
|
||||||
|
const records = [aircraft('abc123', '1090', 0), aircraft('a1b2c3', '978', 0.1)];
|
||||||
|
const layer = createLocalAdsbLayer({
|
||||||
|
receiver: {
|
||||||
|
getState: () => ({ aircraft: [] }),
|
||||||
|
subscribe: () => noop,
|
||||||
|
setMode: async () => true,
|
||||||
|
},
|
||||||
|
feeds: {
|
||||||
|
getState: () => ({ configured: true, feeds: [], records }),
|
||||||
|
subscribe: () => noop,
|
||||||
|
start: noop,
|
||||||
|
stop: noop,
|
||||||
|
},
|
||||||
|
services: {
|
||||||
|
render: { governorRequestRender: noop },
|
||||||
|
context: {
|
||||||
|
registerEntityContext: noop,
|
||||||
|
selectEntityContext: (carrier) => ({ id: 'local-adsb:abc123', carrier }),
|
||||||
|
getSelectedEntityContext: () => ({ id: 'local-adsb:abc123' }),
|
||||||
|
clearSelectedEntityContextForLayer: noop,
|
||||||
|
removeEntityContextsForLayer: noop,
|
||||||
|
},
|
||||||
|
picking: { registerPickOwner: noop, unregisterPickOwner: noop },
|
||||||
|
trails: { createTrail: () => ({ setPositions: noop, destroy: noop }) },
|
||||||
|
},
|
||||||
|
now: () => clock.now,
|
||||||
|
});
|
||||||
|
layer.init(viewer);
|
||||||
|
await layer.enable();
|
||||||
|
await layer.update();
|
||||||
|
assert.equal(layer.selectAircraft('abc123'), true);
|
||||||
|
|
||||||
|
const hostOf = (suffix) =>
|
||||||
|
scene.added.find((host) => host.drawSetId?.endsWith(suffix));
|
||||||
|
// Aircraft: magenta icons drawn over depth out to 2,000 km.
|
||||||
|
const markers = hostOf(':markers');
|
||||||
|
assert.ok(markers instanceof Cesium.BillboardCollection);
|
||||||
|
assert.equal(markers.length, 2);
|
||||||
|
const icon = markers.get(0);
|
||||||
|
assert.equal(icon.id.id, 'local-adsb:abc123');
|
||||||
|
assert.equal(icon.disableDepthTestDistance, Infinity);
|
||||||
|
assert.equal(icon.distanceDisplayCondition.far, 2_000_000);
|
||||||
|
assert.ok(icon.scaleByDistance instanceof Cesium.NearFarScalar);
|
||||||
|
assert.deepEqual(
|
||||||
|
[icon.scaleByDistance.near, icon.scaleByDistance.nearValue],
|
||||||
|
[1000, 3],
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
icon.color.equals(Cesium.Color.fromCssColorString('#ff4fd8')),
|
||||||
|
);
|
||||||
|
// The UAT-only aircraft's ring: an outline, shown as far as it is.
|
||||||
|
const rings = hostOf(':rings');
|
||||||
|
assert.ok(rings instanceof Cesium.PointPrimitiveCollection);
|
||||||
|
assert.equal(rings.length, 1);
|
||||||
|
const ring = rings.get(0);
|
||||||
|
assert.equal(ring.id.id, 'local-adsb:a1b2c3');
|
||||||
|
assert.equal(ring.outlineWidth, 1.5);
|
||||||
|
assert.equal(ring.color.alpha, 0);
|
||||||
|
assert.equal(ring.distanceDisplayCondition.far, 2_000_000);
|
||||||
|
// Selected at its fix, the head has no length yet.
|
||||||
|
const head = hostOf(':trail-head');
|
||||||
|
assert.equal(head.get(1).length, 0);
|
||||||
|
|
||||||
|
// A frame flies them on, in place.
|
||||||
|
const before = toLonLatH(icon.position).lat;
|
||||||
|
clock.now += 1_000;
|
||||||
|
scene.preRender.raiseEvent(scene, Cesium.JulianDate.now());
|
||||||
|
assert.equal(markers.get(0), icon, 'the same billboard');
|
||||||
|
assert.ok(toLonLatH(icon.position).lat > before);
|
||||||
|
assert.equal(rings.get(0).id.id, 'local-adsb:a1b2c3');
|
||||||
|
// The head now runs from the fix to the aircraft, dimmed, not hidden,
|
||||||
|
// behind the surface.
|
||||||
|
assert.equal(hostOf(':trail-head'), head, 'the same lines');
|
||||||
|
const deep = head.get(1);
|
||||||
|
assert.equal(deep.length, 1);
|
||||||
|
const line = deep.get(0);
|
||||||
|
assert.ok(line instanceof Cesium.Primitive);
|
||||||
|
assert.match(line.geometryInstances.id.id, /^gev-trail:local-adsb-head-/);
|
||||||
|
const fail = line.depthFailAppearance.material.uniforms.color;
|
||||||
|
assert.ok(
|
||||||
|
fail.equals(Cesium.Color.fromCssColorString('#ff4fd8').withAlpha(0.45)),
|
||||||
|
);
|
||||||
|
|
||||||
|
await layer.disable();
|
||||||
|
layer.destroy();
|
||||||
|
clicks.destroy();
|
||||||
|
assert.equal(hostOf(':markers'), undefined, 'every set let go');
|
||||||
|
});
|
||||||
@@ -50,7 +50,6 @@
|
|||||||
"src/layers/launches/launchPad.js",
|
"src/layers/launches/launchPad.js",
|
||||||
"src/layers/launches/orbitRendering.js",
|
"src/layers/launches/orbitRendering.js",
|
||||||
"src/layers/launches/rendering.js",
|
"src/layers/launches/rendering.js",
|
||||||
"src/layers/localAdsb/index.js",
|
|
||||||
"src/layers/localAdsb/models.js",
|
"src/layers/localAdsb/models.js",
|
||||||
"src/layers/military/lifecycle.js",
|
"src/layers/military/lifecycle.js",
|
||||||
"src/layers/military/motion.js",
|
"src/layers/military/motion.js",
|
||||||
|
|||||||
Reference in new issue
Block a user