fix(selection): selecting or tracking a contact never recolours it

A tracked aircraft's icon and 3D model keep the colours they have
untracked in Flights and Military Flights (no cyan, no lighter amber);
only the icon's alpha changes (stale fade, clear while its model draws).
A selected vessel or aid keeps its type colour instead of white, and a
tracked satellite's dot keeps its class colour instead of yellow. An
emergency stays red while tracked.
This commit is contained in:
Sameh Khamis committed 2026-11-17 17:49:33 -08:00
1 parent 2f0c01eaa7
commit f49352d228
23 files changed
+192 -108

No files matched your search

-3
View File
@@ -95,9 +95,6 @@ export const MODEL_HEADING_OFFSET_DEG = 180;
/** A model's colour where it draws its mesh's own (`aircraftModelBlend`). */
export const MODEL_WHITE = rgba('#FFFFFF');
/** The tracked contact's tint, and its billboard once a model takes over. */
export const TRACKED_CYAN = rgba('#00FFFF');
export const CYAN_TRANSPARENT = rgba('#00FFFF', 0);
/** An ordinary fleet contact's tint. */
export const FLEET_TINT = rgba('#FFFFFF');
+2 -4
View File
@@ -8,7 +8,6 @@ import {
EMERGENCY_TINT,
VEHICLE_TINT,
FLEET_TINT,
TRACKED_CYAN,
GROUND_SCALE,
COCKPIT_CIVILIAN_COLOR,
} from './policy.js';
@@ -81,11 +80,10 @@ export function createRendering({
const _iconKind = (icao24, klass) =>
tr3bIconKind(icao24, klass, { hot: flightState._irBoost });
/** Model colour: the mesh's own (white), tinted cyan while tracked and red
* while broadcasting an emergency. */
/** Model colour: the mesh's own (white), tinted red while broadcasting an
* emergency. Tracking never recolours it. */
function _modelColor(icao24) {
if (icao24 === flightState._trackedIcao) return TRACKED_CYAN;
return _isEmergency(icao24) ? EMERGENCY_TINT : policy.MODEL_WHITE;
}
+13 -6
View File
@@ -1,4 +1,4 @@
import { CYAN_TRANSPARENT, TRACKED_CYAN } from './policy.js';
import { trackedIconColor } from '../../data/trackedAircraftIcon.js';
import { createModelRecord } from '../../data/modelRecord.js';
import {
aircraftIconTestSeams,
@@ -217,9 +217,11 @@ export function createTesting({
/** Evaluate the production tracked-billboard handoff colour for focused tests. */
function _trackedBillboardColorForTest() {
return parts.rendering._modelOwnsVisual(flightState._trackedIcao)
? CYAN_TRANSPARENT
: TRACKED_CYAN;
const icao24 = flightState._trackedIcao;
const color = parts.rendering._fleetBillboardColor(icao24);
return parts.rendering._modelOwnsVisual(icao24)
? trackedIconColor(color, 0)
: color;
}
/** Drive the exact fleet icon-to-model handoff used by `_fleetTick`. */
@@ -254,15 +256,20 @@ export function createTesting({
}
/** How the tracked billboard is drawn (`_trackedBillboardLook`,
* `_trackedSprite`) next to how the contact's fleet icon is (`_fleetLook`). */
* `_trackedSprite`, `_trackedIconColor`) next to how the contact's fleet
* icon is (`_fleetLook`, `_fleetBillboardColor`). */
function _trackedIconLookForTest(icao24) {
return {
tracked: {
...parts.tracking._trackedBillboardLook(),
sprite: parts.tracking._trackedSprite(icao24),
color: parts.tracking._trackedIconColor(),
},
fleet: {
...parts.icons._fleetLook(icao24),
color: parts.rendering._fleetBillboardColor(icao24),
},
fleet: parts.icons._fleetLook(icao24),
};
}
+13 -12
View File
@@ -15,6 +15,7 @@ import {
createTrackedAircraftIcon,
isOtherTrackedIconSet,
trackedContactHolder,
trackedIconColor,
} from '../../data/trackedAircraftIcon.js';
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
import { julianToEpochMs } from '../../geo/julian.js';
@@ -34,8 +35,6 @@ import {
COCKPIT_AIR_PROX_KEEP_M,
TRAIL_MAX_POINTS,
TRAIL_COLOR,
CYAN_TRANSPARENT,
TRACKED_CYAN,
STALE_ALPHA,
displayDelayMs,
followsClock,
@@ -65,8 +64,6 @@ function aircraftPickId(hit) {
return isOtherTrackedIconSet(hit.set, 'flights') ? undefined : hit.id;
}
const STALE_CYAN = Object.freeze([...TRACKED_CYAN.slice(0, 3), STALE_ALPHA]);
export function createTracking({
flightState,
services,
@@ -820,14 +817,18 @@ export function createTracking({
return { text: '', dimmed: false };
}
/** The tracked billboard's colour: cyan, faded while stale, clear while the 3D model is the visual. */
/** The tracked billboard's colour: the contact's own fleet colour (tracking
* never recolours it), faded while stale, clear while the 3D model is the
* visual. */
function _trackedIconColor() {
if (parts.rendering._modelOwnsVisual(flightState._trackedIcao))
return CYAN_TRANSPARENT;
return _trackedStaleCue(flightState._trackedIcao).dimmed
? STALE_CYAN
: TRACKED_CYAN;
const icao24 = flightState._trackedIcao;
const color = parts.rendering._fleetBillboardColor(icao24);
if (parts.rendering._modelOwnsVisual(icao24))
return trackedIconColor(color, 0);
return _trackedStaleCue(icao24).dimmed
? trackedIconColor(color, STALE_ALPHA)
: color;
}
/**
@@ -1082,13 +1083,13 @@ export function createTracking({
imageLod: _trackedBillboardLook().imageLod,
sprite,
position: getTrackedPosition,
// Solid cyan (faded while stale) when the billboard is the visual (zoomed out, 3D off,
// Its own colour (faded while stale) when the billboard is the visual (zoomed out, 3D off,
// or model still loading); transparent once the tracked model is actually up.
color: _trackedIconColor,
// Screen-projected rotation, evaluated per frame on the camera's own
// axes, so it stays exact through a tracked orbit. The tracked target
// must never vanish into tile geometry — tracking a taxiing plane at
// street level would otherwise bury the cyan icon inside the runway
// street level would otherwise bury the icon inside the runway
// skin, so it draws over depth like the fleet icon set; its
// shared-host tracked card is top-composited separately.
rotation: () => {
+11 -2
View File
@@ -6,7 +6,7 @@ import { createStubRenderer } from '../../render/stub/index.js';
import { createMotion } from './motion.js';
import { createFlightState } from './state.js';
import { createTracking } from './tracking.js';
import { RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
import { FLEET_TINT, RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
// A tracked trail is the aircraft's reports joined along the curve the icon
// is drawn along between them, so the icon always sits on its trail and a
@@ -116,7 +116,11 @@ function harness({
flightState.now = () => clock;
flightState._positionHistory.set(ICAO, fixes);
const parts = {
rendering: { _modelOwnsVisual: () => false, _modelSpec: () => ({}) },
rendering: {
_modelOwnsVisual: () => false,
_modelSpec: () => ({}),
_fleetBillboardColor: () => FLEET_TINT,
},
queries: { _contactLabel: (id, info) => info?.callsign || id },
};
parts.motion = createMotion({ flightState, services: svc, parts });
@@ -797,6 +801,11 @@ test('a stalled feed dims the tracked plane as STALE', () => {
dimmed: true,
});
assert.equal(h.tracking._trackedIconColor()[3], STALE_ALPHA);
assert.deepEqual(
h.tracking._trackedIconColor().slice(0, 3),
FLEET_TINT.slice(0, 3),
'faded in its own colour, never recoloured',
);
assert.equal(h.flightState.records.missingPolls.has(ICAO), false);
} finally {
h.restore();
-8
View File
@@ -31,10 +31,6 @@ export const BILLBOARD_SCALE = 0.7;
export const MIL_ICON_COLOR = rgba('#FFB800');
/** @constant {number[]} Lighter amber tint applied to the actively tracked aircraft */
export const TRACKED_ICON_COLOR = rgba('#FFD166');
/** @constant {number[]} Red tint for aircraft broadcasting an emergency (mirror of flights) */
export const EMERGENCY_ICON_COLOR = rgba(EMERGENCY_TINT_CSS);
@@ -106,10 +102,6 @@ export const COCKPIT_AIR_ALL_KEEP_M = 450000;
export const MODEL_HEADING_OFFSET_DEG = 180;
// every fleet model is nose -X: opposite Cesium heading 0
/** Amber fade target for the tracked billboard once the model takes over (mirrors flights.js CYAN_TRANSPARENT). */
export const AMBER_TRANSPARENT = rgba('#FFB800', 0);
export const COCKPIT_CONTACT_SIZE_PX = 6;
/** The tracked billboard's size by eye distance (the renderer's `NearFar`). */
+2 -4
View File
@@ -8,7 +8,6 @@ import {
BILLBOARD_SCALE,
GROUND_SCALE,
MIL_ICON_COLOR,
TRACKED_ICON_COLOR,
EMERGENCY_ICON_COLOR,
MODEL_WHITE,
} from './policy.js';
@@ -56,11 +55,10 @@ export function createRendering({
const _iconKind = (icao24, klass) =>
tr3bIconKind(icao24, klass, { hot: flightState._irBoost });
/** Model colour: the mesh's own (white), tinted amber while tracked and red
* while broadcasting an emergency. */
/** Model colour: the mesh's own (white), tinted red while broadcasting an
* emergency. Tracking never recolours it. */
function _modelColor(icao24) {
if (icao24 === flightState._trackedIcao) return TRACKED_ICON_COLOR;
const info = flightState.records.data.get(icao24);
return isEmergency(info?.emergency) ? EMERGENCY_ICON_COLOR : MODEL_WHITE;
}
+13 -6
View File
@@ -1,4 +1,4 @@
import { AMBER_TRANSPARENT, TRACKED_ICON_COLOR } from './policy.js';
import { trackedIconColor } from '../../data/trackedAircraftIcon.js';
import { createModelRecord } from '../../data/modelRecord.js';
import {
aircraftIconTestSeams,
@@ -170,9 +170,11 @@ export function createTesting({
/** Evaluate the production tracked-billboard handoff colour for focused tests. */
function _trackedBillboardColorForTest() {
return parts.rendering._modelOwnsVisual(flightState._trackedIcao)
? AMBER_TRANSPARENT
: TRACKED_ICON_COLOR;
const icao24 = flightState._trackedIcao;
const color = parts.rendering._fleetBillboardColor(icao24);
return parts.rendering._modelOwnsVisual(icao24)
? trackedIconColor(color, 0)
: color;
}
/** Drive the exact fleet icon-to-model handoff used by `_fleetTick`. */
@@ -194,15 +196,20 @@ export function createTesting({
}
/** How the tracked billboard is drawn (`_trackedBillboardLook`,
* `_trackedSprite`) next to how the contact's fleet icon is (`_fleetLook`). */
* `_trackedSprite`, `_trackedIconColor`) next to how the contact's fleet
* icon is (`_fleetLook`, `_fleetBillboardColor`). */
function _trackedIconLookForTest(icao24) {
return {
tracked: {
...parts.tracking._trackedBillboardLook(),
sprite: parts.tracking._trackedSprite(icao24),
color: parts.tracking._trackedIconColor(),
},
fleet: {
...parts.icons._fleetLook(icao24),
color: parts.rendering._fleetBillboardColor(icao24),
},
fleet: parts.icons._fleetLook(icao24),
};
}
+14 -17
View File
@@ -15,6 +15,7 @@ import {
createTrackedAircraftIcon,
isOtherTrackedIconSet,
trackedContactHolder,
trackedIconColor,
} from '../../data/trackedAircraftIcon.js';
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
import { julianToEpochMs } from '../../geo/julian.js';
@@ -36,8 +37,6 @@ import {
followsClock,
STALE_ALPHA,
TRAIL_COLOR,
AMBER_TRANSPARENT,
TRACKED_ICON_COLOR,
} from './policy.js';
import {
drawTrailSegments,
@@ -64,11 +63,6 @@ function aircraftPickId(hit) {
return isOtherTrackedIconSet(hit.set, 'military') ? undefined : hit.id;
}
const STALE_TRACKED_COLOR = Object.freeze([
...TRACKED_ICON_COLOR.slice(0, 3),
STALE_ALPHA,
]);
export function createTracking({
flightState,
services,
@@ -312,14 +306,18 @@ export function createTracking({
return { text: '', dimmed: false };
}
/** The tracked billboard's colour: amber, faded while stale, clear while the 3D model is the visual. */
/** The tracked billboard's colour: the contact's own fleet colour (tracking
* never recolours it), faded while stale, clear while the 3D model is the
* visual. */
function _trackedIconColor() {
if (parts.rendering._modelOwnsVisual(flightState._trackedIcao))
return AMBER_TRANSPARENT;
return _trackedStaleCue(flightState._trackedIcao).dimmed
? STALE_TRACKED_COLOR
: TRACKED_ICON_COLOR;
const icao24 = flightState._trackedIcao;
const color = parts.rendering._fleetBillboardColor(icao24);
if (parts.rendering._modelOwnsVisual(icao24))
return trackedIconColor(color, 0);
return _trackedStaleCue(icao24).dimmed
? trackedIconColor(color, STALE_ALPHA)
: color;
}
/**
@@ -1048,14 +1046,13 @@ export function createTracking({
imageLod: _trackedBillboardLook().imageLod,
sprite,
position: getTrackedPosition,
// Solid amber when the billboard is the visual (zoomed out, 3D off, or model still loading);
// transparent once the tracked model is actually up (ready + shown).
// Amber (faded while stale), transparent once the tracked model is the visual.
// Its own colour (faded while stale) when the billboard is the visual (zoomed out, 3D off,
// or model still loading); transparent once the tracked model is actually up (ready + shown).
color: _trackedIconColor,
// Screen-projected rotation, evaluated per frame on the camera's own
// axes, so it stays exact through a tracked orbit. The tracked target
// must never vanish into tile geometry — tracking a taxiing plane at
// street level would otherwise bury the amber icon inside the runway
// street level would otherwise bury the icon inside the runway
// skin, so it draws over depth like the fleet icon set; its
// shared-host tracked card is top-composited separately.
rotation: () => {
+11 -2
View File
@@ -6,7 +6,7 @@ import { createStubRenderer } from '../../render/stub/index.js';
import { createMotion } from './motion.js';
import { createFlightState } from './state.js';
import { createTracking } from './tracking.js';
import { RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
import { MIL_ICON_COLOR, RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
// A tracked military contact's trail is its reports joined along the curve
// the icon is drawn along between them, so the icon always sits on its trail
@@ -104,7 +104,11 @@ function harness({ fixes, info, nowMs, ground = () => null }) {
flightState.now = () => clock;
flightState._positionHistory.set(ICAO, fixes);
const parts = {
rendering: { _modelOwnsVisual: () => false, _modelSpec: () => ({}) },
rendering: {
_modelOwnsVisual: () => false,
_modelSpec: () => ({}),
_fleetBillboardColor: () => MIL_ICON_COLOR,
},
queries: {
_toCleanText: (value) => (typeof value === 'string' ? value.trim() : ''),
_formatAltitude: (ft) => `${ft} ft`,
@@ -649,6 +653,11 @@ test('military: a stalled feed dims the tracked plane as STALE', () => {
dimmed: true,
});
assert.equal(h.tracking._trackedIconColor()[3], STALE_ALPHA);
assert.deepEqual(
h.tracking._trackedIconColor().slice(0, 3),
MIL_ICON_COLOR.slice(0, 3),
'faded in its own colour, never recoloured',
);
assert.equal(h.flightState.records.missingPolls.has(ICAO), false);
} finally {
h.restore();
+10 -1
View File
@@ -271,13 +271,22 @@ test('the rendering part draws the dots, the tracked dot and the rings through t
state._enabled = true;
state._params = { showPoints: false, showOrbits: false };
let at = { x: 10, y: 20, z: 30 };
const carrier = rendering._addTrackedEntity({ position: () => at });
const issRed = [1, 0.27, 0.27, 1];
const carrier = rendering._addTrackedEntity({
position: () => at,
color: issRed,
});
assert.deepEqual(carrier, { noradId: 25544 });
const tracked = draw.set(points.replace(':points', ':tracked'));
assert.equal(tracked.items.size, 0);
rendering._preRenderTick({ frame: 3 });
assert.deepEqual(tracked.items.get('25544').pos, at);
assert.equal(tracked.items.get('25544').pixelSize, 14);
assert.deepEqual(
tracked.items.get('25544').color,
issRed,
'the satellite keeps its own colour',
);
assert.equal(tracked.items.get('25544').disableDepthTest, Infinity);
at = { x: 11, y: 21, z: 31 };
rendering._preRenderTick({ frame: 4 });
+8 -7
View File
@@ -34,12 +34,11 @@ const POINT_SCALE_BY_DISTANCE = Object.freeze({
});
/**
* The tracked satellite's dot: 14 px yellow with a white outline, drawn
* over everything.
* The tracked satellite's dot: 14 px in the satellite's own colour with a
* white outline, drawn over everything. Tracking never recolours it.
*/
const TRACKED_DOT = Object.freeze({
pixelSize: 14,
color: Object.freeze([1, 1, 0, 1]),
outlineColor: Object.freeze([1, 1, 1, 1]),
outlineWidth: 2,
disableDepthTest: Number.POSITIVE_INFINITY,
@@ -386,12 +385,13 @@ export function createRendering({
/**
* Draw the tracked satellite's dot and make the carrier the follow target
* and the tracked card read (its entity record holds the card).
* @param {{position: () => object, viewFrom: {x: number, y: number,
* z: number}}} options `position` is read as the follow camera reads
* it, once each frame before the tick moves the sample on.
* @param {{position: () => object, color: number[], viewFrom: {x: number,
* y: number, z: number}}} options `position` is read as the follow
* camera reads it, once each frame before the tick moves the sample on;
* `color` is the satellite's own dot colour.
* @returns {object} The carrier.
*/
function _addTrackedEntity({ position }) {
function _addTrackedEntity({ position, color }) {
const noradId = layerState._trackedNorad;
const carrier = { noradId };
trackedDot = {
@@ -400,6 +400,7 @@ export function createRendering({
id: String(noradId),
pos: { x: 0, y: 0, z: 0 },
...TRACKED_DOT,
color,
meta: { noradId },
},
drawn: false,
+2
View File
@@ -445,6 +445,8 @@ export function createTracking({ state: layerState, services, parts, source }) {
layerState._trackedEntity = parts.rendering._addTrackedEntity({
position: trackedPosition,
// Its own dot's colour: tracking never recolours a satellite.
color: parts.controls._pointStyleFor(noradId, sat.group).color,
viewFrom,
});
entityRecord(layerState._trackedEntity).selectionOrigin = origin;
+23
View File
@@ -600,6 +600,29 @@ test('an aid to navigation is drawn as the upright buoy, a vessel as its kind’
assert.deepEqual(sail.size, buoy.size);
});
test('selecting a vessel or an aid never changes its colour', async () => {
const aid = {
...observation('993672002'),
mmsi: '993672002',
type: 'Port Hand Mark',
speedMps: 0,
};
const ship = { ...observation('366999004'), type: 'Cargo' };
const { layer, icons } = setup({
async getSnapshot() {
return snapshot([aid, ship]);
},
});
await layer.update();
for (const [id, css] of [
['366999004', VESSEL_KIND_STYLES.cargo.css],
['993672002', AID_TO_NAVIGATION_STYLE.css],
]) {
assert.equal(layer.selectById(id), true);
assert.deepEqual(icons.item(id).color, cssColor(css), id);
}
});
test('a virtual aid to navigation keeps its buoy and its virtual flag', async () => {
const aid = {
...observation('993672009'),
+2 -5
View File
@@ -61,8 +61,6 @@ const HIDDEN_FOLLOW_MS = 250;
/** A vessel or aid sprite's drawn size before its scale (CSS px). */
const SHIP_ICON_PX = 32;
/** A selected vessel's or aid's tint. */
const SELECTED_TINT = Object.freeze([1, 1, 1, 1]);
let instances = 0;
@@ -413,7 +411,6 @@ export function createRendering({
/** The icon item a record draws, as it now is. */
function iconItem(record, visual) {
const selected = record === state.selectedRecord;
const aid = isAidToNavigation(record);
const courseDeg = vesselCourseDeg(record);
// Following the clock, not there yet at the time drawn.
@@ -430,8 +427,8 @@ export function createRendering({
pos: plan?.pos ?? visual.position,
image: shipIcon(record),
size: [SHIP_ICON_PX, SHIP_ICON_PX],
// Tinted by type; selection changes the colour only, never the size.
color: selected ? SELECTED_TINT : shipTint(record),
// Tinted by type; selection changes neither the colour nor the size.
color: shipTint(record),
scale: shipScale(record),
// An aid's buoy stands upright on screen; a vessel turns with course.
rotationMode: aid ? 'screen' : 'course',