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

+5 -6
View File
@@ -1,5 +1,3 @@
import { TRACKED_ICON_COLOR } from '../layers/military/policy.js';
import { TRACKED_CYAN } from '../layers/flights/policy.js';
import { createRendering as civilRendering } from '../layers/flights/rendering.js';
import { createRendering as militaryRendering } from '../layers/military/rendering.js';
import { createMilitarySnapshotRenderer } from '../layers/military/snapshotRenderer.js';
@@ -463,15 +461,16 @@ test('tint priorities cover normal, priority, emergency, tracking and Cockpit do
assert.equal(rendering._modelColor('civil'), red);
if (rendering._cockpitContactColor)
assert.equal(rendering._cockpitContactColor('civil'), red);
// Tracking never recolours: a tracked emergency stays red.
flightState._trackedIcao = 'civil';
assert.equal(
rendering._modelColor('civil'),
factory === civilRendering ? TRACKED_CYAN : TRACKED_ICON_COLOR,
);
assert.equal(rendering._modelColor('civil'), red);
flightState._trackedIcao = null;
flightState.records.data.set('civil', { emergency: null });
// An ordinary model draws its mesh's own colours, whatever the billboard's.
assert.deepEqual([...rendering._modelColor('civil')], [1, 1, 1, 1]);
flightState._trackedIcao = 'civil';
assert.deepEqual([...rendering._modelColor('civil')], [1, 1, 1, 1]);
flightState._trackedIcao = null;
}
});
+4 -5
View File
@@ -400,7 +400,7 @@ export function createAircraftModels({
minPixelSize: record.minPixelSize,
shading: _shadingOf(),
tint: record.tint ?? WHITE,
// The mesh's own colours, tinted while tracked or in an emergency;
// The mesh's own colours, tinted red in an emergency;
// the IR boost draws it flat white.
colorBlend: aircraftModelBlend(state._irBoost === true, record.tint),
environmentMap: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS.enabled,
@@ -828,10 +828,9 @@ export function createAircraftModels({
* in, can never stall or freeze the centering (the old model-graphic-on-entity failure mode).
*
* The model draws exactly as the fleet would draw this contact: the same
* asset at the same scale (its true size), only its
* tint the tracked colour; whether it draws at all is the fleet's rule too
* (`_trackedModelRegimeActive`). Selecting a contact changes its colour,
* never its size or form. */
* asset at the same scale (its true size) in the same colours; whether it
* draws at all is the fleet's rule too (`_trackedModelRegimeActive`).
* Selecting a contact changes neither its colour nor its size or form. */
function _updateTrackedModel() {
// A failed load is let go (the icon carries the contact); the budget
+5 -6
View File
@@ -18,11 +18,10 @@ const HIGHLIGHT = Object.freeze({ mode: 'highlight' });
const FLAT = Object.freeze({ mode: 'mix', amount: 1 });
/**
* How much of a tracked or emergency colour a model takes over its paint.
* Multiplying by a saturated tint zeroes every channel the tint lacks: the
* tracked cyan (no red) draws a red helicopter black and a white Cessna flat
* cyan. Mixed in at this share, the paint stays readable and the colour still
* marks the model.
* How much of an emergency colour a model takes over its paint. Multiplying
* by a saturated tint zeroes every channel the tint lacks: a cyan tint (no
* red) draws a red helicopter black and a white Cessna flat cyan. Mixed in at
* this share, the paint stays readable and the colour still marks the model.
*/
export const AIRCRAFT_MODEL_TINT_MIX = 0.3;
@@ -31,7 +30,7 @@ const TINTED = Object.freeze({ mode: 'mix', amount: AIRCRAFT_MODEL_TINT_MIX });
/**
* How an aircraft model's colour meets its mesh, as a draw item's
* `colorBlend`. White (no tint) multiplies (`highlight`), which draws the
* mesh's own colours as built. A tracked or emergency colour is mixed in at
* mesh's own colours as built. An emergency colour is mixed in at
* `AIRCRAFT_MODEL_TINT_MIX`, so it tints the mesh without hiding its paint.
* The IR boost draws the model flat white instead (`mix` at 1, unlit).
* @param {boolean} irBoost
+5 -5
View File
@@ -81,12 +81,12 @@ test('an untinted model draws its mesh in its own colours', () => {
}
});
test('the tracked and emergency tints keep every paint, never black or one flat colour', () => {
test('the emergency tints keep every paint, never black or one flat colour', () => {
const tints = {
'tracked cyan': flightsPolicy.TRACKED_CYAN,
emergency: flightsPolicy.EMERGENCY_TINT,
'military tracked': militaryPolicy.TRACKED_ICON_COLOR,
'military emergency': militaryPolicy.EMERGENCY_ICON_COLOR,
// Any saturated tint: one with no red once drew a red helicopter black.
cyan: [0, 1, 1, 1],
};
for (const [tintName, tint] of Object.entries(tints)) {
const blend = aircraftModelBlend(false, tint);
@@ -94,7 +94,7 @@ test('the tracked and emergency tints keep every paint, never black or one flat
for (const [paintName, paint] of Object.entries(PAINTS)) {
const out = blended(paint, tint, blend);
drawn[paintName] = out;
// Multiplying by the tracked cyan (no red) drew a red helicopter black.
// Multiplying by a tint with no red drew a red helicopter black.
paint.forEach((c, i) =>
assert.ok(
out[i] >= c * 0.6,
@@ -110,6 +110,6 @@ test('the tracked and emergency tints keep every paint, never black or one flat
});
test('the IR boost draws every model flat white whatever its tint', () => {
for (const tint of [null, flightsPolicy.TRACKED_CYAN])
for (const tint of [null, flightsPolicy.EMERGENCY_TINT])
assert.deepEqual(aircraftModelBlend(true, tint), { mode: 'mix', amount: 1 });
});
+27
View File
@@ -28,6 +28,33 @@ const sameColor = (a, b) =>
a.length === b.length &&
a.every((value, i) => value === b[i]));
/** `trackedIconColor`'s answers, by base colour then alpha. */
const tintsAtAlpha = new Map();
/**
* The tracked icon's colour: the contact's own colour (the one its fleet
* icon draws in), at `alpha`. Tracking never recolours a contact; only the
* alpha changes (faded while stale, clear while its model draws it). One
* frozen array per colour and alpha, so a frame allocates nothing.
* @param {ArrayLike<number>} color The contact's RGBA colour, 0..1.
* @param {number} alpha
* @returns {readonly number[]}
*/
export function trackedIconColor(color, alpha) {
if (color[3] === alpha && Object.isFrozen(color)) return color;
let byAlpha = tintsAtAlpha.get(color);
if (!byAlpha) {
byAlpha = new Map();
tintsAtAlpha.set(color, byAlpha);
}
let tint = byAlpha.get(alpha);
if (!tint) {
tint = Object.freeze([color[0], color[1], color[2], alpha]);
byAlpha.set(alpha, tint);
}
return tint;
}
/**
* Whether `setId` names another layer's tracked icon set: a layer must not
* take a pick of that icon for one of its own contacts.
+11
View File
@@ -5,6 +5,7 @@ import {
createTrackedAircraftIcon,
isOtherTrackedIconSet,
trackedContactHolder,
trackedIconColor,
} from './trackedAircraftIcon.js';
/** A viewer double with a fake draw port and a frame port whose preRender the test runs. */
@@ -188,3 +189,13 @@ test("a layer tells another layer's tracked icon set from its own sets", () => {
);
assert.equal(isOtherTrackedIconSet(undefined, 'military'), false);
});
test('the tracked icon keeps its contact\'s colour; only the alpha changes', () => {
const amber = Object.freeze([1, 0.72, 0, 1]);
assert.equal(trackedIconColor(amber, 1), amber, 'unchanged at its own alpha');
const stale = trackedIconColor(amber, 0.45);
assert.deepEqual(stale, [1, 0.72, 0, 0.45]);
assert.equal(trackedIconColor(amber, 0.45), stale, 'one array per alpha');
assert.ok(Object.isFrozen(stale));
assert.deepEqual(trackedIconColor(amber, 0), [1, 0.72, 0, 0]);
});
+6 -4
View File
@@ -1321,10 +1321,11 @@ for (const fixture of LAYERS) {
fleetItem.minPixelSize,
'the same minimum pixel size',
);
assert.notDeepEqual(
trackedItem.tint,
fleetItem.tint,
'only the colour differs',
assert.deepEqual(trackedItem.tint, fleetItem.tint, 'the same colour');
assert.deepEqual(
trackedItem.colorBlend,
fleetItem.colorBlend,
'the same colour blend',
);
} finally {
fixture.layer.setParams({ models3d: false });
@@ -1355,6 +1356,7 @@ for (const fixture of LAYERS) {
fleet.scaleByDistance,
'the same scale by distance',
);
assert.deepEqual(tracked.color, fleet.color, 'the same colour');
// A landing changes the fleet icon's scale, and the tracked one's with it.
fixture.seed({ viewer, onGround: true });
const grounded = fixture.trackedIconLook(ICAO);
-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',