mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Merge upstream main into pr/street-level-show-action
gevActions.test.mjs: keep the PR's street-level tests and main's analyst display tests.
This commit is contained in:
commit
5370b8a268
258 files changed
+20257
-734
No files matched your search
@@ -68,6 +68,9 @@ import { useLocationStore } from './stores/location.js';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
import { useGlobeActionsStore } from './stores/globeActions.js';
|
||||
import { useRecordingStore } from './stores/recording.js';
|
||||
import { onPlacePacksLoadingChange } from '../data/placeBelow.js';
|
||||
import { withPlacePacks } from './placePacksLoading.js';
|
||||
import { preloadOwnerFlags } from './ownerFlag.js';
|
||||
|
||||
/**
|
||||
* Central UI orchestrator for the God's Eye View application.
|
||||
@@ -162,8 +165,15 @@ export class StyleManager extends ShellFacade {
|
||||
// Vue views share this runtime and its stores; dispose unmounts them.
|
||||
this._ui = createUiRuntime({ pinia: applicationPinia() });
|
||||
this._feedback = new ShellFeedback({
|
||||
readLayers: () => this._dataManager?.getAll?.() || [],
|
||||
readLayers: () => withPlacePacks(this._dataManager?.getAll?.() || []),
|
||||
});
|
||||
// The satellite owner flags load with the app, not on the first ride.
|
||||
preloadOwnerFlags();
|
||||
// The place names under a Cockpit load on its first lookup: the loading
|
||||
// status names them meanwhile.
|
||||
this._offPlacePacks = onPlacePacksLoadingChange(() =>
|
||||
this._updateGlobalLoadingFeedback(),
|
||||
);
|
||||
this.viewer = viewer;
|
||||
this.mapStackController = mapStackController;
|
||||
this.placeSearch = placeSearch;
|
||||
@@ -366,6 +376,9 @@ export class StyleManager extends ShellFacade {
|
||||
flightsLayer: services.flightsLayer,
|
||||
militaryFlightsLayer: services.militaryFlightsLayer,
|
||||
aisLiveVesselsLayer: services.aisLiveVesselsLayer,
|
||||
satellitesLayer: services.satellitesLayer,
|
||||
// Orbit's Live Signals rows list and focus its mapped sites.
|
||||
militaryInstallationsLayer: services.militaryInstallationsLayer,
|
||||
isTr3b: services.isTr3b,
|
||||
toggleTr3b: services.toggleTr3b,
|
||||
militaryAwarenessLayer: services.militaryAwarenessLayer,
|
||||
@@ -380,6 +393,13 @@ export class StyleManager extends ShellFacade {
|
||||
fetchRegionalBrief: services.fetchRegionalBrief,
|
||||
regionalDistanceM: services.regionalDistanceM,
|
||||
weatherCodeLabel: services.weatherCodeLabel,
|
||||
// Orbit reads flat Esri imagery: Google 3D tiles stay coarse from
|
||||
// hundreds of kilometres up. The lease puts the map back on exit.
|
||||
acquireOrbitImagery: () =>
|
||||
this.mapStackController?.acquireImageryComparison?.({
|
||||
owner: 'cockpit-orbit',
|
||||
switchPolicy: 'esri-if-photoreal',
|
||||
}) ?? null,
|
||||
},
|
||||
elements: {
|
||||
_ppToggles: this._ppToggles,
|
||||
@@ -407,6 +427,8 @@ export class StyleManager extends ShellFacade {
|
||||
useCockpitStore(applicationPinia()).publishSignals(rows),
|
||||
radar: (view) =>
|
||||
useCockpitStore(applicationPinia()).publishRadar(view),
|
||||
orbital: (view) =>
|
||||
useCockpitStore(applicationPinia()).publishOrbital(view),
|
||||
utilityLayout: (layout) =>
|
||||
useCockpitStore(applicationPinia()).publishUtilityLayout(layout),
|
||||
},
|
||||
@@ -1835,6 +1857,7 @@ export class StyleManager extends ShellFacade {
|
||||
this._wildlifeSightingCard?.destroy();
|
||||
this._ui.destroy();
|
||||
this._panelChrome.destroy();
|
||||
this._offPlacePacks();
|
||||
this._feedback.destroy();
|
||||
|
||||
this._displayBindings.destroy();
|
||||
|
||||
@@ -245,3 +245,73 @@ test('a repaint that leaves focus outside the panel does not pull it back', asyn
|
||||
'an empty cohort renders no list',
|
||||
);
|
||||
});
|
||||
|
||||
const photo = (extra = {}) => ({
|
||||
src: 'https://t.plnspttrs.net/1/abc123_280.jpg',
|
||||
width: 280,
|
||||
height: 186,
|
||||
link: 'https://www.planespotters.net/photo/1/n123ab',
|
||||
credit: 'Photo © Jane Doe',
|
||||
...extra,
|
||||
});
|
||||
|
||||
test('a tracked flight’s photo shows under its name, credited and linked to its page', async (t) => {
|
||||
const { panel, publish } = fixture(t);
|
||||
await publish({ ...results(), photo: photo() });
|
||||
const root = panel();
|
||||
const link = root.querySelector('a.military-awareness-photo');
|
||||
assert.ok(link, 'the photo renders');
|
||||
assert.equal(
|
||||
root.querySelector('.military-awareness-subject').nextElementSibling,
|
||||
link,
|
||||
'directly under the subject line',
|
||||
);
|
||||
assert.equal(link.getAttribute('href'), photo().link);
|
||||
assert.equal(link.getAttribute('target'), '_blank');
|
||||
assert.equal(link.getAttribute('rel'), 'noopener');
|
||||
const img = link.querySelector('img');
|
||||
assert.equal(img.getAttribute('src'), photo().src);
|
||||
assert.equal(img.getAttribute('alt'), '');
|
||||
assert.equal(img.getAttribute('width'), '280');
|
||||
assert.equal(img.getAttribute('height'), '186');
|
||||
assert.equal(link.querySelector('small').textContent, 'Photo © Jane Doe');
|
||||
});
|
||||
|
||||
test('no photo renders without one', async (t) => {
|
||||
const { panel, publish } = fixture(t);
|
||||
await publish({ ...results(), photo: null });
|
||||
assert.equal(panel().querySelector('.military-awareness-photo'), null);
|
||||
});
|
||||
|
||||
test('a photo whose image fails to load is hidden until another arrives', async (t) => {
|
||||
const { panel, publish } = fixture(t);
|
||||
await publish({ ...results(), photo: photo() });
|
||||
panel()
|
||||
.querySelector('.military-awareness-photo img')
|
||||
.dispatchEvent(new Event('error'));
|
||||
await nextTick();
|
||||
assert.equal(panel().querySelector('.military-awareness-photo'), null);
|
||||
// A repaint with the same photo keeps it hidden.
|
||||
await publish({ ...results({ previousDisabled: false }), photo: photo() });
|
||||
assert.equal(panel().querySelector('.military-awareness-photo'), null);
|
||||
// Another plane's photo shows.
|
||||
const next = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' });
|
||||
await publish({ ...results(), photo: next });
|
||||
assert.equal(
|
||||
panel().querySelector('.military-awareness-photo img').getAttribute('src'),
|
||||
next.src,
|
||||
);
|
||||
});
|
||||
|
||||
test('a late error from a previous photo’s image does not hide the current one', async (t) => {
|
||||
const { panel, publish } = fixture(t);
|
||||
const previous = photo();
|
||||
const current = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' });
|
||||
await publish({ ...results(), photo: current });
|
||||
// The error belongs to the image that failed: here, one still on the old src.
|
||||
const img = panel().querySelector('.military-awareness-photo img');
|
||||
img.setAttribute('src', previous.src);
|
||||
img.dispatchEvent(new Event('error'));
|
||||
await nextTick();
|
||||
assert.ok(panel().querySelector('.military-awareness-photo'));
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
// src/ui/cockpitBodyClasses.test.mjs — the classes the Cockpit puts on
|
||||
// <body> must not also name an element's rule. A bare `.name { … }` written
|
||||
// for a panel matches <body> the moment <body> carries `name`, and its
|
||||
// pointer-events, position and overflow then apply to the whole page.
|
||||
// pointer-events, position and overflow then apply to the whole page (a
|
||||
// shared `cockpit-orbital` once made every click in orbit fall through).
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, readdirSync } from 'node:fs';
|
||||
@@ -52,7 +53,7 @@ function cockpitBodyClasses() {
|
||||
|
||||
test('the Cockpit adds its subject classes to <body>', () => {
|
||||
const classes = cockpitBodyClasses();
|
||||
for (const name of ['cockpit-mode', 'cockpit-bridge']) {
|
||||
for (const name of ['cockpit-mode', 'cockpit-bridge', 'cockpit-orbit']) {
|
||||
assert.ok(classes.includes(name), `${name} is not added to <body>`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -424,23 +424,33 @@ test("turning off the ridden aircraft's layer ends the cockpit", async (t) => {
|
||||
assert.equal(cockpit.active, false);
|
||||
});
|
||||
|
||||
test('C enters the selected vessel bridge and aircraft-only entry refuses it', async (t) => {
|
||||
const { cockpit } = fixture(t);
|
||||
test('BRIDGE enters the selected vessel bridge and aircraft-only entry refuses it', async (t) => {
|
||||
const { $, cockpit } = fixture(t);
|
||||
assert.equal(cockpit.enter({ kind: 'aircraft' }), false);
|
||||
const event = {
|
||||
key: 'c',
|
||||
target: document.body,
|
||||
defaultPrevented: false,
|
||||
preventDefault() {
|
||||
this.defaultPrevented = true;
|
||||
},
|
||||
stopImmediatePropagation() {},
|
||||
};
|
||||
cockpit.onKeyDown(event);
|
||||
cockpit.syncEntry();
|
||||
await settle();
|
||||
$('#cockpit-entry').click();
|
||||
await settle();
|
||||
assert.equal(cockpit.active, true);
|
||||
assert.equal(cockpit.subjectKind, 'vessel');
|
||||
assert.equal(event.defaultPrevented, true);
|
||||
});
|
||||
|
||||
test('C neither enters nor leaves the bridge; it stays the CCTV shortcut', async (t) => {
|
||||
const { cockpit } = fixture(t);
|
||||
const outside = press(cockpit, 'c');
|
||||
await settle();
|
||||
assert.equal(cockpit.active, false, 'C does not enter');
|
||||
assert.equal(outside.defaultPrevented, false);
|
||||
assert.equal(outside.propagationStopped, false);
|
||||
cockpit.enter();
|
||||
await settle();
|
||||
assert.equal(cockpit.subjectKind, 'vessel');
|
||||
for (const key of ['c', 'C']) {
|
||||
const inside = press(cockpit, key);
|
||||
assert.equal(cockpit.active, true, `${key} does not exit`);
|
||||
assert.equal(inside.defaultPrevented, false);
|
||||
assert.equal(inside.propagationStopped, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('C stays the CCTV shortcut when the bridge gate is shut', async (t) => {
|
||||
@@ -501,10 +511,13 @@ function press(
|
||||
repeat,
|
||||
target,
|
||||
defaultPrevented: false,
|
||||
propagationStopped: false,
|
||||
preventDefault() {
|
||||
this.defaultPrevented = true;
|
||||
},
|
||||
stopImmediatePropagation() {},
|
||||
stopImmediatePropagation() {
|
||||
this.propagationStopped = true;
|
||||
},
|
||||
};
|
||||
cockpit.onKeyDown(event);
|
||||
return event;
|
||||
@@ -696,11 +709,9 @@ test('a held arrow keeps turning the bridge view', async (t) => {
|
||||
assert.equal(event.defaultPrevented, true);
|
||||
}
|
||||
assert.equal(cockpit.lookTarget.yawDeg, -30);
|
||||
// A held Home or C still acts only once.
|
||||
// A held Home still acts only once.
|
||||
press(cockpit, 'Home', { repeat: true });
|
||||
assert.equal(cockpit.lookTarget.yawDeg, -30);
|
||||
press(cockpit, 'c', { repeat: true });
|
||||
assert.equal(cockpit.active, true);
|
||||
});
|
||||
|
||||
test('Home, 0 and LOOK AHEAD bring the bridge view back over the bow', async (t) => {
|
||||
@@ -844,6 +855,41 @@ test('arrows do nothing new in an aircraft cockpit', async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test('C neither enters nor leaves an aircraft cockpit', async (t) => {
|
||||
const aircraftInfo = {
|
||||
icao24: 'abc123',
|
||||
callsign: 'TEST1',
|
||||
latitude: 54.5,
|
||||
longitude: 10.2,
|
||||
altitudeM: 3000,
|
||||
velocityMps: 200,
|
||||
track: 45,
|
||||
onGround: false,
|
||||
};
|
||||
const { cockpit, viewer, aircraft } = fixture(t, { aircraftInfo });
|
||||
viewer.trackedEntity = aircraft;
|
||||
const outside = press(cockpit, 'c');
|
||||
await settle();
|
||||
assert.equal(cockpit.active, false, 'C does not enter');
|
||||
assert.equal(outside.defaultPrevented, false);
|
||||
assert.equal(outside.propagationStopped, false);
|
||||
assert.equal(cockpit.enter({ kind: 'aircraft' }), true);
|
||||
await settle();
|
||||
const inside = press(cockpit, 'c');
|
||||
assert.equal(cockpit.active, true, 'C does not exit');
|
||||
assert.equal(inside.propagationStopped, false);
|
||||
assert.doesNotMatch(
|
||||
document.querySelector('.cockpit-help').textContent,
|
||||
/C TOGGLE/,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
document
|
||||
.querySelector('#map-view-switch')
|
||||
.getAttribute('aria-keyshortcuts'),
|
||||
/C/,
|
||||
);
|
||||
});
|
||||
|
||||
/** The eye's ellipsoidal height in a placed camera, metres. */
|
||||
const eyeHeightM = (shot) =>
|
||||
Cesium.Cartographic.fromCartesian(shot.destination).height;
|
||||
@@ -1162,6 +1208,10 @@ test('both entries name the subject the same way', async () => {
|
||||
icon: 'directions_boat',
|
||||
label: 'BRIDGE',
|
||||
});
|
||||
assert.deepEqual(cockpitEntryFace('satellite'), {
|
||||
icon: 'satellite_alt',
|
||||
label: 'ORBIT',
|
||||
});
|
||||
assert.deepEqual(cockpitEntryFace('aircraft'), {
|
||||
icon: 'flight',
|
||||
label: 'COCKPIT',
|
||||
|
||||
@@ -153,7 +153,7 @@ export function maybeRefreshRegionalBrief(info) {
|
||||
!Number.isFinite(info.longitude)
|
||||
)
|
||||
return;
|
||||
const subjectId = `${info.layerId || 'aircraft'}:${info.icao24 || info.mmsi || info.registration || info.callsign || 'unknown'}`;
|
||||
const subjectId = `${info.layerId || 'aircraft'}:${info.icao24 || info.mmsi || info.noradId || info.registration || info.callsign || 'unknown'}`;
|
||||
if (subjectId !== this.regionalBriefSubjectId) {
|
||||
this.regionalBriefAbort?.abort();
|
||||
this.regionalBriefAbort = null;
|
||||
|
||||
@@ -57,6 +57,10 @@ export function update() {
|
||||
updateVessel.call(this, nowMs);
|
||||
return;
|
||||
}
|
||||
if (this.subjectKind === 'satellite') {
|
||||
this.updateOrbital(nowMs);
|
||||
return;
|
||||
}
|
||||
const info = this.readAircraftInfo();
|
||||
|
||||
// Adopt a newly selected track before the camera cadence gate. A context
|
||||
|
||||
+164
-2
@@ -1,6 +1,7 @@
|
||||
/** Coordinate Cockpit lifecycle through supplied aircraft, terrain, rendering and briefing operations. */
|
||||
import {
|
||||
readAircraftInfo,
|
||||
readSatelliteInfo,
|
||||
readVesselInfo,
|
||||
readSubjectLayerId,
|
||||
resolveEntryKind,
|
||||
@@ -15,6 +16,29 @@ import {
|
||||
exit,
|
||||
} from './cockpitTrackingController.js';
|
||||
import { update } from './cockpitCamera.js';
|
||||
import {
|
||||
beginOrbital,
|
||||
endOrbital,
|
||||
resetOrbitalLook,
|
||||
jumpToSensorSwath,
|
||||
onOrbitalWheel,
|
||||
stepOrbitalZoom,
|
||||
turnOrbitalLook,
|
||||
updateOrbital,
|
||||
updateOrbitalHud,
|
||||
} from './cockpitOrbitalView.js';
|
||||
import {
|
||||
onOrbitalClick,
|
||||
onOrbitalDoubleClick,
|
||||
routeSceneClick,
|
||||
toggleOrbitalFocus,
|
||||
} from './cockpitOrbitalFocus.js';
|
||||
import {
|
||||
handleOrbitalSignalClick,
|
||||
refreshOrbitalSignals,
|
||||
updateOrbitalSignals,
|
||||
} from './cockpitOrbitalSignals.js';
|
||||
import { rideOrbitalSatellite } from './cockpitOrbitalSatellites.js';
|
||||
import {
|
||||
publishInstrumentsView,
|
||||
publishRouteView,
|
||||
@@ -95,6 +119,7 @@ export class CockpitViewController {
|
||||
onCameraTakeover = null,
|
||||
isEntryAllowed = null,
|
||||
isBridgeEntryAllowed = null,
|
||||
isOrbitEntryAllowed = null,
|
||||
isUtilityDisclosureOpen = null,
|
||||
onEntered = null,
|
||||
onExited = null,
|
||||
@@ -108,10 +133,21 @@ export class CockpitViewController {
|
||||
this.destroyed = false;
|
||||
this.disposed = false;
|
||||
this.active = false;
|
||||
/** 'aircraft' or 'vessel' while active; which subject the camera rides. */
|
||||
/**
|
||||
* 'aircraft', 'vessel' or 'satellite' while active; which subject the
|
||||
* camera rides.
|
||||
*/
|
||||
this.subjectKind = null;
|
||||
/** The vessel subject's MMSI; aircraft are identified by trackedEntity. */
|
||||
/**
|
||||
* The vessel subject's MMSI or the satellite's NORAD id; aircraft are
|
||||
* identified by trackedEntity.
|
||||
*/
|
||||
this.subjectId = null;
|
||||
/**
|
||||
* The orbital view's zoom, look and saved field of view while a
|
||||
* satellite is ridden (src/ui/cockpitOrbitalView.js); null otherwise.
|
||||
*/
|
||||
this.orbital = null;
|
||||
this.trackedEntity = null;
|
||||
this.trackedEntityWasShown = true;
|
||||
this.heading = null;
|
||||
@@ -162,6 +198,11 @@ export class CockpitViewController {
|
||||
typeof isBridgeEntryAllowed === 'function'
|
||||
? isBridgeEntryAllowed
|
||||
: () => false;
|
||||
// Nor a satellite layer to ride without one.
|
||||
this.isOrbitEntryAllowed =
|
||||
typeof isOrbitEntryAllowed === 'function'
|
||||
? isOrbitEntryAllowed
|
||||
: () => false;
|
||||
this.isUtilityDisclosureOpen =
|
||||
typeof isUtilityDisclosureOpen === 'function'
|
||||
? isUtilityDisclosureOpen
|
||||
@@ -197,6 +238,7 @@ export class CockpitViewController {
|
||||
this.publishSignals = publish.signals ?? (() => {});
|
||||
this.publishUtilityLayout = publish.utilityLayout ?? (() => {});
|
||||
this.publishRadar = publish.radar ?? (() => {});
|
||||
this.publishOrbital = publish.orbital ?? (() => {});
|
||||
/** The bridge radar's range in nautical miles; kept across bridges. */
|
||||
this.radarRangeNm = DEFAULT_RADAR_RANGE_NM;
|
||||
this.presence = {
|
||||
@@ -262,6 +304,16 @@ export class CockpitViewController {
|
||||
true,
|
||||
);
|
||||
this._listenerRemovers.push(routeSceneDoubleClick.call(this));
|
||||
// In orbit a click on a mapped point keeps the camera on it.
|
||||
this._listenerRemovers.push(routeSceneClick.call(this));
|
||||
// In orbit the wheel steps the optical zoom (Cesium's own wheel zoom is
|
||||
// off while the Cockpit holds the camera).
|
||||
this._listen(
|
||||
viewer.scene?.canvas,
|
||||
'wheel',
|
||||
(event) => this.onOrbitalWheel(event),
|
||||
{ passive: false },
|
||||
);
|
||||
// The readout's entry renders inside the Intel HUD, which may mount after
|
||||
// this controller; delegated like the radar's range button.
|
||||
this._listen(document, 'click', (event) => {
|
||||
@@ -302,6 +354,17 @@ export class CockpitViewController {
|
||||
this._listen(document, 'click', (event) => {
|
||||
if (event.target?.closest?.('#cockpit-look-ahead')) this.lookAhead();
|
||||
});
|
||||
// The orbital HUD mounts only in orbit, so its controls are delegated.
|
||||
this._listen(document, 'click', (event) => {
|
||||
const target = event.target;
|
||||
if (target?.closest?.('#cockpit-orbital-zoom-in'))
|
||||
this.stepOrbitalZoom(1);
|
||||
else if (target?.closest?.('#cockpit-orbital-zoom-out'))
|
||||
this.stepOrbitalZoom(-1);
|
||||
else if (target?.closest?.('#cockpit-orbital-nadir')) this.orbitalNadir();
|
||||
else if (target?.closest?.('#cockpit-orbital-sensor'))
|
||||
this.jumpToSensorSwath();
|
||||
});
|
||||
this._listen(this.signalToggle, 'click', () =>
|
||||
this.setSignalCollapsed(!this.signalCollapsed, { user: true }),
|
||||
);
|
||||
@@ -346,6 +409,105 @@ export class CockpitViewController {
|
||||
readVesselInfo() {
|
||||
return readVesselInfo.call(this);
|
||||
}
|
||||
readSatelliteInfo() {
|
||||
return readSatelliteInfo.call(this);
|
||||
}
|
||||
beginOrbital() {
|
||||
return beginOrbital.call(this);
|
||||
}
|
||||
endOrbital() {
|
||||
return endOrbital.call(this);
|
||||
}
|
||||
updateOrbital(nowMs) {
|
||||
return updateOrbital.call(this, nowMs);
|
||||
}
|
||||
updateOrbitalHud(info, nowMs) {
|
||||
return updateOrbitalHud.call(this, info, nowMs);
|
||||
}
|
||||
/**
|
||||
* Step the orbital view's optical zoom (the + and − keys and buttons).
|
||||
* @param {number} direction Positive zooms in, negative out.
|
||||
* @returns {boolean} True when the zoom changed.
|
||||
*/
|
||||
stepOrbitalZoom(direction) {
|
||||
return stepOrbitalZoom.call(this, direction);
|
||||
}
|
||||
jumpToSensorSwath() {
|
||||
return jumpToSensorSwath.call(this);
|
||||
}
|
||||
onOrbitalWheel(event) {
|
||||
return onOrbitalWheel.call(this, event);
|
||||
}
|
||||
/**
|
||||
* A click on the orbital picture: on a mapped point in reach it keeps the
|
||||
* camera on that point; anywhere else it ends such a focus.
|
||||
* @param {{x: number, y: number}|null|undefined} position
|
||||
* @returns {boolean} True when the click focused a point.
|
||||
*/
|
||||
onOrbitalClick(position) {
|
||||
return onOrbitalClick.call(this, position);
|
||||
}
|
||||
/**
|
||||
* A double-click on the orbital picture: on a mapped ground point it keeps
|
||||
* or starts the focus there instead of letting Cesium track the point.
|
||||
* @param {{x: number, y: number}|null|undefined} position
|
||||
* @returns {boolean} True when it was taken.
|
||||
*/
|
||||
onOrbitalDoubleClick(position) {
|
||||
return onOrbitalDoubleClick.call(this, position);
|
||||
}
|
||||
/**
|
||||
* A site's orbital Live Signals row: focus that site, switch to it, or end
|
||||
* the focus held on it.
|
||||
* @param {string} key The site's id in the Mapped Installations layer.
|
||||
* @returns {boolean} True when the focus changed.
|
||||
*/
|
||||
toggleOrbitalFocus(key) {
|
||||
return toggleOrbitalFocus.call(this, key);
|
||||
}
|
||||
/** Rebuild the orbital Live Signals rows now. */
|
||||
refreshOrbitalSignals() {
|
||||
return refreshOrbitalSignals.call(this);
|
||||
}
|
||||
/** Rebuild the orbital Live Signals rows on their clock. */
|
||||
updateOrbitalSignals(nowMs) {
|
||||
return updateOrbitalSignals.call(this, nowMs);
|
||||
}
|
||||
/**
|
||||
* Ride the satellite an orbital Live Signals row names (RETURN goes back).
|
||||
* @param {number|string} noradId
|
||||
* @returns {boolean} True when the ridden satellite changed.
|
||||
*/
|
||||
rideOrbitalSatellite(noradId) {
|
||||
return rideOrbitalSatellite.call(this, noradId);
|
||||
}
|
||||
/**
|
||||
* A click on an orbital Live Signals row.
|
||||
* @returns {boolean} True in orbit.
|
||||
*/
|
||||
handleOrbitalSignalClick(layerId, id) {
|
||||
return handleOrbitalSignalClick.call(this, layerId, id);
|
||||
}
|
||||
/**
|
||||
* Tilt the orbital view one arrow step off nadir.
|
||||
* @param {{axis: 'yaw'|'pitch', sign: number, stepDeg: number}} step
|
||||
* @returns {boolean} True in an orbital view.
|
||||
*/
|
||||
turnOrbitalLook(step) {
|
||||
return turnOrbitalLook.call(this, step);
|
||||
}
|
||||
/**
|
||||
* The NADIR control and the Home and 0 keys in orbit: back to pure nadir.
|
||||
* Focus leaves the button before it hides.
|
||||
* @returns {boolean} True in an orbital view.
|
||||
*/
|
||||
orbitalNadir() {
|
||||
const button = document.getElementById('cockpit-orbital-nadir');
|
||||
const hadFocus = !!button && button.contains(document.activeElement);
|
||||
const reset = resetOrbitalLook.call(this);
|
||||
if (reset && hadFocus) this.mapViewButton?.focus({ preventScroll: true });
|
||||
return reset;
|
||||
}
|
||||
readSubjectLayerId() {
|
||||
return readSubjectLayerId.call(this);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
COCKPIT_AIRCRAFT_LAYER_IDS,
|
||||
bridgeEntryAllowed,
|
||||
cockpitEntryAllowed,
|
||||
orbitEntryAllowed,
|
||||
} from '../contextModePolicy.js';
|
||||
import { formatAwarenessLabel } from '../data/militaryAwarenessEngine.js';
|
||||
import { enterCockpitWithTracking } from '../cockpitTracking.js';
|
||||
@@ -42,6 +43,8 @@ export class CockpitCoordinator {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
aisLiveVesselsLayer,
|
||||
satellitesLayer,
|
||||
militaryInstallationsLayer,
|
||||
isTr3b,
|
||||
toggleTr3b,
|
||||
militaryAwarenessLayer,
|
||||
@@ -56,6 +59,7 @@ export class CockpitCoordinator {
|
||||
fetchRegionalBrief,
|
||||
regionalDistanceM,
|
||||
weatherCodeLabel,
|
||||
acquireOrbitImagery,
|
||||
} = services;
|
||||
this._cockpitDisplayPortal = null;
|
||||
this.cockpitView = new CockpitViewController(viewer, {
|
||||
@@ -63,6 +67,8 @@ export class CockpitCoordinator {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
aisLiveVesselsLayer,
|
||||
satellitesLayer,
|
||||
militaryInstallationsLayer,
|
||||
isTr3b,
|
||||
toggleTr3b,
|
||||
militaryAwarenessLayer,
|
||||
@@ -78,6 +84,7 @@ export class CockpitCoordinator {
|
||||
fetchRegionalBrief,
|
||||
regionalDistanceM,
|
||||
weatherCodeLabel,
|
||||
acquireOrbitImagery,
|
||||
// The Contact card and Live Signals say which feeds are off.
|
||||
isLayerEnabled: (layerId) => this._isLayerEnabled(layerId),
|
||||
},
|
||||
@@ -101,6 +108,14 @@ export class CockpitCoordinator {
|
||||
vesselsEnabled: !!this._dataManager?.isEnabled('ais-live-vessels'),
|
||||
contextModeChanging: this._contextModeChanging,
|
||||
}),
|
||||
isOrbitEntryAllowed: () =>
|
||||
orbitEntryAllowed({
|
||||
satellitesEnabled: !!this._dataManager?.isEnabled('satellites'),
|
||||
contextModeChanging: this._contextModeChanging,
|
||||
// The layer says whether its class may be ridden.
|
||||
subjectEnterable:
|
||||
satellitesLayer?.getCockpitSubject?.()?.enterable !== false,
|
||||
}),
|
||||
publish: this.publishCockpit,
|
||||
isUtilityDisclosureOpen: () => !!this.readUtilityDisclosureOpen?.(),
|
||||
onEntered: () => this.enterPanels(),
|
||||
@@ -176,6 +191,12 @@ export class CockpitCoordinator {
|
||||
// vessel selection before the entry can run, leaving neither.
|
||||
if (this.cockpitView?.active && this.cockpitView.subjectKind === 'vessel')
|
||||
return 'Cockpit is on a vessel bridge — exit the bridge first, then track an aircraft to enter Cockpit';
|
||||
// Likewise in orbit: the aircraft's tracking takes the satellite's.
|
||||
if (
|
||||
this.cockpitView?.active &&
|
||||
this.cockpitView.subjectKind === 'satellite'
|
||||
)
|
||||
return 'Cockpit is in an orbital view — exit it first, then track an aircraft to enter Cockpit';
|
||||
if (!this._aircraftLayerEnabled)
|
||||
return 'No aircraft layer is on — turn on Flights or Military Flights and track an aircraft to enter Cockpit';
|
||||
return null;
|
||||
@@ -190,6 +211,11 @@ export class CockpitCoordinator {
|
||||
active && this.cockpitView?.subjectKind === 'vessel'
|
||||
? this.cockpitView.readVesselInfo?.()
|
||||
: null;
|
||||
// Likewise an orbital view in use: its satellite, never an aircraft.
|
||||
const satellite =
|
||||
active && this.cockpitView?.subjectKind === 'satellite'
|
||||
? this.cockpitView.readSatelliteInfo?.()
|
||||
: null;
|
||||
const gateOpen = Boolean(this.cockpitView?.isEntryAllowed?.());
|
||||
// "Could Cockpit be ENTERED right now" — so it is false while already
|
||||
// inside, unconditionally. Cockpit takes the entity off
|
||||
@@ -218,22 +244,30 @@ export class CockpitCoordinator {
|
||||
? 'subject-layer-off'
|
||||
: 'no-tracked-aircraft',
|
||||
visionMode: this.cockpitView?.visionMode || null,
|
||||
subject: vessel
|
||||
subject: satellite
|
||||
? {
|
||||
kind: 'vessel',
|
||||
id: vessel.mmsi,
|
||||
layerId: vessel.layerId,
|
||||
kind: 'satellite',
|
||||
id: satellite.id,
|
||||
layerId: satellite.layerId,
|
||||
callsign: null,
|
||||
name: vessel.name,
|
||||
name: satellite.name,
|
||||
}
|
||||
: info
|
||||
: vessel
|
||||
? {
|
||||
kind: 'aircraft',
|
||||
id: info.icao24 || info.id || null,
|
||||
layerId: info.layerId || null,
|
||||
callsign: info.callsign || null,
|
||||
kind: 'vessel',
|
||||
id: vessel.mmsi,
|
||||
layerId: vessel.layerId,
|
||||
callsign: null,
|
||||
name: vessel.name,
|
||||
}
|
||||
: null,
|
||||
: info
|
||||
? {
|
||||
kind: 'aircraft',
|
||||
id: info.icao24 || info.id || null,
|
||||
layerId: info.layerId || null,
|
||||
callsign: info.callsign || null,
|
||||
}
|
||||
: null,
|
||||
navigation: snapshot
|
||||
? {
|
||||
canPrevious: Boolean(snapshot.navigation?.canPrevious),
|
||||
|
||||
@@ -25,6 +25,20 @@ const CIVIL = Object.freeze({
|
||||
latitude: 30,
|
||||
longitude: -97,
|
||||
});
|
||||
/** A tracked satellite, as the Satellites layer reports it. */
|
||||
const SATELLITE = Object.freeze({
|
||||
kind: 'satellite',
|
||||
layerId: 'satellites',
|
||||
id: '25544',
|
||||
noradId: 25544,
|
||||
name: 'ISS (ZARYA)',
|
||||
classLabel: 'STATION · ISS',
|
||||
latitude: 30,
|
||||
longitude: -97,
|
||||
altitudeM: 420_000,
|
||||
velocityMps: 7_660,
|
||||
stale: false,
|
||||
});
|
||||
const MILITARY = Object.freeze({
|
||||
...CIVIL,
|
||||
icao24: 'ae0001',
|
||||
@@ -36,6 +50,7 @@ function fixture(
|
||||
{
|
||||
enabled = [],
|
||||
tracked = null,
|
||||
satellite = null,
|
||||
contextMode = null,
|
||||
changing = false,
|
||||
dataManager: suppliedManager = null,
|
||||
@@ -87,6 +102,13 @@ function fixture(
|
||||
flightsLayer: { getTrackedInfo: trackedFrom('flights') },
|
||||
militaryFlightsLayer: { getTrackedInfo: trackedFrom('military') },
|
||||
aisLiveVesselsLayer: { getCockpitSubject: () => null },
|
||||
// Like the layer, no subject while Satellites is off.
|
||||
satellitesLayer: {
|
||||
getCockpitSubject: () =>
|
||||
satellite && layers.has('satellites') ? { ...satellite } : null,
|
||||
getCockpitPosition: () => null,
|
||||
setCockpitSubject: () => true,
|
||||
},
|
||||
militaryAwarenessLayer: { getContextSnapshot: () => null },
|
||||
isTr3b: () => false,
|
||||
holdContinuousRender() {},
|
||||
@@ -121,7 +143,11 @@ function fixture(
|
||||
t.after(() => {
|
||||
coordinator.stop();
|
||||
app.unmount();
|
||||
document.body.classList.remove('cockpit-mode', 'cockpit-bridge');
|
||||
document.body.classList.remove(
|
||||
'cockpit-mode',
|
||||
'cockpit-bridge',
|
||||
'cockpit-orbit',
|
||||
);
|
||||
});
|
||||
/** Turn a layer off and tell the Context owner, as the data manager does. */
|
||||
const disable = (layerId) => {
|
||||
@@ -220,6 +246,26 @@ test('voice entry on a vessel bridge refuses before it touches tracking', (t) =>
|
||||
assert.equal(cockpit.subjectKind, 'vessel');
|
||||
});
|
||||
|
||||
test('voice entry in an orbital view refuses before it touches tracking', (t) => {
|
||||
const { coordinator, cockpit } = fixture(t, { enabled: ['flights'] });
|
||||
let navigated = false;
|
||||
coordinator.services.militaryAwarenessLayer.navigateNext = () => {
|
||||
navigated = true;
|
||||
return true;
|
||||
};
|
||||
cockpit.active = true;
|
||||
cockpit.subjectKind = 'satellite';
|
||||
t.after(() => {
|
||||
cockpit.active = false;
|
||||
cockpit.subjectKind = null;
|
||||
});
|
||||
const voice = coordinator.controlCockpit('enter', { targetLayer: 'flights' });
|
||||
assert.equal(voice.ok, false);
|
||||
assert.match(voice.error, /orbital view/);
|
||||
assert.equal(navigated, false, 'no aircraft was tracked');
|
||||
assert.equal(cockpit.subjectKind, 'satellite');
|
||||
});
|
||||
|
||||
test('with an aircraft layer on but nothing tracked, the reason is the missing aircraft', (t) => {
|
||||
const { coordinator } = fixture(t, { enabled: ['military'] });
|
||||
assert.equal(
|
||||
@@ -520,3 +566,85 @@ test('the readout entry reads BRIDGE for a selected vessel', async (t) => {
|
||||
assert.match(readoutEntry.textContent, /directions_boat/);
|
||||
assert.match(readoutEntry.textContent, /BRIDGE/);
|
||||
});
|
||||
|
||||
test('a tracked satellite needs Satellites on for the ORBIT entry', async (t) => {
|
||||
const { $, cockpit } = fixture(t, { satellite: SATELLITE });
|
||||
cockpit.syncEntry();
|
||||
await nextTick();
|
||||
assert.equal($('#cockpit-entry').hidden, true, 'Satellites off: no entry');
|
||||
assert.equal(cockpit.enter(), false);
|
||||
});
|
||||
|
||||
test('with Satellites on, the tracked satellite offers ORBIT and reports itself', async (t) => {
|
||||
const { $, cockpit, coordinator, pinia } = fixture(t, {
|
||||
enabled: ['satellites'],
|
||||
satellite: SATELLITE,
|
||||
});
|
||||
useHudStore(pinia);
|
||||
cockpit.syncEntry();
|
||||
await nextTick();
|
||||
for (const selector of ['#cockpit-entry', '#cockpit-entry-readout']) {
|
||||
assert.equal($(selector).hidden, false, selector);
|
||||
assert.match($(selector).textContent, /satellite_alt/);
|
||||
assert.match($(selector).textContent, /ORBIT/);
|
||||
}
|
||||
// Voice stays aircraft-only: it neither offers nor takes the satellite.
|
||||
assert.equal(coordinator.getCockpitState().entryAllowed, false);
|
||||
assert.equal(coordinator.controlCockpit('enter').ok, false);
|
||||
assert.equal(cockpit.active, false);
|
||||
$('#cockpit-entry-readout').click();
|
||||
await nextTick();
|
||||
assert.equal(cockpit.active, true);
|
||||
assert.equal(cockpit.subjectKind, 'satellite');
|
||||
const state = coordinator.getCockpitState();
|
||||
assert.equal(state.active, true);
|
||||
assert.deepEqual(state.subject, {
|
||||
kind: 'satellite',
|
||||
id: '25544',
|
||||
layerId: 'satellites',
|
||||
callsign: null,
|
||||
name: 'ISS (ZARYA)',
|
||||
});
|
||||
});
|
||||
|
||||
test('tracked debris offers no ORBIT entry and refuses to be entered', async (t) => {
|
||||
const { $, cockpit } = fixture(t, {
|
||||
enabled: ['satellites'],
|
||||
satellite: {
|
||||
...SATELLITE,
|
||||
id: '27386',
|
||||
noradId: 27386,
|
||||
name: 'SL-16 R/B',
|
||||
satelliteClass: 'debris',
|
||||
enterable: false,
|
||||
},
|
||||
});
|
||||
cockpit.syncEntry();
|
||||
await nextTick();
|
||||
for (const selector of ['#cockpit-entry', '#cockpit-entry-readout'])
|
||||
assert.equal($(selector).hidden, true, selector);
|
||||
assert.equal(cockpit.enter(), false);
|
||||
assert.equal(cockpit.enter({ kind: 'satellite' }), false);
|
||||
assert.equal(cockpit.active, false);
|
||||
});
|
||||
|
||||
test('a Context change in flight blocks the orbital view too', (t) => {
|
||||
const { cockpit } = fixture(t, {
|
||||
enabled: ['satellites'],
|
||||
satellite: SATELLITE,
|
||||
changing: true,
|
||||
});
|
||||
assert.equal(cockpit.enter(), false);
|
||||
});
|
||||
|
||||
test('turning Satellites off ends the orbital view', (t) => {
|
||||
const { cockpit, disable } = fixture(t, {
|
||||
enabled: ['satellites', 'flights'],
|
||||
satellite: SATELLITE,
|
||||
});
|
||||
assert.equal(cockpit.enter(), true);
|
||||
disable('flights');
|
||||
assert.equal(cockpit.active, true, 'other feeds are free to go off');
|
||||
disable('satellites');
|
||||
assert.equal(cockpit.active, false);
|
||||
});
|
||||
+37
-32
@@ -39,6 +39,8 @@ function subjectWorldPosition(kind) {
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
if (kind === 'satellite')
|
||||
return this.services.satellitesLayer?.getCockpitPosition?.() ?? null;
|
||||
const info = this.readVesselInfo();
|
||||
if (!Number.isFinite(info?.latitude) || !Number.isFinite(info?.longitude))
|
||||
return null;
|
||||
@@ -87,7 +89,7 @@ export function onScenePointerDown(nowMs = performance.now()) {
|
||||
|
||||
/**
|
||||
* Enter first person when the followed track itself is double-clicked: the
|
||||
* same entry, and the same gates, as C and the entry buttons. The click may
|
||||
* same entry, and the same gates, as the entry buttons. The click may
|
||||
* land where the track is drawn now or where it was as the gesture began. A
|
||||
* double-click anywhere else, or one a tool owns (drawing ends a shape with
|
||||
* one), is left alone.
|
||||
@@ -121,7 +123,8 @@ export function onSceneDoubleClick(position, nowMs = performance.now()) {
|
||||
* installs its own (pickAndTrackObject), which untracks whenever the pick is
|
||||
* not an Entity: on a followed aircraft's model, a primitive, it would drop
|
||||
* the very track the double-click means to ride. A double-click on the
|
||||
* followed track is the Cockpit's; any other goes on to Cesium's.
|
||||
* followed track is the Cockpit's, as is one on a mapped ground point in
|
||||
* orbit (a focus); any other goes on to Cesium's.
|
||||
* @returns {() => void} Puts Cesium's handler back, unless another owner
|
||||
* (the draw tool borrows it) has replaced ours since.
|
||||
*/
|
||||
@@ -132,6 +135,9 @@ export function routeSceneDoubleClick() {
|
||||
const stock = handler.getInputAction?.(type) ?? null;
|
||||
const routed = (event) => {
|
||||
if (this.onSceneDoubleClick(event?.position)) return;
|
||||
// In orbit, a double-click on a mapped ground point is a focus, never a
|
||||
// retarget that would end the view.
|
||||
if (this.onOrbitalDoubleClick?.(event?.position)) return;
|
||||
stock?.(event);
|
||||
};
|
||||
handler.setInputAction(routed, type);
|
||||
@@ -194,9 +200,35 @@ function handleLookKey(event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Zoom keys in orbit: `+` (or `=`, unshifted) in and `-` (or `_`) out. */
|
||||
const ORBITAL_ZOOM_KEYS = Object.freeze({ '+': 1, '=': 1, '-': -1, _: -1 });
|
||||
|
||||
/**
|
||||
* The Cockpit's capture-phase keydown: Escape and C, and on a bridge the
|
||||
* look-around keys.
|
||||
* In an orbital view: tilt off nadir with the arrows (single 5° steps; Shift
|
||||
* does not take the bridge's 45° step), return to nadir with Home or 0, and
|
||||
* step the zoom with + and −. The bridge's focus guards apply.
|
||||
* @returns {boolean} True when the key was taken.
|
||||
*/
|
||||
function handleOrbitalKey(event) {
|
||||
if (!this.active || this.subjectKind !== 'satellite') return false;
|
||||
if (event.metaKey || event.ctrlKey || event.altKey) return false;
|
||||
const step = lookKeyStep(event.key);
|
||||
const reset = !event.repeat && (event.key === 'Home' || event.key === '0');
|
||||
const zoom = event.repeat ? 0 : ORBITAL_ZOOM_KEYS[event.key] || 0;
|
||||
if (!step && !reset && !zoom) return false;
|
||||
if (event.target?.closest?.(LOOK_KEY_OWNERS)) return false;
|
||||
if (this.isUtilityDisclosureOpen?.()) return false;
|
||||
event.preventDefault();
|
||||
if (step) this.turnOrbitalLook(step);
|
||||
else if (reset) this.orbitalNadir();
|
||||
else this.stepOrbitalZoom(zoom);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cockpit's capture-phase keydown: Escape, on a bridge the look-around
|
||||
* keys and in orbit the tilt and zoom keys. C is left to the app-wide CCTV
|
||||
* shortcut; entry is by double-click or the entry buttons.
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
export function onKeyDown(event) {
|
||||
@@ -247,32 +279,5 @@ export function onKeyDown(event) {
|
||||
if (event.target?.closest?.('input, textarea, select, [contenteditable]'))
|
||||
return;
|
||||
if (handleLookKey.call(this, event)) return;
|
||||
const key = event.key?.toLowerCase();
|
||||
if (key === 'c' && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
||||
if (!this.active) {
|
||||
const cockpitAttempt = !!(
|
||||
this.readAircraftInfo() && this.viewer.trackedEntity?.position
|
||||
);
|
||||
// With no tracked aircraft, C takes the selected vessel's bridge, but
|
||||
// only when the bridge can be entered: otherwise C stays the CCTV
|
||||
// shortcut, as it is with nothing selected.
|
||||
const bridgeAttempt =
|
||||
!cockpitAttempt &&
|
||||
!!this.readVesselInfo() &&
|
||||
this.isBridgeEntryAllowed();
|
||||
if (!cockpitAttempt && !bridgeAttempt) return;
|
||||
if (bridgeAttempt) {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
this.enter({ kind: 'vessel' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
if (!this.active && !this.isEntryAllowed()) return;
|
||||
if (this.active) this.exit();
|
||||
else this.enter({ kind: 'aircraft' });
|
||||
return;
|
||||
}
|
||||
handleOrbitalKey.call(this, event);
|
||||
}
|
||||
@@ -140,6 +140,11 @@ export function updateHud(
|
||||
updateVesselHud.call(this, info, nowMs, forceContext);
|
||||
return;
|
||||
}
|
||||
// The orbital view keeps its own HUD (CockpitOrbital).
|
||||
if (info?.kind === 'satellite') {
|
||||
this.updateOrbitalHud(info, nowMs);
|
||||
return;
|
||||
}
|
||||
this.lastSubjectInfo = info;
|
||||
const view = this.instruments;
|
||||
view.kind = 'aircraft';
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
// src/ui/cockpitOrbital.test.mjs — the orbital view HUD shows what the
|
||||
// Cockpit controller publishes to the store, over happy-dom.
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp, nextTick } from 'vue';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
import CockpitOrbital from './views/panels/CockpitOrbital.vue';
|
||||
import { ownerFlagStyle } from './ownerFlag.js';
|
||||
|
||||
/** Let a settled promise reach the view. */
|
||||
async function settle() {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await nextTick();
|
||||
}
|
||||
|
||||
const VIEW = Object.freeze({
|
||||
name: 'ISS (ZARYA)',
|
||||
classLabel: 'STATION · ISS',
|
||||
altitudeM: 418_400,
|
||||
velocityMps: 7_662,
|
||||
latitude: 12.3456,
|
||||
longitude: -45.6789,
|
||||
zoom: 4,
|
||||
zoomSteps: [1, 2, 4, 8],
|
||||
footprintKm: 61.4,
|
||||
transition: { active: false, blurPx: 0, lockTick: false },
|
||||
});
|
||||
|
||||
function fixture(t) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
const app = createApp(CockpitOrbital).use(pinia);
|
||||
app.mount(host);
|
||||
t.after(() => app.unmount());
|
||||
const store = useCockpitStore(pinia);
|
||||
const section = () => document.getElementById('cockpit-orbital');
|
||||
const text = (selector) =>
|
||||
section().querySelector(selector)?.textContent.trim() ?? null;
|
||||
return { store, section, text };
|
||||
}
|
||||
|
||||
test('the orbital HUD is hidden until a satellite view is published', async (t) => {
|
||||
const f = fixture(t);
|
||||
assert.equal(f.section().hidden, true);
|
||||
assert.equal(f.section().querySelector('#cockpit-orbital-zoom-in'), null);
|
||||
});
|
||||
|
||||
test('a published orbital view renders its readouts and zoom controls', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({ ...VIEW });
|
||||
await nextTick();
|
||||
assert.equal(f.section().hidden, false);
|
||||
assert.equal(f.text('.cockpit-orbital-kicker'), 'ORBITAL VIEW · NADIR');
|
||||
assert.equal(f.text('.cockpit-orbital-name'), 'ISS (ZARYA)');
|
||||
assert.equal(f.text('.cockpit-orbital-class'), 'STATION · ISS');
|
||||
assert.equal(f.text('.cockpit-orbital-altitude'), '418 KM');
|
||||
assert.equal(f.text('.cockpit-orbital-velocity'), '7.66 KM/S');
|
||||
assert.match(f.text('.cockpit-orbital-subpoint'), /12\.346°N.*45\.679°W/);
|
||||
assert.equal(f.text('.cockpit-orbital-north'), 'NORTH UP');
|
||||
assert.equal(f.text('.cockpit-orbital-zoom'), 'ZOOM 4×');
|
||||
assert.equal(f.text('.cockpit-orbital-swath'), 'SWATH 61 KM');
|
||||
|
||||
const zoomIn = document.getElementById('cockpit-orbital-zoom-in');
|
||||
const zoomOut = document.getElementById('cockpit-orbital-zoom-out');
|
||||
assert.equal(zoomIn.getAttribute('aria-label'), 'Zoom in');
|
||||
assert.equal(zoomOut.getAttribute('aria-label'), 'Zoom out');
|
||||
assert.equal(zoomIn.disabled, false);
|
||||
assert.equal(zoomOut.disabled, false);
|
||||
assert.ok(f.section().querySelector('.cockpit-orbital-reticle'));
|
||||
});
|
||||
|
||||
test('zoom buttons stop at the ends of the zoom steps', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({ ...VIEW, zoom: 8, footprintKm: 7.25 });
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
document.getElementById('cockpit-orbital-zoom-in').disabled,
|
||||
true,
|
||||
);
|
||||
assert.equal(f.text('.cockpit-orbital-swath'), 'SWATH 7.3 KM');
|
||||
f.store.publishOrbital({ ...VIEW, zoom: 1 });
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
document.getElementById('cockpit-orbital-zoom-out').disabled,
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
document.getElementById('cockpit-orbital-zoom-in').disabled,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('an unknown velocity leaves its row out', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({ ...VIEW, velocityMps: null });
|
||||
await nextTick();
|
||||
assert.equal(f.section().querySelector('.cockpit-orbital-velocity'), null);
|
||||
assert.equal(f.text('.cockpit-orbital-altitude'), '418 KM');
|
||||
});
|
||||
|
||||
test('a zoom step reflects its blur and lock tick', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
transition: { active: true, blurPx: 4.5, lockTick: false },
|
||||
});
|
||||
await nextTick();
|
||||
assert.ok(f.section().classList.contains('cockpit-orbital-focusing'));
|
||||
assert.equal(
|
||||
f.section().style.getPropertyValue('--cockpit-orbital-blur'),
|
||||
'4.50px',
|
||||
);
|
||||
const reticle = f.section().querySelector('.cockpit-orbital-reticle');
|
||||
assert.equal(
|
||||
reticle.classList.contains('cockpit-orbital-reticle-lock'),
|
||||
false,
|
||||
);
|
||||
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
transition: { active: false, blurPx: 0, lockTick: true },
|
||||
});
|
||||
await nextTick();
|
||||
assert.ok(!f.section().classList.contains('cockpit-orbital-focusing'));
|
||||
assert.equal(
|
||||
f.section().style.getPropertyValue('--cockpit-orbital-blur'),
|
||||
'0px',
|
||||
);
|
||||
assert.ok(
|
||||
f
|
||||
.section()
|
||||
.querySelector('.cockpit-orbital-reticle')
|
||||
.classList.contains('cockpit-orbital-reticle-lock'),
|
||||
);
|
||||
});
|
||||
|
||||
test('publishing null hides the orbital HUD again', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({ ...VIEW });
|
||||
await nextTick();
|
||||
assert.equal(f.section().hidden, false);
|
||||
f.store.publishOrbital(null);
|
||||
await nextTick();
|
||||
assert.equal(f.section().hidden, true);
|
||||
assert.equal(f.section().querySelector('.cockpit-orbital-name'), null);
|
||||
});
|
||||
|
||||
const ISS_TLE = Object.freeze({
|
||||
line1:
|
||||
'1 25544U 98067A 26308.34166667 .00016717 00000-0 30306-3 0 9993',
|
||||
line2:
|
||||
'2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.50377579477310',
|
||||
epochMs: Date.UTC(2026, 10, 4, 8, 12, 0),
|
||||
});
|
||||
|
||||
test('the place below shows at the top once known', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({ ...VIEW, place: undefined });
|
||||
await nextTick();
|
||||
assert.equal(f.section().querySelector('#cockpit-orbital-over'), null);
|
||||
const over = () =>
|
||||
f.section().querySelector('#cockpit-orbital-over strong')?.textContent;
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
place: { kind: 'country', name: 'France', countryCode: 'FR' },
|
||||
});
|
||||
await nextTick();
|
||||
assert.match(f.text('#cockpit-orbital-over'), /^CURRENTLY OVER/);
|
||||
assert.equal(over(), 'France');
|
||||
// The division as Natural Earth names it, the country localized.
|
||||
const sichuan = {
|
||||
kind: 'country',
|
||||
name: 'China',
|
||||
countryCode: 'CN',
|
||||
division: 'Sichuan',
|
||||
near: null,
|
||||
};
|
||||
f.store.publishOrbital({ ...VIEW, place: sichuan });
|
||||
await nextTick();
|
||||
assert.equal(over(), 'Sichuan, China');
|
||||
// From 8x, the populated place in view.
|
||||
f.store.publishOrbital({ ...VIEW, place: { ...sichuan, near: 'Chengdu' } });
|
||||
await nextTick();
|
||||
assert.equal(over(), 'Sichuan, China · near Chengdu');
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
place: { kind: 'sea', name: 'Caspian Sea', countryCode: null },
|
||||
});
|
||||
await nextTick();
|
||||
assert.equal(over(), 'Caspian Sea');
|
||||
// No feature holds the point (a gap at a simplified coastline): the band
|
||||
// says nothing rather than call land open ocean.
|
||||
f.store.publishOrbital({ ...VIEW, place: null });
|
||||
await nextTick();
|
||||
assert.equal(document.querySelector('#cockpit-orbital-over'), null);
|
||||
});
|
||||
|
||||
test('an owner country shows its flag from the sheet, or its code if the sheet will not load', async (t) => {
|
||||
// The sheet loads through an Image; this one answers when told.
|
||||
const images = [];
|
||||
const RealImage = globalThis.Image;
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
images.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = RealImage;
|
||||
});
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
owner: { countryCode: 'US', label: 'USA' },
|
||||
});
|
||||
await nextTick();
|
||||
assert.equal(f.section().querySelector('.cockpit-orbital-flag'), null);
|
||||
assert.equal(images.length, 1, 'the sheet is asked for');
|
||||
images[0].onerror();
|
||||
await settle();
|
||||
// No sheet: the code, so the owner never disappears.
|
||||
assert.equal(f.text('.cockpit-orbital-owner-badge'), 'US');
|
||||
// Another satellite of the same country asks again.
|
||||
f.store.publishOrbital({ ...f.store.orbital, noradId: 43013 });
|
||||
await nextTick();
|
||||
assert.equal(images.length, 2, 'a new ride asks again');
|
||||
images[1].onerror();
|
||||
await settle();
|
||||
// The next flag asks again; this time the sheet comes.
|
||||
f.store.publishOrbital({
|
||||
...f.store.orbital,
|
||||
owner: { countryCode: 'FR', label: 'France' },
|
||||
});
|
||||
await nextTick();
|
||||
assert.equal(images.length, 3);
|
||||
images[2].onload();
|
||||
await settle();
|
||||
const flag = f.section().querySelector('.cockpit-orbital-flag');
|
||||
assert.equal(flag.getAttribute('role'), 'img');
|
||||
assert.equal(flag.getAttribute('aria-label'), 'France');
|
||||
assert.equal(
|
||||
flag.style.backgroundPosition,
|
||||
ownerFlagStyle('FR').backgroundPosition,
|
||||
);
|
||||
assert.equal(f.section().querySelector('.cockpit-orbital-owner-badge'), null);
|
||||
});
|
||||
|
||||
test('the readout names the owner, operator and element set', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
noradId: 25544,
|
||||
cosparId: '1998-067A',
|
||||
tle: ISS_TLE,
|
||||
// A country with no flag on the sheet shows as a badge, named in the
|
||||
// reader's language.
|
||||
owner: { countryCode: 'IS', label: 'Ísland' },
|
||||
operator: 'NASA',
|
||||
});
|
||||
await nextTick();
|
||||
assert.equal(f.text('.cockpit-orbital-name'), 'ISS (ZARYA)');
|
||||
assert.equal(f.text('.cockpit-orbital-owner-badge'), 'Ísland');
|
||||
assert.equal(
|
||||
f.section().querySelector('.cockpit-orbital-owner-badge').title,
|
||||
'Iceland',
|
||||
);
|
||||
assert.equal(f.text('.cockpit-orbital-operator'), 'NASA');
|
||||
assert.equal(
|
||||
f.text('.cockpit-orbital-ident-text'),
|
||||
'NORAD 25544 · 1998-067A · EPOCH 2026-11-04 08:12Z',
|
||||
);
|
||||
// The element set's age, as the controller reads it on each publish.
|
||||
f.store.publishOrbital({
|
||||
...f.store.orbital,
|
||||
tleAgeMs: 13.5 * 3_600_000,
|
||||
});
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
f.text('.cockpit-orbital-ident-text'),
|
||||
'NORAD 25544 · 1998-067A · EPOCH 2026-11-04 08:12Z · 13 H OLD',
|
||||
);
|
||||
f.store.publishOrbital({ ...f.store.orbital, tleAgeMs: 50 * 3_600_000 });
|
||||
await nextTick();
|
||||
assert.match(f.text('.cockpit-orbital-ident-text'), / · 2 D OLD$/);
|
||||
f.store.publishOrbital({ ...f.store.orbital, tleAgeMs: 10 * 60_000 });
|
||||
await nextTick();
|
||||
assert.match(f.text('.cockpit-orbital-ident-text'), / · <1 H OLD$/);
|
||||
f.store.publishOrbital({ ...f.store.orbital, tleAgeMs: null });
|
||||
await nextTick();
|
||||
const toggle = document.getElementById('cockpit-orbital-tle-toggle');
|
||||
const tle = document.getElementById('cockpit-orbital-tle');
|
||||
assert.equal(toggle.getAttribute('aria-expanded'), 'false');
|
||||
assert.equal(tle.style.display, 'none', 'folded');
|
||||
toggle.click();
|
||||
await nextTick();
|
||||
assert.equal(toggle.getAttribute('aria-expanded'), 'true');
|
||||
assert.notEqual(tle.style.display, 'none');
|
||||
assert.equal(tle.textContent, `${ISS_TLE.line1}\n${ISS_TLE.line2}`);
|
||||
// Another satellite starts folded.
|
||||
f.store.publishOrbital({ ...VIEW, noradId: 48274, tle: ISS_TLE });
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
document
|
||||
.getElementById('cockpit-orbital-tle-toggle')
|
||||
.getAttribute('aria-expanded'),
|
||||
'false',
|
||||
);
|
||||
});
|
||||
|
||||
test('unknown identity fields leave their rows out', async (t) => {
|
||||
const f = fixture(t);
|
||||
f.store.publishOrbital({
|
||||
...VIEW,
|
||||
noradId: null,
|
||||
cosparId: null,
|
||||
tle: null,
|
||||
owner: null,
|
||||
operator: null,
|
||||
});
|
||||
await nextTick();
|
||||
for (const selector of [
|
||||
'.cockpit-orbital-flag',
|
||||
'.cockpit-orbital-owner-badge',
|
||||
'.cockpit-orbital-operator',
|
||||
'.cockpit-orbital-ident',
|
||||
'#cockpit-orbital-tle',
|
||||
])
|
||||
assert.equal(f.section().querySelector(selector), null, selector);
|
||||
// An element set with no NORAD id still dates itself.
|
||||
f.store.publishOrbital({ ...VIEW, tle: ISS_TLE });
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
f.text('.cockpit-orbital-ident-text'),
|
||||
'EPOCH 2026-11-04 08:12Z',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,463 @@
|
||||
/**
|
||||
* Ground focus in the Cockpit's orbital view: a site's Live Signals row, or
|
||||
* a click on a mapped site's marker, keeps the camera on that site as the
|
||||
* satellite moves; clicking elsewhere, the site's row again, NADIR or the
|
||||
* site leaving the off-nadir reach eases the view back. Sites come
|
||||
* from the Mapped Installations layer's own records and pick ids. Bound to
|
||||
* the Cockpit controller like the orbital view itself
|
||||
* (src/ui/cockpitOrbitalView.js); its state lives on the orbital session, so
|
||||
* it ends with the session.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { clampOrbitalLook, easeLook } from '../cockpitLook.js';
|
||||
import { ORBITAL_EARTH_RADIUS_M } from '../cockpitOrbital.js';
|
||||
import {
|
||||
easeFocusRemainder,
|
||||
focusEaseDtMs,
|
||||
focusInReach,
|
||||
focusLook,
|
||||
pointsInReach,
|
||||
} from '../cockpitOrbitalFocus.js';
|
||||
import { isPointerFree } from '../data/inputOwnership.js';
|
||||
|
||||
const NADIR_LOOK = Object.freeze({ yawDeg: 0, pitchDeg: 0 });
|
||||
|
||||
/** The Mapped Installations layer's id. */
|
||||
const SITES_LAYER_ID = 'military-installations';
|
||||
|
||||
/** The most sites asked of the layer around the sub-satellite point. */
|
||||
const SITE_QUERY_MAX = 500;
|
||||
|
||||
/** How long a site the layer dropped stays listed, ms (it may come back). */
|
||||
const SITE_MEMORY_MS = 10_000;
|
||||
|
||||
/** The farthest from the sub-satellite point a listed site may lie, m. */
|
||||
const SITE_QUERY_MAX_RANGE_M = 3_000_000;
|
||||
|
||||
/** The greatest angle off nadir the reach allows: 45° on both axes. */
|
||||
const REACH_CORNER_RAD = Math.acos(Math.cos(Math.PI / 4) ** 2);
|
||||
|
||||
/**
|
||||
* How far over the ground the reach extends from the sub-satellite point,
|
||||
* m: the central angle at the reach's corner off nadir (or the horizon, if
|
||||
* nearer), with a little margin, capped. Sites farther out are never asked
|
||||
* of the layer.
|
||||
*/
|
||||
function reachGroundRangeM(altitudeM) {
|
||||
const R = ORBITAL_EARTH_RADIUS_M;
|
||||
const h = Math.max(0, Number.isFinite(altitudeM) ? altitudeM : 0);
|
||||
const sine = ((R + h) / R) * Math.sin(REACH_CORNER_RAD);
|
||||
const central =
|
||||
sine >= 1 ? Math.acos(R / (R + h)) : Math.asin(sine) - REACH_CORNER_RAD;
|
||||
return Math.min(SITE_QUERY_MAX_RANGE_M, R * central * 1.05);
|
||||
}
|
||||
|
||||
/** Whether the user asked for reduced motion: focus turns then cut. */
|
||||
function prefersReducedMotion() {
|
||||
return Boolean(
|
||||
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches,
|
||||
);
|
||||
}
|
||||
|
||||
function inOrbit(controller) {
|
||||
return (
|
||||
controller.active &&
|
||||
!controller.destroyed &&
|
||||
controller.subjectKind === 'satellite' &&
|
||||
Boolean(controller.orbital)
|
||||
);
|
||||
}
|
||||
|
||||
function sitesLayer(controller) {
|
||||
return controller.services?.militaryInstallationsLayer ?? null;
|
||||
}
|
||||
|
||||
/** Whether the Mapped Installations layer is on (unknown reads as off). */
|
||||
function sitesLayerOn(controller) {
|
||||
const isLayerEnabled = controller.services?.isLayerEnabled;
|
||||
return typeof isLayerEnabled === 'function'
|
||||
? isLayerEnabled(SITES_LAYER_ID) !== false
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A mapped site by id: as the layer has it loaded now, else, while the
|
||||
* layer is on, as the focus or the Live Signals rows last saw it. The layer
|
||||
* reloads its thinned view as the camera moves, so a site in view can leave
|
||||
* its records for a moment; a site does not move, so its last position
|
||||
* stands. Null with the layer off or the site never seen.
|
||||
*/
|
||||
function siteById(controller, id) {
|
||||
let live = null;
|
||||
try {
|
||||
live = sitesLayer(controller)?.getById?.(id) ?? null;
|
||||
} catch {
|
||||
live = null;
|
||||
}
|
||||
if (live) return live;
|
||||
if (!sitesLayerOn(controller)) return null;
|
||||
const state = controller.orbital;
|
||||
const key = String(id);
|
||||
if (state?.focus?.key === key && state.focus.site) return state.focus.site;
|
||||
return state?.listedSites?.get(key)?.site ?? null;
|
||||
}
|
||||
|
||||
/** Where a site is drawn, ECEF, or null. */
|
||||
function sitePosition(site) {
|
||||
const p = site?.position;
|
||||
return p &&
|
||||
Number.isFinite(p.x) &&
|
||||
Number.isFinite(p.y) &&
|
||||
Number.isFinite(p.z)
|
||||
? { x: p.x, y: p.y, z: p.z }
|
||||
: null;
|
||||
}
|
||||
|
||||
/** The mapped site a canvas position shows, through the layer's pick ids. */
|
||||
function siteAt(controller, position) {
|
||||
let picked = null;
|
||||
try {
|
||||
picked = controller.viewer.scene?.pick?.(position) ?? null;
|
||||
} catch {
|
||||
picked = null;
|
||||
}
|
||||
if (!picked) return null;
|
||||
try {
|
||||
return sitesLayer(controller)?.findByPick?.(picked) ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** The focus look at a site from the last frame's satellite, or null. */
|
||||
function lookAt(state, site) {
|
||||
const frame = state.focusFrame;
|
||||
if (!frame) return null;
|
||||
return focusLook(frame.nadir, frame.position, sitePosition(site));
|
||||
}
|
||||
|
||||
/**
|
||||
* Point the view at a mapped site and keep it there: from the view as it is
|
||||
* now, so switching targets turns rather than jumps. A site beyond the
|
||||
* reach is refused.
|
||||
* @returns {boolean} True when the focus is on that site.
|
||||
*/
|
||||
function startFocus(site) {
|
||||
const state = this.orbital;
|
||||
const look = lookAt(state, site);
|
||||
// Before the first frame there is nothing to measure against; the frame
|
||||
// that follows checks the reach.
|
||||
if (state.focusFrame && !focusInReach(look)) return false;
|
||||
state.focus = {
|
||||
key: String(site.id),
|
||||
label: String(site.name || site.id),
|
||||
// Where the site is, kept while the layer reloads around it.
|
||||
site: {
|
||||
id: site.id,
|
||||
name: site.name,
|
||||
class: site.class,
|
||||
position: sitePosition(site),
|
||||
},
|
||||
look,
|
||||
// The view minus the target's look, eased away; set on the next frame.
|
||||
remainder: null,
|
||||
};
|
||||
state.focusReleasing = false;
|
||||
if (look) state.lookTarget = clampOrbitalLook(look);
|
||||
this.refreshOrbitalSignals?.();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* End the focus. The view eases back to nadir on the focus's clock (cut
|
||||
* under reduced motion), or with `handOver` stays where it is for an arrow
|
||||
* key to tilt on from.
|
||||
* @param {{handOver?: boolean}} [options]
|
||||
* @returns {boolean} True when a focus was ended.
|
||||
*/
|
||||
export function releaseOrbitalFocus({ handOver = false } = {}) {
|
||||
const state = this.orbital;
|
||||
if (!state?.focus) {
|
||||
// An arrow during the ease back takes the arrows' own clock again and
|
||||
// tilts on from where the view is, not from the nadir it was easing to.
|
||||
if (handOver && state?.focusReleasing) {
|
||||
state.lookTarget = clampOrbitalLook(state.lookView);
|
||||
state.focusReleasing = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
state.focus = null;
|
||||
if (handOver) {
|
||||
state.lookTarget = clampOrbitalLook(state.lookView);
|
||||
state.focusReleasing = false;
|
||||
} else {
|
||||
state.lookTarget = { ...NADIR_LOOK };
|
||||
if (prefersReducedMotion()) {
|
||||
state.lookView = { ...NADIR_LOOK };
|
||||
state.focusReleasing = false;
|
||||
} else state.focusReleasing = true;
|
||||
}
|
||||
this.refreshOrbitalSignals?.();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A site's Live Signals row: focus that site, switch to it from another, or
|
||||
* end the focus when it is the one held.
|
||||
* @param {string} key The site's id in the Mapped Installations layer.
|
||||
* @returns {boolean} True when the focus changed.
|
||||
*/
|
||||
export function toggleOrbitalFocus(key) {
|
||||
if (!inOrbit(this) || key === null || key === undefined) return false;
|
||||
const state = this.orbital;
|
||||
if (state.focus?.key === String(key)) return releaseOrbitalFocus.call(this);
|
||||
const site = siteById(this, String(key));
|
||||
return site ? startFocus.call(this, site) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A double-click on the orbital picture. On a mapped ground point it keeps
|
||||
* or starts the focus on it (as a single click does) and is taken: Cesium's
|
||||
* own double-click would track that point, which ends the view. Any other
|
||||
* double-click, one a tool owns, and every one outside orbit go on.
|
||||
* @param {{x: number, y: number}|null|undefined} position Canvas position.
|
||||
* @returns {boolean} True when it landed on a ground point and was taken.
|
||||
*/
|
||||
export function onOrbitalDoubleClick(position) {
|
||||
if (!inOrbit(this) || !isPointerFree()) return false;
|
||||
if (!Number.isFinite(position?.x) || !Number.isFinite(position?.y))
|
||||
return false;
|
||||
const site = siteAt(this, position);
|
||||
if (!site) return false;
|
||||
// A site beyond the reach is not focused, but still never tracked.
|
||||
if (this.orbital.focus?.key !== String(site.id)) startFocus.call(this, site);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A click on the orbital picture. One on a mapped ground point in reach
|
||||
* focuses it; any other click ends a focus. A click a tool owns (drawing)
|
||||
* is left alone, as is every click outside orbit.
|
||||
* @param {{x: number, y: number}|null|undefined} position Canvas position.
|
||||
* @returns {boolean} True when the click focused a point.
|
||||
*/
|
||||
export function onOrbitalClick(position) {
|
||||
if (!inOrbit(this) || !isPointerFree()) return false;
|
||||
if (!Number.isFinite(position?.x) || !Number.isFinite(position?.y))
|
||||
return false;
|
||||
const site = siteAt(this, position);
|
||||
const state = this.orbital;
|
||||
if (site) {
|
||||
if (state.focus?.key === String(site.id)) return true;
|
||||
if (startFocus.call(this, site)) return true;
|
||||
// A mapped site beyond the reach is a click elsewhere: the focus ends.
|
||||
}
|
||||
releaseOrbitalFocus.call(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the scene's single click through the orbital focus first, then hand
|
||||
* it on to Cesium's own (it picks into `selectedEntity`), as before.
|
||||
* @returns {() => void} Puts Cesium's handler back, unless another owner
|
||||
* (the draw tool borrows it) has replaced ours since.
|
||||
*/
|
||||
export function routeSceneClick() {
|
||||
const handler = this.viewer.screenSpaceEventHandler;
|
||||
if (typeof handler?.setInputAction !== 'function') return () => {};
|
||||
const type = Cesium.ScreenSpaceEventType.LEFT_CLICK;
|
||||
const stock = handler.getInputAction?.(type) ?? null;
|
||||
const routed = (event) => {
|
||||
this.onOrbitalClick(event?.position);
|
||||
stock?.(event);
|
||||
};
|
||||
handler.setInputAction(routed, type);
|
||||
return () => {
|
||||
if (handler.isDestroyed?.() || handler.getInputAction?.(type) !== routed)
|
||||
return;
|
||||
if (stock) handler.setInputAction(stock, type);
|
||||
else handler.removeInputAction(type);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The orbital view's look for one frame, while a focus holds or is ending.
|
||||
* A held focus aims at its target: the live look plus whatever is left of
|
||||
* the turn onto it. The focus ends, easing back, when its layer is turned
|
||||
* off or its site is beyond the reach (a site the layer stops loading is
|
||||
* held from its last record). Also rebuilds
|
||||
* the orbital Live Signals rows on their own clock.
|
||||
* @param {object} state The orbital session.
|
||||
* @param {{direction: object, up: object, right: object}} nadir This
|
||||
* frame's nadir frame.
|
||||
* @param {{x: number, y: number, z: number}} position The satellite, ECEF.
|
||||
* @param {number} nowMs
|
||||
* @returns {boolean} True when it placed `state.lookView` itself.
|
||||
*/
|
||||
export function updateOrbitalFocus(state, nadir, position, nowMs) {
|
||||
state.focusFrame = {
|
||||
nadir,
|
||||
position: { x: position.x, y: position.y, z: position.z },
|
||||
};
|
||||
// After a satellite switch the first frame on the new satellite (the hop
|
||||
// landed, or none) is the one the rows can be measured from: rebuild now.
|
||||
if (state.awaitingFrame && !state.hop) {
|
||||
state.awaitingFrame = false;
|
||||
state.signalsMs = -Infinity;
|
||||
}
|
||||
const dtMs = nowMs - (state.lookLastMs || nowMs);
|
||||
let aimed = false;
|
||||
const focus = state.focus;
|
||||
if (focus) {
|
||||
const site = siteById(this, focus.key);
|
||||
const look = site
|
||||
? focusLook(nadir, state.focusFrame.position, sitePosition(site))
|
||||
: null;
|
||||
if (!focusInReach(look)) {
|
||||
releaseOrbitalFocus.call(this);
|
||||
} else {
|
||||
focus.look = look;
|
||||
const reduced = prefersReducedMotion();
|
||||
focus.remainder = focus.remainder
|
||||
? easeFocusRemainder(focus.remainder, dtMs, { immediate: reduced })
|
||||
: reduced
|
||||
? { ...NADIR_LOOK }
|
||||
: {
|
||||
yawDeg: state.lookView.yawDeg - look.yawDeg,
|
||||
pitchDeg: state.lookView.pitchDeg - look.pitchDeg,
|
||||
};
|
||||
state.lookTarget = clampOrbitalLook(look);
|
||||
state.lookView = {
|
||||
yawDeg: look.yawDeg + focus.remainder.yawDeg,
|
||||
pitchDeg: look.pitchDeg + focus.remainder.pitchDeg,
|
||||
};
|
||||
aimed = true;
|
||||
}
|
||||
}
|
||||
this.updateOrbitalSignals?.(nowMs);
|
||||
return aimed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ease the orbital look toward its target for one frame: the look's own
|
||||
* easing, on the focus's slower clock while a focus is easing back.
|
||||
* @param {object} state The orbital session.
|
||||
* @param {number} dtMs
|
||||
* @param {{immediate?: boolean}} [options]
|
||||
* @returns {{yawDeg: number, pitchDeg: number}}
|
||||
*/
|
||||
export function easeOrbitalLook(state, dtMs, { immediate = false } = {}) {
|
||||
const view = easeLook(
|
||||
state.lookView,
|
||||
state.lookTarget,
|
||||
state.focusReleasing ? focusEaseDtMs(dtMs) : dtMs,
|
||||
{ immediate },
|
||||
);
|
||||
if (
|
||||
state.focusReleasing &&
|
||||
view.yawDeg === state.lookTarget.yawDeg &&
|
||||
view.pitchDeg === state.lookTarget.pitchDeg
|
||||
)
|
||||
state.focusReleasing = false;
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* The focused target for the HUD: its name and the live look at it, whose
|
||||
* single off-nadir angle the readout shows. Null without a focus, or before
|
||||
* its first frame.
|
||||
* @returns {{key: string, label: string, offNadirDeg: number,
|
||||
* yawDeg: number, pitchDeg: number}|null}
|
||||
*/
|
||||
export function orbitalFocusReadout() {
|
||||
const focus = this.orbital?.focus;
|
||||
if (!focus?.look) return null;
|
||||
return {
|
||||
key: focus.key,
|
||||
label: focus.label,
|
||||
offNadirDeg: focus.look.offNadirDeg,
|
||||
yawDeg: focus.look.yawDeg,
|
||||
pitchDeg: focus.look.pitchDeg,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The mapped sites the orbital view can be turned to, for the Live Signals
|
||||
* rows: the Mapped Installations layer's loaded sites around the
|
||||
* sub-satellite point (`getNearby`), with those seen in the last
|
||||
* SITE_MEMORY_MS and the focused one, facing the satellite and within the
|
||||
* off-nadir reach, nearest to nadir first. Empty before the first frame or
|
||||
* with the layer off.
|
||||
* @param {{latitude: number, longitude: number, altitudeM: number}} info
|
||||
* The ridden satellite.
|
||||
* @returns {{entries: Array<{site: object, offNadirDeg: number,
|
||||
* focused: boolean}>}}
|
||||
*/
|
||||
export function orbitalSitesInReach(info) {
|
||||
const state = this.orbital;
|
||||
const frame = state?.focusFrame;
|
||||
const layer = sitesLayer(this);
|
||||
// The layer keeps its records when it is turned off: nothing is listed
|
||||
// then, and no row is left to focus from.
|
||||
if (state && !sitesLayerOn(this)) state.listedSites = new Map();
|
||||
if (!frame || typeof layer?.getNearby !== 'function' || !sitesLayerOn(this))
|
||||
return { entries: [] };
|
||||
if (!Number.isFinite(info?.latitude) || !Number.isFinite(info?.longitude))
|
||||
return { entries: [] };
|
||||
const rangeM = reachGroundRangeM(info.altitudeM);
|
||||
let sites = [];
|
||||
try {
|
||||
sites = layer.getNearby(
|
||||
Cesium.Cartesian3.fromDegrees(info.longitude, info.latitude, 0),
|
||||
rangeM,
|
||||
SITE_QUERY_MAX,
|
||||
);
|
||||
} catch {
|
||||
sites = [];
|
||||
}
|
||||
const byId = new Map();
|
||||
const candidates = [];
|
||||
for (const site of sites || []) {
|
||||
const position = sitePosition(site);
|
||||
if (!position || site.id === null || site.id === undefined) continue;
|
||||
const key = String(site.id);
|
||||
byId.set(key, site);
|
||||
candidates.push({ key, position });
|
||||
}
|
||||
// In orbit the layer reloads its thinned view every second or so, and a
|
||||
// site in view can drop out of its records and come back. Sites do not
|
||||
// move: one seen within SITE_MEMORY_MS stays a candidate, so the rows hold
|
||||
// still and a row's site can be focused from what the rows show.
|
||||
const nowMs = performance.now();
|
||||
const remembered = new Map();
|
||||
for (const [key, entry] of state.listedSites ?? []) {
|
||||
if (nowMs - entry.seenMs > SITE_MEMORY_MS || byId.has(key)) continue;
|
||||
remembered.set(key, entry);
|
||||
byId.set(key, entry.site);
|
||||
candidates.push({ key, position: entry.site.position });
|
||||
}
|
||||
// The focused site stays a candidate while the layer reloads around it.
|
||||
const held = state.focus;
|
||||
if (held?.site?.position && !byId.has(held.key)) {
|
||||
byId.set(held.key, held.site);
|
||||
candidates.push({ key: held.key, position: held.site.position });
|
||||
}
|
||||
for (const [key, site] of byId)
|
||||
if (!remembered.has(key))
|
||||
remembered.set(key, {
|
||||
site: { ...site, position: sitePosition(site) },
|
||||
seenMs: nowMs,
|
||||
});
|
||||
state.listedSites = remembered;
|
||||
const focusKey = state.focus?.key ?? null;
|
||||
return {
|
||||
entries: pointsInReach(candidates, {
|
||||
nadir: frame.nadir,
|
||||
satellite: frame.position,
|
||||
}).map(({ key, offNadirDeg }) => ({
|
||||
site: byId.get(key),
|
||||
offNadirDeg,
|
||||
focused: key === focusKey,
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,963 @@
|
||||
// src/ui/cockpitOrbitalFocus.test.mjs — the orbital view's Live Signals
|
||||
// rows and its ground focus: the rows list the Mapped Installations layer's
|
||||
// sites around the satellite (getNearby) and the nearest satellites; a site
|
||||
// row, or a click on the site's marker (the layer's pick ids), turns the
|
||||
// camera onto it and holds it as the satellite moves; a click elsewhere, the
|
||||
// row again, NADIR or the site leaving the reach eases the view back, never
|
||||
// in one jump; a satellite row rides that satellite and stays in orbit.
|
||||
// The layers are stubs with the real methods' shapes. Over happy-dom.
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp, defineComponent, h, nextTick } from 'vue';
|
||||
import * as Cesium from 'cesium';
|
||||
import { CockpitViewController } from './cockpitController.js';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
import { useHudStore } from './stores/hud.js';
|
||||
import CockpitView from './views/CockpitView.vue';
|
||||
import ContextView from './views/ContextView.vue';
|
||||
import IntelHudView from './views/IntelHudView.vue';
|
||||
import { claimPointer, releasePointer } from '../data/inputOwnership.js';
|
||||
import { ORBITAL_FOCUS_EASE_TAU_MS } from '../cockpitOrbitalFocus.js';
|
||||
import { ORBITAL_HOP_MS } from '../cockpitOrbitalSatellites.js';
|
||||
|
||||
const START_MS = 1_800_000_000_000;
|
||||
const ASPECT = 16 / 9;
|
||||
const FRAME_MS = 16;
|
||||
|
||||
/** Satellites the layer knows, by NORAD id: the ridden one and its neighbours. */
|
||||
const SATELLITES = Object.freeze({
|
||||
25544: { name: 'ISS (ZARYA)', lat: 30, lon: -97, alt: 420_000, cls: 'stations' },
|
||||
49260: { name: 'LANDSAT 9', lat: 31.5, lon: -95, alt: 705_000, cls: 'imaging' },
|
||||
40697: { name: 'SENTINEL-2A', lat: 26, lon: -99, alt: 786_000, cls: 'imaging' },
|
||||
99001: { name: 'DEB FRAGMENT', lat: 30.2, lon: -97.1, alt: 430_000, cls: 'debris' },
|
||||
});
|
||||
|
||||
/** Mapped sites as the installations layer keeps them. */
|
||||
const SITES = Object.freeze({
|
||||
alpha: {
|
||||
id: 'osm:military:way/101',
|
||||
osmKey: 'way/101',
|
||||
name: 'Camp Alpha',
|
||||
class: 'base',
|
||||
lat: 31,
|
||||
lon: -96.5,
|
||||
memberNames: ['North Field'],
|
||||
at: { x: 100, y: 100 },
|
||||
},
|
||||
bravo: {
|
||||
id: 'osm:military:way/202',
|
||||
osmKey: 'way/202',
|
||||
name: 'Bravo Field',
|
||||
class: 'airfield',
|
||||
lat: 29.2,
|
||||
lon: -97.8,
|
||||
at: { x: 300, y: 300 },
|
||||
},
|
||||
// Beyond the ±45° reach of the ISS at its start.
|
||||
far: {
|
||||
id: 'osm:military:way/303',
|
||||
osmKey: 'way/303',
|
||||
name: 'Far Range',
|
||||
class: 'range',
|
||||
lat: 33.5,
|
||||
lon: -101,
|
||||
at: { x: 500, y: 50 },
|
||||
},
|
||||
});
|
||||
|
||||
const EMPTY_GROUND = Object.freeze({ x: 640, y: 360 });
|
||||
|
||||
/** The Mapped Installations layer: its records, getNearby, getById, findByPick. */
|
||||
function installationsLayer() {
|
||||
const records = Object.values(SITES).map((site) => ({
|
||||
id: site.id,
|
||||
osmKey: site.osmKey,
|
||||
name: site.name,
|
||||
class: site.class,
|
||||
kind: 'installation',
|
||||
latitude: site.lat,
|
||||
longitude: site.lon,
|
||||
memberNames: site.memberNames || [],
|
||||
sources: [{ name: 'OpenStreetMap', id: site.osmKey }],
|
||||
}));
|
||||
const layer = {
|
||||
enabled: true,
|
||||
records,
|
||||
calls: { getNearby: 0 },
|
||||
withPosition(record) {
|
||||
return {
|
||||
...record,
|
||||
position: Cesium.Cartesian3.fromDegrees(record.longitude, record.latitude, 0),
|
||||
};
|
||||
},
|
||||
// As the layer's own: loaded installations within `rangeM` of
|
||||
// `center`, nearest first, each with its drawn position and distance.
|
||||
getNearby(center, rangeM, maxCount = 50) {
|
||||
layer.calls.getNearby += 1;
|
||||
if (!center) return [];
|
||||
const from = Cesium.Cartographic.fromCartesian(center);
|
||||
const geodesic = new Cesium.EllipsoidGeodesic();
|
||||
return layer.records
|
||||
.filter((record) => record.kind === 'installation')
|
||||
.map((record) => {
|
||||
geodesic.setEndPoints(
|
||||
from,
|
||||
Cesium.Cartographic.fromDegrees(record.longitude, record.latitude),
|
||||
);
|
||||
return { ...layer.withPosition(record), distanceM: geodesic.surfaceDistance };
|
||||
})
|
||||
.filter((record) => record.distanceM <= rangeM)
|
||||
.sort((a, b) => a.distanceM - b.distanceM)
|
||||
.slice(0, maxCount);
|
||||
},
|
||||
getById(id) {
|
||||
if (!layer.enabled) return null;
|
||||
const record = layer.records.find((r) => r.id === String(id));
|
||||
return record ? layer.withPosition(record) : null;
|
||||
},
|
||||
findByPick(picked) {
|
||||
const id =
|
||||
picked?.id?.installationId ||
|
||||
(typeof picked?.id?.id === 'string' ? picked.id.id : null);
|
||||
return id ? layer.getById(id) : null;
|
||||
},
|
||||
};
|
||||
return layer;
|
||||
}
|
||||
|
||||
/** The satellites layer: tracking, the Cockpit subject and every position. */
|
||||
function satellitesLayer(viewer) {
|
||||
const positions = new Map(
|
||||
Object.entries(SATELLITES).map(([id, sat]) => [Number(id), { ...sat }]),
|
||||
);
|
||||
const layer = {
|
||||
tracked: 25544,
|
||||
calls: [],
|
||||
position(id) {
|
||||
const sat = positions.get(id);
|
||||
return Cesium.Cartesian3.fromDegrees(sat.lon, sat.lat, sat.alt);
|
||||
},
|
||||
move(dLat, dLon) {
|
||||
const sat = positions.get(layer.tracked);
|
||||
sat.lat += dLat;
|
||||
sat.lon += dLon;
|
||||
},
|
||||
getCockpitSubject() {
|
||||
if (layer.tracked === null) return null;
|
||||
const sat = positions.get(layer.tracked);
|
||||
return {
|
||||
kind: 'satellite',
|
||||
layerId: 'satellites',
|
||||
id: String(layer.tracked),
|
||||
noradId: layer.tracked,
|
||||
name: sat.name,
|
||||
classLabel: sat.cls.toUpperCase(),
|
||||
latitude: sat.lat,
|
||||
longitude: sat.lon,
|
||||
altitudeM: sat.alt,
|
||||
velocityMps: 7_600,
|
||||
groundTrackDeg: 51.6,
|
||||
satelliteClass: sat.cls,
|
||||
stale: false,
|
||||
};
|
||||
},
|
||||
getCockpitPosition(result) {
|
||||
if (layer.tracked === null) return null;
|
||||
return Cesium.Cartesian3.clone(layer.position(layer.tracked), result);
|
||||
},
|
||||
getAllPositions(maxCount = 300) {
|
||||
return [...positions.entries()].slice(0, maxCount).map(([id, sat]) => ({
|
||||
id,
|
||||
label: sat.name,
|
||||
position: layer.position(id),
|
||||
latitude: sat.lat,
|
||||
longitude: sat.lon,
|
||||
altitudeM: sat.alt,
|
||||
satelliteClass: sat.cls,
|
||||
}));
|
||||
},
|
||||
// As the layer's: the nearest shown satellites, bounded, with the
|
||||
// asked-for ids and classes left out.
|
||||
getNearestPositions(center, maxCount = 8, { excludeIds = [], excludeClasses = [] } = {}) {
|
||||
layer.calls.push(['nearest']);
|
||||
const skip = new Set(excludeIds.map(String));
|
||||
return layer
|
||||
.getAllPositions()
|
||||
.filter((entry) => !skip.has(String(entry.id)))
|
||||
.filter((entry) => !excludeClasses.includes(entry.satelliteClass))
|
||||
.map((entry) => ({
|
||||
...entry,
|
||||
distanceM: Cesium.Cartesian3.distance(center, entry.position),
|
||||
}))
|
||||
.sort((a, b) => a.distanceM - b.distanceM)
|
||||
.slice(0, maxCount);
|
||||
},
|
||||
/** The satellite leaves the catalogue. */
|
||||
remove(id) {
|
||||
positions.delete(Number(id));
|
||||
},
|
||||
// As the layer's: tracking hands the camera to Cesium's follow.
|
||||
trackById(noradId) {
|
||||
const id = Number(noradId);
|
||||
if (!positions.has(id)) return false;
|
||||
layer.calls.push(['track', id]);
|
||||
layer.tracked = id;
|
||||
viewer.trackedEntity = { position: { getValue: () => layer.position(id) } };
|
||||
return true;
|
||||
},
|
||||
setCockpitSubject(noradId) {
|
||||
layer.calls.push(['subject', noradId]);
|
||||
return true;
|
||||
},
|
||||
refocusTrackedById: () => true,
|
||||
drop() {
|
||||
layer.tracked = null;
|
||||
},
|
||||
};
|
||||
return layer;
|
||||
}
|
||||
|
||||
function fixture(t, { reducedMotion = false } = {}) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
const app = createApp(
|
||||
defineComponent(() => () => [h(ContextView), h(IntelHudView), h(CockpitView)]),
|
||||
).use(pinia);
|
||||
app.mount(host);
|
||||
useHudStore(pinia);
|
||||
const store = useCockpitStore(pinia);
|
||||
const previousMatchMedia = globalThis.matchMedia;
|
||||
globalThis.matchMedia = (query) => ({
|
||||
matches: query.includes('reduce') && reducedMotion,
|
||||
});
|
||||
const listeners = () => ({ addEventListener: () => () => {} });
|
||||
const shots = [];
|
||||
const picks = new Map();
|
||||
const viewer = {
|
||||
trackedEntity: undefined,
|
||||
clock: { currentTime: null },
|
||||
camera: {
|
||||
frustum: { fov: 1, aspectRatio: ASPECT },
|
||||
cancelFlight() {},
|
||||
setView({ destination, orientation }) {
|
||||
shots.push({
|
||||
destination: Cesium.Cartesian3.clone(destination),
|
||||
direction: Cesium.Cartesian3.clone(orientation.direction),
|
||||
up: Cesium.Cartesian3.clone(orientation.up),
|
||||
});
|
||||
},
|
||||
},
|
||||
entities: { contains: () => false },
|
||||
scene: {
|
||||
preUpdate: listeners(),
|
||||
screenSpaceCameraController: { enableInputs: true },
|
||||
pick: (position) => picks.get(`${position.x},${position.y}`),
|
||||
},
|
||||
trackedEntityChanged: listeners(),
|
||||
};
|
||||
// The Viewer's own input handler: its single click picks into
|
||||
// selectedEntity; its double-click tracks what it picks, which would end
|
||||
// the orbital view.
|
||||
const actions = new Map();
|
||||
const handler = {
|
||||
stockClicks: 0,
|
||||
stockDoubleClicks: 0,
|
||||
getInputAction: (type) => actions.get(type),
|
||||
setInputAction: (action, type) => actions.set(type, action),
|
||||
removeInputAction: (type) => actions.delete(type),
|
||||
isDestroyed: () => false,
|
||||
};
|
||||
handler.stock = () => {
|
||||
handler.stockClicks += 1;
|
||||
};
|
||||
handler.stockDouble = ({ position }) => {
|
||||
handler.stockDoubleClicks += 1;
|
||||
const picked = viewer.scene.pick(position);
|
||||
viewer.trackedEntity = picked
|
||||
? { position: { getValue: () => null } }
|
||||
: undefined;
|
||||
};
|
||||
actions.set(Cesium.ScreenSpaceEventType.LEFT_CLICK, handler.stock);
|
||||
actions.set(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, handler.stockDouble);
|
||||
viewer.screenSpaceEventHandler = handler;
|
||||
|
||||
const sites = installationsLayer();
|
||||
const satellites = satellitesLayer(viewer);
|
||||
const modeEvents = [];
|
||||
const onMode = (event) => modeEvents.push(event.detail);
|
||||
window.addEventListener('gev:cockpit-mode-changed', onMode);
|
||||
const cockpit = new CockpitViewController(viewer, {
|
||||
services: {
|
||||
flightsLayer: { getTrackedInfo: () => null },
|
||||
militaryFlightsLayer: { getTrackedInfo: () => null },
|
||||
aisLiveVesselsLayer: { getCockpitSubject: () => null },
|
||||
satellitesLayer: satellites,
|
||||
militaryInstallationsLayer: sites,
|
||||
militaryAwarenessLayer: {},
|
||||
isLayerEnabled: (layerId) =>
|
||||
layerId === 'military-installations' ? sites.enabled : true,
|
||||
isTr3b: () => false,
|
||||
holdContinuousRender() {},
|
||||
releaseContinuousRender() {},
|
||||
cachedGroundFloor: () => null,
|
||||
GROUND_FLOOR_LIFT_M: 0,
|
||||
},
|
||||
isEntryAllowed: () => false,
|
||||
isBridgeEntryAllowed: () => false,
|
||||
isOrbitEntryAllowed: () => true,
|
||||
publish: {
|
||||
presence: (view) => store.publishPresence(view),
|
||||
instruments: (view) => store.publishInstruments(view),
|
||||
route: (view) => store.publishRoute(view),
|
||||
radar: (view) => store.publishRadar(view),
|
||||
orbital: (view) => store.publishOrbital(view),
|
||||
signals: (rows) => store.publishSignals(rows),
|
||||
},
|
||||
});
|
||||
Object.assign(cockpit, {
|
||||
setVisionMode() {},
|
||||
showBriefPage() {},
|
||||
startBriefRotation() {},
|
||||
stopBriefRotation() {},
|
||||
scheduleContextLayout() {},
|
||||
updateLocalPosition() {},
|
||||
maybeRefreshRegionalBrief() {},
|
||||
updateContext() {},
|
||||
updateRoute() {},
|
||||
});
|
||||
// Named markers pick as `{ installationId }`, as the layer draws them.
|
||||
for (const site of Object.values(SITES))
|
||||
picks.set(`${site.at.x},${site.at.y}`, {
|
||||
id: { installationId: site.id },
|
||||
primitive: {},
|
||||
});
|
||||
|
||||
const originalNow = performance.now;
|
||||
const originalDateNow = Date.now;
|
||||
let nowMs = START_MS;
|
||||
performance.now = () => nowMs;
|
||||
Date.now = () => nowMs;
|
||||
|
||||
t.after(() => {
|
||||
window.removeEventListener('gev:cockpit-mode-changed', onMode);
|
||||
cockpit.stop();
|
||||
app.unmount();
|
||||
globalThis.matchMedia = previousMatchMedia;
|
||||
performance.now = originalNow;
|
||||
Date.now = originalDateNow;
|
||||
document.body.classList.remove('cockpit-mode', 'cockpit-bridge', 'cockpit-orbit');
|
||||
});
|
||||
|
||||
const frame = () => {
|
||||
nowMs += FRAME_MS;
|
||||
cockpit.update();
|
||||
return shots.at(-1);
|
||||
};
|
||||
const fire = (type, position) => actions.get(type)?.({ position });
|
||||
return {
|
||||
$: (selector) => document.querySelector(selector),
|
||||
cockpit,
|
||||
viewer,
|
||||
store,
|
||||
shots,
|
||||
handler,
|
||||
sites,
|
||||
satellites,
|
||||
modeEvents,
|
||||
frame,
|
||||
click: (position) => fire(Cesium.ScreenSpaceEventType.LEFT_CLICK, position),
|
||||
/** A double-click as Cesium fires it: two clicks, then the double. */
|
||||
doubleClick(position) {
|
||||
fire(Cesium.ScreenSpaceEventType.LEFT_CLICK, position);
|
||||
fire(Cesium.ScreenSpaceEventType.LEFT_CLICK, position);
|
||||
fire(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, position);
|
||||
},
|
||||
/** Rebuild the Context card on the next frame, past its clock. */
|
||||
refreshCard() {
|
||||
nowMs += 1000;
|
||||
cockpit.update();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
async function inOrbit(t, options) {
|
||||
const scene = fixture(t, options);
|
||||
assert.equal(scene.cockpit.enter(), true);
|
||||
await settle();
|
||||
scene.frame();
|
||||
scene.refreshCard();
|
||||
await settle();
|
||||
return scene;
|
||||
}
|
||||
|
||||
const angleDeg = (a, b) =>
|
||||
Cesium.Math.toDegrees(Cesium.Cartesian3.angleBetween(a, b));
|
||||
|
||||
const sitePosition = (key) =>
|
||||
Cesium.Cartesian3.fromDegrees(SITES[key].lon, SITES[key].lat, 0);
|
||||
|
||||
/** How far the camera looks from a site, degrees. */
|
||||
function missDeg(shot, key) {
|
||||
const line = Cesium.Cartesian3.subtract(
|
||||
sitePosition(key),
|
||||
shot.destination,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
return angleDeg(shot.direction, line);
|
||||
}
|
||||
|
||||
/** The camera's angle from nadir, degrees. */
|
||||
function offNadir(shot) {
|
||||
const toCentre = Cesium.Cartesian3.negate(shot.destination, new Cesium.Cartesian3());
|
||||
return angleDeg(shot.direction, toCentre);
|
||||
}
|
||||
|
||||
/** The off-nadir angle to a site from the camera's position, degrees. */
|
||||
function siteOffNadir(shot, key) {
|
||||
const line = Cesium.Cartesian3.subtract(
|
||||
sitePosition(key),
|
||||
shot.destination,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const toCentre = Cesium.Cartesian3.negate(shot.destination, new Cesium.Cartesian3());
|
||||
return angleDeg(line, toCentre);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run frames, the satellite drifting a little each one, and return the
|
||||
* largest turn of the camera between two frames.
|
||||
*/
|
||||
function run(scene, frames, { drift = 0.0005 } = {}) {
|
||||
let largest = 0;
|
||||
let previous = scene.shots.at(-1);
|
||||
for (let i = 0; i < frames; i += 1) {
|
||||
scene.satellites.move(drift, drift);
|
||||
const shot = scene.frame();
|
||||
largest = Math.max(largest, angleDeg(previous.direction, shot.direction));
|
||||
previous = shot;
|
||||
}
|
||||
return largest;
|
||||
}
|
||||
|
||||
/** Frames enough for the focus easing to land (about 12 time constants). */
|
||||
const LAND_FRAMES = Math.ceil((12 * ORBITAL_FOCUS_EASE_TAU_MS) / FRAME_MS);
|
||||
|
||||
/**
|
||||
* No frame turns the camera further than this: a smooth turn, no jump. The
|
||||
* focus clock moves about 6% of the way in a 16 ms frame, so even a swing
|
||||
* back from the 45° reach stays under it.
|
||||
*/
|
||||
const MAX_TURN_PER_FRAME_DEG = 3;
|
||||
|
||||
/** A Live Signals row's button, by layer and id. */
|
||||
const rowButton = (scene, layerId, id) =>
|
||||
scene.$(
|
||||
`#cockpit-signal-list button[data-signal-layer="${layerId}"][data-signal-id="${id}"]`,
|
||||
);
|
||||
const siteRow = (scene, key) =>
|
||||
rowButton(scene, 'military-installations', SITES[key].id);
|
||||
const satelliteRow = (scene, id) => rowButton(scene, 'satellites', String(id));
|
||||
/** The rows as published: title, detail, tone and target. */
|
||||
const rows = (scene) => scene.store.signals ?? [];
|
||||
/** Rebuild the rows and let the view render them. */
|
||||
async function refreshRows(scene) {
|
||||
scene.refreshCard();
|
||||
await settle();
|
||||
}
|
||||
|
||||
test('in orbit Live Signals lists the sites getNearby finds and the nearest satellites', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { $, sites } = scene;
|
||||
assert.ok(sites.calls.getNearby > 0, 'asked the installations layer');
|
||||
assert.equal($('#cockpit-context').hidden, true, 'no Contact card in orbit');
|
||||
const shown = rows(scene);
|
||||
assert.ok(shown.length <= 5, 'five rows at most');
|
||||
assert.equal(shown[0].title, 'TRACK ACQUIRED', 'the track row stays first');
|
||||
// Two site rows, nearest to nadir first, then the satellites (debris out).
|
||||
const sitesShown = shown.filter((row) => row.target?.layerId === 'military-installations');
|
||||
assert.deepEqual(
|
||||
sitesShown.map((row) => row.target.id).sort(),
|
||||
[SITES.alpha.id, SITES.bravo.id].sort(),
|
||||
);
|
||||
for (const row of sitesShown) {
|
||||
assert.match(row.detail, /^(BASE|AIRFIELD) · OFF-NADIR \d+\.\d°$/);
|
||||
assert.match(row.className, /nearby actionable/);
|
||||
}
|
||||
const satellitesShown = shown.filter((row) => row.target?.layerId === 'satellites');
|
||||
assert.deepEqual(satellitesShown.map((row) => row.title), ['LANDSAT 9', 'SENTINEL-2A']);
|
||||
assert.match(satellitesShown[0].detail, /^SATELLITE · (AHEAD|[LR] \d{3}°) · [\d,.]+\s+KM$/);
|
||||
// Each row names its own action.
|
||||
assert.equal(siteRow(scene, 'alpha').getAttribute('aria-label'), 'Keep the camera on Camp Alpha');
|
||||
assert.equal(satelliteRow(scene, 49260).getAttribute('aria-label'), 'Ride LANDSAT 9');
|
||||
// Rebuilt on the clock, rows keep their keys and times.
|
||||
const before = shown.map((row) => [row.key, row.time]);
|
||||
await refreshRows(scene);
|
||||
assert.deepEqual(rows(scene).map((row) => [row.key, row.time]), before);
|
||||
});
|
||||
|
||||
test('a site row turns the camera onto it, holds it, and reads its off-nadir angle', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { $, cockpit, store } = scene;
|
||||
assert.ok(missDeg(scene.shots.at(-1), 'alpha') > 10, 'not centred at nadir');
|
||||
siteRow(scene, 'alpha').click();
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
// The first frames turn part of the way: no jump onto the site.
|
||||
assert.ok(missDeg(scene.frame(), 'alpha') > 5, 'still turning');
|
||||
const largest = run(scene, LAND_FRAMES);
|
||||
assert.ok(largest > 0.1 && largest < MAX_TURN_PER_FRAME_DEG, `turned ${largest}° in a frame`);
|
||||
for (let i = 0; i < 20; i += 1) {
|
||||
scene.satellites.move(0.002, 0.002);
|
||||
const shot = scene.frame();
|
||||
assert.ok(missDeg(shot, 'alpha') < 1e-5, `frame ${i}: ${missDeg(shot, 'alpha')}°`);
|
||||
}
|
||||
for (let i = 0; i < 8; i += 1) scene.frame();
|
||||
await settle();
|
||||
const shot = scene.shots.at(-1);
|
||||
assert.equal(
|
||||
$('#cockpit-orbital-look-readout').textContent,
|
||||
`OFF-NADIR ${siteOffNadir(shot, 'alpha').toFixed(1)}°`,
|
||||
);
|
||||
assert.equal($('#cockpit-orbital-focus').textContent, 'FOCUS · Camp Alpha');
|
||||
assert.equal($('#cockpit-orbital-look-readout').getAttribute('aria-live'), 'off');
|
||||
assert.equal(store.orbital.footprintKm, null);
|
||||
assert.match($('.cockpit-orbital-swath').textContent, /^SWATH ≈ [\d.]+ KM$/);
|
||||
// The held site's row reads as the subject does, first among the sites.
|
||||
const held = rows(scene).find((row) => row.target?.id === SITES.alpha.id);
|
||||
assert.match(held.className, /^track actionable$/);
|
||||
assert.match(held.detail, /^FOCUS · BASE · OFF-NADIR/);
|
||||
assert.equal(siteRow(scene, 'alpha').getAttribute('aria-label'), 'Release the camera from Camp Alpha');
|
||||
});
|
||||
|
||||
test('another site row switches the focus; the held site row ends it', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit } = scene;
|
||||
siteRow(scene, 'alpha').click();
|
||||
run(scene, LAND_FRAMES);
|
||||
await settle();
|
||||
siteRow(scene, 'bravo').click();
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.bravo.id);
|
||||
const largest = run(scene, LAND_FRAMES);
|
||||
assert.ok(largest < MAX_TURN_PER_FRAME_DEG, `turned ${largest}° in a frame`);
|
||||
assert.ok(missDeg(scene.shots.at(-1), 'bravo') < 1e-5);
|
||||
await settle();
|
||||
assert.match(rows(scene).find((row) => row.target?.id === SITES.alpha.id).className, /^nearby/);
|
||||
siteRow(scene, 'bravo').click();
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
const back = run(scene, LAND_FRAMES, { drift: 0 });
|
||||
assert.ok(back < MAX_TURN_PER_FRAME_DEG);
|
||||
assert.ok(offNadir(scene.shots.at(-1)) < 1e-6, 'back at nadir');
|
||||
});
|
||||
|
||||
test('a click on a site marker focuses it through the layer; a click elsewhere eases back', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, handler } = scene;
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
assert.equal(handler.stockClicks, 1, 'Cesium still gets the click');
|
||||
run(scene, LAND_FRAMES);
|
||||
assert.ok(missDeg(scene.shots.at(-1), 'alpha') < 1e-5);
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id, 'kept on a second click');
|
||||
const focused = offNadir(scene.shots.at(-1));
|
||||
scene.click(EMPTY_GROUND);
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
assert.ok(offNadir(scene.frame()) > focused * 0.8, 'no jump back');
|
||||
const largest = run(scene, LAND_FRAMES, { drift: 0 });
|
||||
assert.ok(largest < MAX_TURN_PER_FRAME_DEG);
|
||||
assert.ok(offNadir(scene.shots.at(-1)) < 1e-6);
|
||||
// A site beyond the reach is not focused, and ends a focus as a click
|
||||
// elsewhere does.
|
||||
scene.click(SITES.far.at);
|
||||
assert.equal(cockpit.orbital.focus ?? null, null);
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
scene.click(SITES.far.at);
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
});
|
||||
|
||||
test('a click a tool owns is left alone', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const lease = claimPointer('draw');
|
||||
t.after(() => releasePointer(lease));
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(scene.cockpit.orbital.focus ?? null, null, 'no focus while drawing');
|
||||
releasePointer(lease);
|
||||
scene.click(SITES.alpha.at);
|
||||
const again = claimPointer('draw');
|
||||
t.after(() => releasePointer(again));
|
||||
scene.click(EMPTY_GROUND);
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.alpha.id, 'kept while drawing');
|
||||
});
|
||||
|
||||
test('a double-click on a site focuses it and keeps the orbital view', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, viewer, handler } = scene;
|
||||
scene.doubleClick(SITES.alpha.at);
|
||||
assert.equal(handler.stockDoubleClicks, 0, 'Cesium does not track the site');
|
||||
assert.equal(viewer.trackedEntity, undefined);
|
||||
scene.frame();
|
||||
assert.equal(cockpit.active, true, 'still in orbit');
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
scene.doubleClick(SITES.bravo.at);
|
||||
assert.equal(cockpit.orbital.focus.key, SITES.bravo.id);
|
||||
scene.doubleClick(SITES.far.at);
|
||||
assert.equal(handler.stockDoubleClicks, 0, 'beyond reach: not focused, not tracked');
|
||||
scene.frame();
|
||||
assert.equal(cockpit.active, true);
|
||||
scene.doubleClick(EMPTY_GROUND);
|
||||
assert.equal(handler.stockDoubleClicks, 1, 'anywhere else goes on to Cesium');
|
||||
});
|
||||
|
||||
test('the focus ends by itself, easing back, when the site leaves the reach', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit } = scene;
|
||||
siteRow(scene, 'bravo').click();
|
||||
run(scene, LAND_FRAMES, { drift: 0 });
|
||||
let released = null;
|
||||
let previous = scene.shots.at(-1);
|
||||
let largest = 0;
|
||||
for (let i = 0; i < 2000 && released === null; i += 1) {
|
||||
scene.satellites.move(0.004, 0.004);
|
||||
const shot = scene.frame();
|
||||
largest = Math.max(largest, angleDeg(previous.direction, shot.direction));
|
||||
previous = shot;
|
||||
if (!cockpit.orbital.focus) released = i;
|
||||
}
|
||||
assert.ok(released > 0, 'the focus ended');
|
||||
assert.ok(offNadir(scene.shots.at(-1)) > 40, 'held to the reach');
|
||||
largest = Math.max(largest, run(scene, LAND_FRAMES, { drift: 0 }));
|
||||
assert.ok(largest < MAX_TURN_PER_FRAME_DEG, `turned ${largest}° in a frame`);
|
||||
assert.ok(offNadir(scene.shots.at(-1)) < 1e-6, 'back at nadir');
|
||||
});
|
||||
|
||||
test('turning the layer off ends the focus and says why; a reload around the site keeps it', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
scene.click(SITES.alpha.at);
|
||||
run(scene, 5);
|
||||
scene.sites.enabled = false;
|
||||
scene.frame();
|
||||
assert.equal(scene.cockpit.orbital.focus, null, 'layer off');
|
||||
assert.equal(scene.cockpit.orbital.focusReleasing, true, 'easing back');
|
||||
await refreshRows(scene);
|
||||
const status = rows(scene).find((row) => row.title === 'SITES STANDBY');
|
||||
assert.ok(status, 'a status row says why no site is listed');
|
||||
assert.equal(status.detail, 'ENABLE MAPPED INSTALLATIONS FOR SITE PINGS');
|
||||
assert.equal(status.className, 'warning');
|
||||
assert.ok(!rows(scene).some((row) => row.target?.layerId === 'military-installations'));
|
||||
assert.equal(rows(scene).filter((row) => row.target?.layerId === 'satellites').length, 2);
|
||||
scene.sites.enabled = true;
|
||||
await refreshRows(scene);
|
||||
assert.ok(!rows(scene).some((row) => row.title === 'SITES STANDBY'));
|
||||
scene.click(SITES.bravo.at);
|
||||
run(scene, LAND_FRAMES);
|
||||
// The layer reloads its thinned view: the site leaves its records for a
|
||||
// while. It has not moved, so the focus stays on it.
|
||||
const loaded = scene.sites.records;
|
||||
scene.sites.records = loaded.filter((r) => r.id !== SITES.bravo.id);
|
||||
run(scene, 10);
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.bravo.id, 'kept through a reload');
|
||||
assert.ok(missDeg(scene.shots.at(-1), 'bravo') < 1e-5, 'still centred');
|
||||
scene.sites.records = loaded;
|
||||
// A row the list shows works even if the layer just dropped its site.
|
||||
await refreshRows(scene);
|
||||
scene.sites.records = loaded.filter((r) => r.id !== SITES.alpha.id);
|
||||
siteRow(scene, 'alpha').click();
|
||||
assert.equal(scene.cockpit.orbital.focus.key, SITES.alpha.id);
|
||||
});
|
||||
|
||||
test('a satellite row rides it, staying in orbit; RETURN goes back', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, satellites, viewer, modeEvents } = scene;
|
||||
assert.ok(!rows(scene).some((row) => row.title.startsWith('RETURN')), 'no history yet');
|
||||
siteRow(scene, 'alpha').click();
|
||||
run(scene, 5);
|
||||
const before = Cesium.Cartesian3.clone(scene.shots.at(-1).destination);
|
||||
|
||||
const firstTrack = cockpit.signalItems.find((item) => item.key === 'track');
|
||||
firstTrack.timestamp -= 60_000;
|
||||
satelliteRow(scene, 49260).click();
|
||||
const newTrack = cockpit.signalItems.filter((item) => item.key === 'track');
|
||||
assert.equal(newTrack.length, 1);
|
||||
assert.ok(newTrack[0].timestamp > firstTrack.timestamp, 'the new ride’s own time');
|
||||
assert.deepEqual(satellites.calls.slice(-2), [['track', 49260], ['subject', 49260]]);
|
||||
assert.equal(viewer.trackedEntity, undefined, 'the Cockpit keeps the camera');
|
||||
assert.equal(cockpit.subjectId, 49260);
|
||||
assert.equal(cockpit.orbital.focus, null, 'the focus is reset');
|
||||
assert.equal(modeEvents.at(-1)?.active, true);
|
||||
await settle();
|
||||
const shown = rows(scene);
|
||||
assert.deepEqual([shown[0].title, shown[0].detail], ['TRACK ACQUIRED', 'LANDSAT 9 · NADIR VIEW']);
|
||||
assert.equal(shown.filter((row) => row.title === 'TRACK ACQUIRED').length, 1);
|
||||
const back = shown.find((row) => row.title === 'RETURN · ISS (ZARYA)');
|
||||
assert.ok(back, 'a RETURN row while there is history');
|
||||
assert.equal(back.detail, 'PREVIOUS SATELLITE');
|
||||
assert.equal(satelliteRow(scene, 25544).getAttribute('aria-label'), 'Return to ISS (ZARYA)');
|
||||
assert.ok(!shown.some((row) => row.title === 'ISS (ZARYA)'), 'listed once, as RETURN');
|
||||
|
||||
// The camera hops along the way, never in one jump.
|
||||
const target = satellites.position(49260);
|
||||
const hopM = Cesium.Cartesian3.distance(before, target);
|
||||
let previous = before;
|
||||
let largestStep = 0;
|
||||
for (let i = 0; i < Math.ceil(ORBITAL_HOP_MS / FRAME_MS) + 2; i += 1) {
|
||||
const shot = scene.frame();
|
||||
assert.equal(cockpit.active, true, `still in orbit at frame ${i}`);
|
||||
largestStep = Math.max(largestStep, Cesium.Cartesian3.distance(previous, shot.destination));
|
||||
previous = shot.destination;
|
||||
}
|
||||
assert.ok(largestStep < hopM * 0.1, `largest step ${largestStep} m of ${hopM} m`);
|
||||
assert.ok(Cesium.Cartesian3.distance(previous, target) < 1, 'landed on the satellite');
|
||||
run(scene, LAND_FRAMES, { drift: 0 });
|
||||
assert.ok(offNadir(scene.shots.at(-1)) < 1e-6, 'looking at nadir');
|
||||
|
||||
// On to another, then RETURN twice back to the start.
|
||||
await refreshRows(scene);
|
||||
satelliteRow(scene, 40697).click();
|
||||
assert.equal(cockpit.subjectId, 40697);
|
||||
await settle();
|
||||
assert.ok(rows(scene).some((row) => row.title === 'RETURN · LANDSAT 9'));
|
||||
satelliteRow(scene, 49260).click();
|
||||
assert.equal(cockpit.subjectId, 49260);
|
||||
await settle();
|
||||
satelliteRow(scene, 25544).click();
|
||||
assert.equal(cockpit.subjectId, 25544);
|
||||
await settle();
|
||||
assert.ok(!rows(scene).some((row) => row.title.startsWith('RETURN')), 'back at the start');
|
||||
scene.frame();
|
||||
assert.equal(cockpit.active, true);
|
||||
assert.ok(!satellites.calls.some(([, id]) => id === 99001), 'debris never offered');
|
||||
});
|
||||
|
||||
test('while the camera hops, no stale rows; on landing, rows measured from the new satellite', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit } = scene;
|
||||
satelliteRow(scene, 49260).click();
|
||||
await settle();
|
||||
// Mid-hop: TRACK ACQUIRED and RETURN only, nothing measured from the old
|
||||
// satellite's frame (which would list LANDSAT 9 itself at 0 km).
|
||||
let shown = rows(scene);
|
||||
assert.deepEqual(
|
||||
shown.map((row) => row.title),
|
||||
['TRACK ACQUIRED', 'RETURN · ISS (ZARYA)'],
|
||||
);
|
||||
scene.frame();
|
||||
scene.refreshCard();
|
||||
await settle();
|
||||
assert.ok(cockpit.orbital.hop, 'still hopping');
|
||||
assert.deepEqual(rows(scene).map((row) => row.title), ['TRACK ACQUIRED', 'RETURN · ISS (ZARYA)']);
|
||||
// Landed: the first frame on the satellite rebuilds them at once.
|
||||
for (let i = 0; i < Math.ceil(ORBITAL_HOP_MS / FRAME_MS) + 2; i += 1) scene.frame();
|
||||
await settle();
|
||||
shown = rows(scene);
|
||||
assert.ok(shown.some((row) => row.target?.layerId === 'military-installations'), 'sites back');
|
||||
const satellitesShown = shown.filter((row) => row.title !== 'TRACK ACQUIRED' && row.target?.layerId === 'satellites');
|
||||
assert.ok(!satellitesShown.some((row) => row.title === 'LANDSAT 9'), 'never the ridden one');
|
||||
assert.equal(satellitesShown.filter((row) => row.target.id === '25544').length, 1, 'ISS only as RETURN');
|
||||
});
|
||||
|
||||
test('RETURN to a satellite that left the catalogue offers the one before it', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, satellites } = scene;
|
||||
satelliteRow(scene, 49260).click();
|
||||
for (let i = 0; i < 80; i += 1) scene.frame();
|
||||
await settle();
|
||||
satelliteRow(scene, 40697).click();
|
||||
for (let i = 0; i < 80; i += 1) scene.frame();
|
||||
await settle();
|
||||
assert.ok(rows(scene).some((row) => row.title === 'RETURN · LANDSAT 9'));
|
||||
satellites.remove(49260);
|
||||
satelliteRow(scene, 49260).click();
|
||||
assert.equal(cockpit.subjectId, 40697, 'still on the same satellite');
|
||||
await settle();
|
||||
assert.ok(rows(scene).some((row) => row.title === 'RETURN · ISS (ZARYA)'), 'the one before');
|
||||
satelliteRow(scene, 25544).click();
|
||||
assert.equal(cockpit.subjectId, 25544);
|
||||
});
|
||||
|
||||
test('with Installations off no site is offered, by row, list or click', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit, sites } = scene;
|
||||
// The real layer keeps its records and getNearby answers while off.
|
||||
sites.enabled = false;
|
||||
await refreshRows(scene);
|
||||
assert.ok(rows(scene).some((row) => row.title === 'SITES STANDBY'));
|
||||
assert.equal(cockpit.orbital.listedSites.size, 0, 'nothing kept to focus from');
|
||||
assert.equal(cockpit.toggleOrbitalFocus(SITES.alpha.id), false);
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.equal(cockpit.orbital.focus ?? null, null);
|
||||
});
|
||||
|
||||
test('an arrow during the ease back from a focus turns on the arrows’ clock', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { cockpit } = scene;
|
||||
siteRow(scene, 'alpha').click();
|
||||
run(scene, LAND_FRAMES);
|
||||
scene.click(EMPTY_GROUND);
|
||||
scene.frame();
|
||||
assert.equal(cockpit.orbital.focusReleasing, true);
|
||||
const view = { ...cockpit.orbital.lookView };
|
||||
assert.ok(Math.abs(view.pitchDeg) > 1 || Math.abs(view.yawDeg) > 1, 'still turned');
|
||||
cockpit.onKeyDown({
|
||||
key: 'ArrowUp',
|
||||
target: document.body,
|
||||
preventDefault() {},
|
||||
stopImmediatePropagation() {},
|
||||
});
|
||||
assert.equal(cockpit.orbital.focusReleasing, false);
|
||||
// The arrow tilts on from where the view is, not from nadir.
|
||||
assert.ok(
|
||||
Math.abs(cockpit.orbital.lookTarget.yawDeg - view.yawDeg) < 1e-6,
|
||||
'across kept',
|
||||
);
|
||||
assert.ok(cockpit.orbital.lookTarget.pitchDeg > view.pitchDeg, 'tilted on up');
|
||||
});
|
||||
|
||||
test('leaving orbit leaves no orbital rows to act on', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
scene.click(SITES.alpha.at);
|
||||
run(scene, 5);
|
||||
scene.satellites.drop();
|
||||
scene.frame();
|
||||
assert.equal(scene.cockpit.active, false);
|
||||
assert.equal(scene.store.presence.context, false);
|
||||
scene.click(SITES.bravo.at);
|
||||
assert.equal(scene.cockpit.toggleOrbitalFocus(SITES.bravo.id), false);
|
||||
assert.equal(scene.cockpit.onOrbitalClick(SITES.bravo.at), false);
|
||||
assert.equal(scene.cockpit.rideOrbitalSatellite(49260), false);
|
||||
assert.equal(scene.cockpit.handleOrbitalSignalClick('satellites', '49260'), false);
|
||||
});
|
||||
|
||||
test('NADIR and Home end a focus; an arrow takes the view over where it is', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
const { $, cockpit } = scene;
|
||||
const press = (key) =>
|
||||
cockpit.onKeyDown({
|
||||
key,
|
||||
target: document.body,
|
||||
preventDefault() {},
|
||||
stopImmediatePropagation() {},
|
||||
});
|
||||
scene.click(SITES.alpha.at);
|
||||
run(scene, LAND_FRAMES);
|
||||
await settle();
|
||||
$('#cockpit-orbital-nadir').click();
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
assert.ok(offNadir(scene.frame()) > 5, 'eases back');
|
||||
scene.click(SITES.alpha.at);
|
||||
run(scene, LAND_FRAMES);
|
||||
press('Home');
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
scene.click(SITES.alpha.at);
|
||||
run(scene, LAND_FRAMES);
|
||||
const held = { ...cockpit.orbital.lookView };
|
||||
press('ArrowUp');
|
||||
assert.equal(cockpit.orbital.focus, null);
|
||||
assert.equal(
|
||||
cockpit.orbital.lookTarget.pitchDeg,
|
||||
Math.floor(held.pitchDeg / 5 + 1e-9) * 5 + 5,
|
||||
);
|
||||
});
|
||||
|
||||
test('reduced motion cuts onto the site, back, and between satellites', async (t) => {
|
||||
const scene = await inOrbit(t, { reducedMotion: true });
|
||||
await settle();
|
||||
scene.click(SITES.alpha.at);
|
||||
assert.ok(missDeg(scene.frame(), 'alpha') < 1e-5, 'on it at once');
|
||||
scene.click(EMPTY_GROUND);
|
||||
assert.ok(offNadir(scene.frame()) < 1e-6, 'back at once');
|
||||
satelliteRow(scene, 49260).click();
|
||||
const shot = scene.frame();
|
||||
assert.ok(Cesium.Cartesian3.distance(shot.destination, scene.satellites.position(49260)) < 1);
|
||||
});
|
||||
|
||||
test('stopping the Cockpit hands both clicks back to Cesium', async (t) => {
|
||||
const scene = fixture(t);
|
||||
const click = Cesium.ScreenSpaceEventType.LEFT_CLICK;
|
||||
const double = Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK;
|
||||
assert.notEqual(scene.handler.getInputAction(click), scene.handler.stock);
|
||||
scene.cockpit.stop();
|
||||
assert.equal(scene.handler.getInputAction(click), scene.handler.stock);
|
||||
assert.equal(scene.handler.getInputAction(double), scene.handler.stockDouble);
|
||||
});
|
||||
|
||||
test('the focused site keeps its row after nearer sites push it down', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
siteRow(scene, 'alpha').click();
|
||||
run(scene, LAND_FRAMES);
|
||||
// Eight more sites appear right below the satellite, all nearer to nadir.
|
||||
for (let i = 0; i < 8; i += 1)
|
||||
scene.sites.records.push({
|
||||
id: `osm:military:way/9${i}`,
|
||||
osmKey: `way/9${i}`,
|
||||
name: `Near ${i}`,
|
||||
class: 'base',
|
||||
kind: 'installation',
|
||||
latitude: 30.4 + i * 0.01,
|
||||
longitude: -96.6,
|
||||
memberNames: [],
|
||||
sources: [],
|
||||
});
|
||||
await refreshRows(scene);
|
||||
const sitesShown = rows(scene).filter((row) => row.target?.layerId === 'military-installations');
|
||||
assert.equal(sitesShown.length, 2);
|
||||
assert.equal(sitesShown[0].target.id, SITES.alpha.id, 'the focused site is kept, first');
|
||||
siteRow(scene, 'alpha').click();
|
||||
assert.equal(scene.cockpit.orbital.focus, null, 'its row still ends the focus');
|
||||
});
|
||||
|
||||
test('a site the layer drops in a reload keeps its row, and its row still focuses it', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
await settle();
|
||||
const before = rows(scene).map((row) => row.key);
|
||||
const loaded = scene.sites.records;
|
||||
// The thinned view reloads without Camp Alpha for a moment.
|
||||
scene.sites.records = loaded.filter((r) => r.id !== SITES.alpha.id);
|
||||
await refreshRows(scene);
|
||||
assert.deepEqual(rows(scene).map((row) => row.key), before, 'the rows hold still');
|
||||
siteRow(scene, 'alpha').click();
|
||||
assert.equal(scene.cockpit.orbital.focus?.key, SITES.alpha.id, 'focused from its row');
|
||||
siteRow(scene, 'alpha').click();
|
||||
// Gone for good: after a while it leaves the rows.
|
||||
for (let i = 0; i < 12; i += 1) await refreshRows(scene);
|
||||
assert.ok(!rows(scene).some((row) => row.target?.id === SITES.alpha.id), 'forgotten later');
|
||||
});
|
||||
|
||||
test('shown rows keep their places while they still qualify', async (t) => {
|
||||
const scene = await inOrbit(t);
|
||||
await settle();
|
||||
const sitesBefore = rows(scene)
|
||||
.filter((row) => row.target?.layerId === 'military-installations')
|
||||
.map((row) => row.target.id);
|
||||
// A site appears right below the satellite, nearer to nadir than both.
|
||||
scene.sites.records.push({
|
||||
id: 'osm:military:way/999',
|
||||
osmKey: 'way/999',
|
||||
name: 'Directly Below',
|
||||
class: 'base',
|
||||
kind: 'installation',
|
||||
latitude: 30.01,
|
||||
longitude: -97.01,
|
||||
memberNames: [],
|
||||
sources: [],
|
||||
});
|
||||
await refreshRows(scene);
|
||||
const sitesAfter = rows(scene)
|
||||
.filter((row) => row.target?.layerId === 'military-installations')
|
||||
.map((row) => row.target.id);
|
||||
assert.deepEqual(sitesAfter, sitesBefore, 'no row moves while its site is in reach');
|
||||
// Once a shown site leaves the list, the nearer one takes its slot.
|
||||
scene.sites.records = scene.sites.records.filter((r) => r.id !== SITES.bravo.id);
|
||||
for (let i = 0; i < 12; i += 1) await refreshRows(scene);
|
||||
assert.ok(
|
||||
rows(scene).some((row) => row.target?.id === 'osm:military:way/999'),
|
||||
'the nearer site fills the freed slot',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* The satellites around the one the Cockpit's orbital view rides: the
|
||||
* nearest ones for the Live Signals rows, and riding one of them (or going
|
||||
* back to the one before) from its row. The view stays in orbit: the
|
||||
* satellites layer tracks the
|
||||
* new satellite, the Cockpit takes the camera straight back, any ground
|
||||
* focus ends, and the camera hops along the great circle to the new
|
||||
* satellite. Bound to the Cockpit controller like the orbital view itself.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { t } from '../i18n/index.js';
|
||||
import { zoomTransitionProgress } from '../cockpitOrbital.js';
|
||||
import {
|
||||
ORBITAL_HOP_MS,
|
||||
ORBITAL_SATELLITES_MAX,
|
||||
hopPosition,
|
||||
} from '../cockpitOrbitalSatellites.js';
|
||||
|
||||
/** Whether the user asked for reduced motion: hops then cut. */
|
||||
function prefersReducedMotion() {
|
||||
return Boolean(
|
||||
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches,
|
||||
);
|
||||
}
|
||||
|
||||
function inOrbit(controller) {
|
||||
return (
|
||||
controller.active &&
|
||||
!controller.destroyed &&
|
||||
controller.subjectKind === 'satellite' &&
|
||||
Boolean(controller.orbital)
|
||||
);
|
||||
}
|
||||
|
||||
/** The satellites ridden in this orbital visit, oldest first. */
|
||||
function visits(controller) {
|
||||
const state = controller.orbital;
|
||||
if (!Array.isArray(state.visits)) state.visits = [];
|
||||
const current = controller.subjectId;
|
||||
if (current !== null && current !== undefined && !state.visits.length)
|
||||
state.visits.push(current);
|
||||
return state.visits;
|
||||
}
|
||||
|
||||
/**
|
||||
* The satellites nearest the ridden one, nearest first (debris left out):
|
||||
* the layer's bounded nearest query, measured from the satellite itself
|
||||
* (not the camera, which may still be hopping to it).
|
||||
* @returns {Array<object>} As the layer's `getNearestPositions`.
|
||||
*/
|
||||
export function orbitalNearbySatellites() {
|
||||
const layer = this.services?.satellitesLayer;
|
||||
if (typeof layer?.getNearestPositions !== 'function') return [];
|
||||
try {
|
||||
const from = layer.getCockpitPosition?.();
|
||||
if (!from) return [];
|
||||
return (
|
||||
layer.getNearestPositions(from, ORBITAL_SATELLITES_MAX, {
|
||||
excludeIds: [this.subjectId],
|
||||
excludeClasses: ['debris'],
|
||||
}) || []
|
||||
);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The satellite ridden before this one in this orbital visit, or null.
|
||||
* @returns {number|string|null}
|
||||
*/
|
||||
export function previousOrbitalSatellite() {
|
||||
if (!inOrbit(this)) return null;
|
||||
const ridden = visits(this);
|
||||
return ridden.length > 1 ? ridden[ridden.length - 2] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ride the satellite a Live Signals row names: back to the one ridden before
|
||||
* (its RETURN row), or on to another, remembered so RETURN can come back.
|
||||
* @param {number|string} noradId
|
||||
* @returns {boolean} True when the ridden satellite changed.
|
||||
*/
|
||||
export function rideOrbitalSatellite(noradId) {
|
||||
if (!inOrbit(this)) return false;
|
||||
const ridden = visits(this);
|
||||
const back = ridden.length > 1 ? ridden[ridden.length - 2] : null;
|
||||
if (back !== null && String(back) === String(noradId)) {
|
||||
if (!switchOrbitalSatellite.call(this, back)) {
|
||||
// It left the catalogue: forget it, so RETURN offers the one before.
|
||||
ridden.splice(ridden.length - 2, 1);
|
||||
this.refreshOrbitalSignals?.();
|
||||
return false;
|
||||
}
|
||||
ridden.pop();
|
||||
} else {
|
||||
if (!switchOrbitalSatellite.call(this, noradId)) return false;
|
||||
ridden.push(this.subjectId);
|
||||
}
|
||||
// The RETURN row follows the history just changed.
|
||||
this.refreshOrbitalSignals?.();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ride another satellite without leaving orbit. The satellites layer tracks
|
||||
* it (as a click on its point would); the Cockpit takes the camera back at
|
||||
* once, ends any ground focus with the view back at nadir, and starts the
|
||||
* hop from where the camera is.
|
||||
* @param {number|string} noradId
|
||||
* @returns {boolean} True when the ridden satellite changed.
|
||||
*/
|
||||
export function switchOrbitalSatellite(noradId) {
|
||||
if (!inOrbit(this)) return false;
|
||||
if (String(noradId) === String(this.subjectId)) return false;
|
||||
const layer = this.services?.satellitesLayer;
|
||||
const state = this.orbital;
|
||||
const from = state.focusFrame?.position ?? null;
|
||||
let tracked = false;
|
||||
try {
|
||||
tracked = Boolean(layer?.trackById?.(noradId, { origin: 'user' }));
|
||||
} catch {
|
||||
tracked = false;
|
||||
}
|
||||
// Tracking hands the camera to Cesium's follow; the orbital view keeps it.
|
||||
this.viewer.trackedEntity = undefined;
|
||||
const info = tracked ? this.readSatelliteInfo() : null;
|
||||
if (!info || String(info.noradId) !== String(noradId)) {
|
||||
// Nothing changed hands, or the layer could not take it: the view ends
|
||||
// on the next frame rather than ride something it did not ask for.
|
||||
return false;
|
||||
}
|
||||
layer.setCockpitSubject?.(info.noradId);
|
||||
this.subjectId = info.noradId;
|
||||
state.focus = null;
|
||||
state.focusReleasing = !prefersReducedMotion();
|
||||
state.lookTarget = { yawDeg: 0, pitchDeg: 0 };
|
||||
if (!state.focusReleasing) state.lookView = { yawDeg: 0, pitchDeg: 0 };
|
||||
state.hop =
|
||||
from && !prefersReducedMotion()
|
||||
? { from: { ...from }, startMs: performance.now() }
|
||||
: null;
|
||||
// The rows measure from the camera's frame, still the old satellite's:
|
||||
// until the camera is on the new one, they list no sites or satellites.
|
||||
state.awaitingFrame = true;
|
||||
state.previousUp = null;
|
||||
// The field of view is still the old satellite's until the next frame; the
|
||||
// HUD published below sizes the strip from the settled zoom meanwhile.
|
||||
state.verticalFov = null;
|
||||
state.place = undefined;
|
||||
state.placeTracker?.reset?.();
|
||||
state.prefetched?.clear?.();
|
||||
this.lastHudUpdateMs = 0;
|
||||
this.lastContextUpdateMs = 0;
|
||||
this.dispatchCockpitModeChanged(true, info);
|
||||
// The new satellite's TRACK ACQUIRED replaces the old one, time and all.
|
||||
this.signalItems = this.signalItems.filter((item) => item.key !== 'track');
|
||||
this.signalSignatures.delete('track');
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · NADIR VIEW', { label: info.name }),
|
||||
);
|
||||
this.updateOrbitalHud(info);
|
||||
this.refreshOrbitalSignals?.();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the camera is this frame: on the satellite, or part-way along a hop
|
||||
* to it, eased like a zoom step. The hop ends when it lands.
|
||||
* @param {object} state The orbital session.
|
||||
* @param {Cesium.Cartesian3} position The ridden satellite this frame.
|
||||
* @param {number} nowMs
|
||||
* @returns {Cesium.Cartesian3}
|
||||
*/
|
||||
export function orbitalEyePosition(state, position, nowMs) {
|
||||
const hop = state.hop;
|
||||
if (!hop) return position;
|
||||
const progress = zoomTransitionProgress(nowMs - hop.startMs, {
|
||||
durationMs: ORBITAL_HOP_MS,
|
||||
});
|
||||
if (progress >= 1) {
|
||||
state.hop = null;
|
||||
return position;
|
||||
}
|
||||
const eye = hopPosition(hop.from, position, progress);
|
||||
if (!eye) {
|
||||
state.hop = null;
|
||||
return position;
|
||||
}
|
||||
return new Cesium.Cartesian3(eye.x, eye.y, eye.z);
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/**
|
||||
* The Live Signals rows in the orbital view. Orbit feeds no Contacts
|
||||
* snapshot, so the rows are built here, the way the aircraft rows are built
|
||||
* from one (src/ui/cockpitSignals.js): the TRACK ACQUIRED row, the nearest
|
||||
* mapped sites in reach (a row focuses its site, or releases the one held),
|
||||
* a RETURN row to the satellite ridden before, and the nearest satellites (a
|
||||
* row rides it). With Mapped Installations off a status row says why no
|
||||
* site is listed. Five rows at most, with stable keys, rebuilt on their own
|
||||
* clock. Bound to the Cockpit controller.
|
||||
*/
|
||||
import { formatNumber, t } from '../i18n/index.js';
|
||||
import { ORBITAL_REACH_REFRESH_MS } from '../cockpitOrbitalFocus.js';
|
||||
import { bearingBetweenCoordinates, relativeBearing } from '../cockpitMath.js';
|
||||
import {
|
||||
installationClassLabel,
|
||||
installationTitle,
|
||||
} from '../layers/installations/classLabel.js';
|
||||
import { formatCockpitDistance } from './cockpitPresentation.js';
|
||||
import { orbitalSitesInReach } from './cockpitOrbitalFocus.js';
|
||||
import {
|
||||
orbitalNearbySatellites,
|
||||
previousOrbitalSatellite,
|
||||
} from './cockpitOrbitalSatellites.js';
|
||||
|
||||
/** The most rows Live Signals shows, as for aircraft. */
|
||||
const SIGNAL_ROWS = 5;
|
||||
|
||||
/** Site rows when there are satellites to list too. */
|
||||
const SITE_ROWS = 2;
|
||||
|
||||
const SITES_LAYER_ID = 'military-installations';
|
||||
|
||||
function inOrbit(controller) {
|
||||
return (
|
||||
controller.active &&
|
||||
!controller.destroyed &&
|
||||
controller.subjectKind === 'satellite' &&
|
||||
Boolean(controller.orbital)
|
||||
);
|
||||
}
|
||||
|
||||
function sitesLayerOn(controller) {
|
||||
const isLayerEnabled = controller.services?.isLayerEnabled;
|
||||
return typeof isLayerEnabled === 'function'
|
||||
? isLayerEnabled(SITES_LAYER_ID) !== false
|
||||
: false;
|
||||
}
|
||||
|
||||
/** Where another satellite is, from the top of the frame, worded. */
|
||||
function bearingWords(info, satellite) {
|
||||
const bearing = bearingBetweenCoordinates(
|
||||
info.latitude,
|
||||
info.longitude,
|
||||
satellite.latitude,
|
||||
satellite.longitude,
|
||||
);
|
||||
// Relative to the top of the frame: the ground track, or north.
|
||||
const relative = relativeBearing(
|
||||
bearing,
|
||||
Number.isFinite(info.groundTrackDeg) ? info.groundTrackDeg : 0,
|
||||
);
|
||||
if (relative === null) return t('BRG —');
|
||||
if (Math.abs(relative) < 8) return t('AHEAD');
|
||||
return t('{side} {angle}', {
|
||||
side: relative < 0 ? t('L') : t('R'),
|
||||
angle: `${String(Math.round(Math.abs(relative))).padStart(3, '0')}°`,
|
||||
});
|
||||
}
|
||||
|
||||
/** The ids the rows of one layer show now, in their order. */
|
||||
function shownIds(controller, layerId, keyPrefix) {
|
||||
return controller.signalItems
|
||||
.filter((item) => item.key.startsWith(keyPrefix))
|
||||
.filter((item) => item.target?.layerId === layerId)
|
||||
.map((item) => String(item.target.id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Order rows so those already shown keep their places while they still
|
||||
* qualify; new ones fill after them, nearest first. Sites pass under a low
|
||||
* orbit in seconds: re-sorting by angle every beat would move a row away
|
||||
* from the pointer reaching for it.
|
||||
* @param {Array<object>} entries Nearest first.
|
||||
* @param {(entry: object) => string} keyOf
|
||||
* @param {Array<string>} shown Ids shown now, in order.
|
||||
* @param {string|null} [first] An id that goes first (the focused site).
|
||||
*/
|
||||
function stickyOrder(entries, keyOf, shown, first = null) {
|
||||
const byKey = new Map(entries.map((entry) => [keyOf(entry), entry]));
|
||||
const ordered = [];
|
||||
const take = (key) => {
|
||||
const entry = byKey.get(key);
|
||||
if (!entry) return;
|
||||
ordered.push(entry);
|
||||
byKey.delete(key);
|
||||
};
|
||||
if (first !== null) take(first);
|
||||
for (const key of shown) take(key);
|
||||
for (const entry of entries) take(keyOf(entry));
|
||||
return ordered;
|
||||
}
|
||||
|
||||
/** The site rows: the focused site first, then those shown, then the nearest. */
|
||||
function siteRows(info, { settled = true } = {}) {
|
||||
if (!sitesLayerOn(this)) {
|
||||
// Also forgets the sites last listed, so none is focused from a row.
|
||||
orbitalSitesInReach.call(this, info);
|
||||
return [
|
||||
{
|
||||
key: 'site-status',
|
||||
tone: 'warning',
|
||||
title: t('SITES STANDBY'),
|
||||
detail: t('ENABLE MAPPED INSTALLATIONS FOR SITE PINGS'),
|
||||
target: null,
|
||||
},
|
||||
];
|
||||
}
|
||||
if (!settled) return [];
|
||||
const { entries } = orbitalSitesInReach.call(this, info);
|
||||
const focused = entries.find((entry) => entry.focused);
|
||||
return stickyOrder(
|
||||
entries,
|
||||
(entry) => String(entry.site.id),
|
||||
shownIds(this, SITES_LAYER_ID, 'site:'),
|
||||
focused ? String(focused.site.id) : null,
|
||||
).map(({ site, offNadirDeg, focused }) => {
|
||||
const title = installationTitle(site.name) || t('Unnamed site');
|
||||
const angle = t('OFF-NADIR {angle}°', {
|
||||
angle: formatNumber(offNadirDeg, {
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1,
|
||||
}),
|
||||
});
|
||||
const words = [installationClassLabel(site.class), angle];
|
||||
if (focused) words.unshift(t('FOCUS'));
|
||||
return {
|
||||
key: `site:${site.id}`,
|
||||
// The held site reads as the subject does.
|
||||
tone: focused ? 'track' : 'nearby',
|
||||
title,
|
||||
detail: words.join(' · '),
|
||||
target: {
|
||||
layerId: SITES_LAYER_ID,
|
||||
id: String(site.id),
|
||||
label: focused
|
||||
? t('Release the camera from {name}', { name: title })
|
||||
: t('Keep the camera on {name}', { name: title }),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** The satellite rows: RETURN to the one before, then the nearest. */
|
||||
function satelliteRows(info) {
|
||||
const state = this.orbital;
|
||||
state.satelliteNames ??= new Map();
|
||||
state.satelliteNames.set(String(info.noradId), info.name);
|
||||
const rows = [];
|
||||
const back = previousOrbitalSatellite.call(this);
|
||||
if (back !== null) {
|
||||
const name = state.satelliteNames.get(String(back)) ?? String(back);
|
||||
rows.push({
|
||||
key: `satellite-return:${back}`,
|
||||
tone: 'nearby',
|
||||
title: t('RETURN · {name}', { name }),
|
||||
detail: t('PREVIOUS SATELLITE'),
|
||||
target: {
|
||||
layerId: 'satellites',
|
||||
id: String(back),
|
||||
label: t('Return to {name}', { name }),
|
||||
},
|
||||
});
|
||||
}
|
||||
// Measured only once the camera is on the ridden satellite.
|
||||
const measured = !state.hop && !state.awaitingFrame;
|
||||
const nearby = measured
|
||||
? stickyOrder(
|
||||
orbitalNearbySatellites.call(this),
|
||||
(satellite) => String(satellite.id),
|
||||
shownIds(this, 'satellites', 'satellite:'),
|
||||
)
|
||||
: [];
|
||||
for (const satellite of nearby) {
|
||||
if (back !== null && String(satellite.id) === String(back)) continue;
|
||||
const name = String(satellite.label ?? satellite.id);
|
||||
state.satelliteNames.set(String(satellite.id), name);
|
||||
rows.push({
|
||||
key: `satellite:${satellite.id}`,
|
||||
tone: 'nearby',
|
||||
title: name,
|
||||
detail: [
|
||||
t('SATELLITE'),
|
||||
bearingWords(info, satellite),
|
||||
formatCockpitDistance(satellite.distanceM),
|
||||
].join(' · '),
|
||||
target: {
|
||||
layerId: 'satellites',
|
||||
id: String(satellite.id),
|
||||
label: t('Ride {name}', { name }),
|
||||
},
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the orbital Live Signals rows now: after a focus change, a
|
||||
* satellite switch, or on their clock. TRACK ACQUIRED stays first; sites
|
||||
* take two rows when satellites fill the rest, more when they do not.
|
||||
*/
|
||||
export function refreshOrbitalSignals() {
|
||||
if (!inOrbit(this)) return;
|
||||
const info = this.lastSubjectInfo;
|
||||
if (info?.kind !== 'satellite') return;
|
||||
this.orbital.signalsMs = performance.now();
|
||||
const previous = new Map(this.signalItems.map((item) => [item.key, item]));
|
||||
const rows = [];
|
||||
const track = this.signalItems.find((item) => item.key === 'track');
|
||||
if (track) rows.push(track);
|
||||
// While the camera hops to a new satellite its frame is not the
|
||||
// satellite's yet: the site rows wait for it (the status row does not).
|
||||
const settled = !this.orbital.hop && !this.orbital.awaitingFrame;
|
||||
const sites = siteRows.call(this, info, { settled });
|
||||
const satellites = satelliteRows.call(this, info);
|
||||
const free = SIGNAL_ROWS - rows.length;
|
||||
rows.push(...sites.slice(0, Math.max(SITE_ROWS, free - satellites.length)));
|
||||
rows.push(...satellites.slice(0, SIGNAL_ROWS - rows.length));
|
||||
const now = Date.now();
|
||||
this.signalItems = rows.map((row) => ({
|
||||
...row,
|
||||
timestamp: previous.get(row.key)?.timestamp ?? row.timestamp ?? now,
|
||||
}));
|
||||
this.signalSignatures.clear();
|
||||
this.publishCockpitSignals();
|
||||
}
|
||||
|
||||
/**
|
||||
* The rows' clock: rebuild once every ORBITAL_REACH_REFRESH_MS.
|
||||
* @param {number} nowMs
|
||||
*/
|
||||
export function updateOrbitalSignals(nowMs) {
|
||||
const state = this.orbital;
|
||||
if (!state) return;
|
||||
if (nowMs - (state.signalsMs ?? -Infinity) < ORBITAL_REACH_REFRESH_MS) return;
|
||||
refreshOrbitalSignals.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A click on an orbital row: a site row focuses its site or releases it, a
|
||||
* satellite row rides that satellite (RETURN goes back).
|
||||
* @param {string} layerId
|
||||
* @param {string} id
|
||||
* @returns {boolean} True in orbit, where the row is this module's.
|
||||
*/
|
||||
export function handleOrbitalSignalClick(layerId, id) {
|
||||
if (!inOrbit(this)) return false;
|
||||
if (layerId === SITES_LAYER_ID) this.toggleOrbitalFocus(id);
|
||||
else if (layerId === 'satellites') this.rideOrbitalSatellite(id);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,911 @@
|
||||
/** The orbital (satellite) view of the Cockpit controller: camera, zoom, look and HUD. */
|
||||
import * as Cesium from 'cesium';
|
||||
import { formatNumber, msg, t } from '../i18n/index.js';
|
||||
import {
|
||||
ORBITAL_DEFAULT_ZOOM,
|
||||
ORBITAL_PREFETCH_INTERVAL_MS,
|
||||
centreLinesFirst,
|
||||
ORBITAL_PREFETCH_MAX_TILES,
|
||||
ORBITAL_PREFETCH_MIN_ZOOM,
|
||||
ORBITAL_SETTLE_BLUR_PX,
|
||||
ORBITAL_ZOOM_LADDER,
|
||||
ORBITAL_ZOOM_TRANSITION_MS,
|
||||
cesiumFrustumFovRad,
|
||||
footprintWidthKm,
|
||||
fovForZoom,
|
||||
groundTrackAhead,
|
||||
imageryLevelForView,
|
||||
interpolateZoomFov,
|
||||
nadirOrientation,
|
||||
nextOrbitalZoom,
|
||||
offNadirAngleDeg,
|
||||
offNadirOrientation,
|
||||
offNadirCentreMeetsEarth,
|
||||
offNadirSwathScale,
|
||||
orbitalBaseFovRad,
|
||||
orbitalMaxZoom,
|
||||
previousOrbitalZoom,
|
||||
sensorStripFraction,
|
||||
sensorSwathZoom,
|
||||
tilesForPoints,
|
||||
wheelZoomStep,
|
||||
zoomSettleHolding,
|
||||
zoomTransitionState,
|
||||
} from '../cockpitOrbital.js';
|
||||
import {
|
||||
clampOrbitalLook,
|
||||
lookIsOffset,
|
||||
orbitalLookReadoutParts,
|
||||
stepOrbitalLook,
|
||||
} from '../cockpitLook.js';
|
||||
import { cockpitUiUpdateDue } from '../cockpitMath.js';
|
||||
import { createPlaceTracker, nearPlaceRadiusKm } from '../data/placeBelow.js';
|
||||
import { isPointerFree } from '../data/inputOwnership.js';
|
||||
import { zoomableSwathKm } from '../layers/satellites/sensors.js';
|
||||
import {
|
||||
easeOrbitalLook,
|
||||
orbitalFocusReadout,
|
||||
releaseOrbitalFocus,
|
||||
updateOrbitalFocus,
|
||||
} from './cockpitOrbitalFocus.js';
|
||||
import { orbitalEyePosition } from './cockpitOrbitalSatellites.js';
|
||||
import {
|
||||
COCKPIT_CONTEXT_UPDATE_MS,
|
||||
COCKPIT_HUD_UPDATE_MS,
|
||||
compassPointLabel,
|
||||
formatCockpitCoordinate,
|
||||
} from './cockpitPresentation.js';
|
||||
|
||||
/**
|
||||
* How often the orbital view asks for a regional brief. A low orbit crosses
|
||||
* the briefing's 25 km refresh distance every few seconds, so the sub-satellite
|
||||
* point is briefed on a clock instead.
|
||||
*/
|
||||
export const ORBITAL_BRIEF_REFRESH_MS = 60_000;
|
||||
|
||||
/** Whether the user asked for reduced motion: zoom steps and tilts cut. */
|
||||
function prefersReducedMotion() {
|
||||
return Boolean(
|
||||
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches,
|
||||
);
|
||||
}
|
||||
|
||||
const IDLE_TRANSITION = Object.freeze({
|
||||
active: false,
|
||||
blurPx: 0,
|
||||
lockTick: false,
|
||||
});
|
||||
|
||||
const NADIR_LOOK = Object.freeze({ yawDeg: 0, pitchDeg: 0 });
|
||||
|
||||
/**
|
||||
* Start an orbital session's state. Keeps the camera's own field of view so
|
||||
* the exit can put it back exactly.
|
||||
*/
|
||||
export function beginOrbital() {
|
||||
const frustum = this.viewer.camera?.frustum;
|
||||
const state = {
|
||||
imagery: acquireOrbitImagery(this.services),
|
||||
zoom: ORBITAL_DEFAULT_ZOOM,
|
||||
// Wheel scrolling summed toward the next zoom step (wheelZoomStep).
|
||||
wheel: null,
|
||||
// Imagery pre-loaded ahead of the ground track from 16x: when it last
|
||||
// looked ahead, and the tiles already asked for (oldest first).
|
||||
prefetchMs: -Infinity,
|
||||
prefetched: new Set(),
|
||||
// The provider those tiles came from, and the requests still in flight.
|
||||
prefetchProvider: null,
|
||||
prefetchRequests: new Set(),
|
||||
// A zoom step in flight: the magnification it started from and when.
|
||||
transition: null,
|
||||
previousUp: null,
|
||||
savedFov: Number.isFinite(frustum?.fov) ? frustum.fov : null,
|
||||
altitudeM: null,
|
||||
verticalFov: null,
|
||||
lastBriefMs: 0,
|
||||
lookTarget: { ...NADIR_LOOK },
|
||||
lookView: { ...NADIR_LOOK },
|
||||
lookLastMs: performance.now(),
|
||||
// What the sub-satellite point is over: undefined until the first
|
||||
// lookup lands, then a place or null (nothing named there).
|
||||
place: undefined,
|
||||
placeTracker: null,
|
||||
};
|
||||
state.placeTracker = createPlaceTracker({
|
||||
lookup: this.services.placeBelow,
|
||||
onPlace: (place) => {
|
||||
if (this.orbital !== state) return;
|
||||
state.place = place;
|
||||
if (this.lastSubjectInfo?.kind === 'satellite')
|
||||
publishOrbitalView.call(this, this.lastSubjectInfo);
|
||||
},
|
||||
});
|
||||
this.orbital = state;
|
||||
}
|
||||
|
||||
/** End the orbital session: restore the field of view and clear the HUD. */
|
||||
export function endOrbital() {
|
||||
const state = this.orbital;
|
||||
if (!state) return;
|
||||
this.orbital = null;
|
||||
state.placeTracker?.reset();
|
||||
// Pre-loads still queued or in flight are for a view no longer shown.
|
||||
for (const request of state.prefetchRequests) request.cancel?.();
|
||||
state.prefetchRequests.clear();
|
||||
const frustum = this.viewer.camera?.frustum;
|
||||
if (frustum && state.savedFov !== null) frustum.fov = state.savedFov;
|
||||
// Back to the map the operator had, unless they picked another meanwhile.
|
||||
state.imagery?.release?.()?.catch?.(() => {});
|
||||
this.publishOrbital(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offer the sub-satellite point to the place tracker, with the radius a
|
||||
* populated place may lie in to be named (half the settled view's smaller
|
||||
* ground dimension, from NEAR_PLACE_MIN_ZOOM on), so a zoom step refreshes
|
||||
* the place at once.
|
||||
*/
|
||||
function trackPlace(info, nowMs) {
|
||||
const state = this.orbital;
|
||||
if (!state?.placeTracker) return;
|
||||
let nearKm = null;
|
||||
if (Number.isFinite(info.altitudeM)) {
|
||||
const frustum = this.viewer.camera?.frustum;
|
||||
const aspect = Number.isFinite(frustum?.aspectRatio)
|
||||
? frustum.aspectRatio
|
||||
: canvasAspect(this.viewer);
|
||||
const fov = fovForZoom(orbitalBaseFovRad(info.altitudeM), state.zoom);
|
||||
// The field of view is vertical: aspect 1 gives the ground height.
|
||||
nearKm = nearPlaceRadiusKm(
|
||||
state.zoom,
|
||||
footprintWidthKm(info.altitudeM, fov, aspect),
|
||||
footprintWidthKm(info.altitudeM, fov, 1),
|
||||
);
|
||||
}
|
||||
state.placeTracker.update(info.latitude, info.longitude, nowMs, nearKm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lease the map for flat imagery while in orbit. Another owner already
|
||||
* holding it (an imagery comparison) keeps the map as it is.
|
||||
* @returns {{release: () => Promise<void>}|null}
|
||||
*/
|
||||
function acquireOrbitImagery(services) {
|
||||
try {
|
||||
const lease = services?.acquireOrbitImagery?.() ?? null;
|
||||
lease?.ready?.catch?.(() => {});
|
||||
return lease;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** The magnification the view shows at `nowMs`, mid-step included. */
|
||||
function currentMagnification(state, baseFov, nowMs) {
|
||||
const fov = verticalFovAt(state, baseFov, nowMs).fov;
|
||||
return Math.tan(baseFov / 2) / Math.tan(fov / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* The vertical field of view at `nowMs` and the step's HUD state. Once the
|
||||
* field of view lands, the focus pull holds until the imagery has loaded
|
||||
* (see `zoomSettleHolding`), then the reticle locks. A step that has settled
|
||||
* (lock tick over) is retired.
|
||||
*/
|
||||
function verticalFovAt(state, baseFov, nowMs, tilesLoaded = true) {
|
||||
const target = fovForZoom(baseFov, state.zoom);
|
||||
const step = state.transition;
|
||||
if (!step) return { fov: target, transition: IDLE_TRANSITION, moving: false };
|
||||
const elapsedMs = nowMs - step.startMs;
|
||||
const landedMs = elapsedMs - ORBITAL_ZOOM_TRANSITION_MS;
|
||||
if (landedMs >= 0 && step.heldMs === undefined) {
|
||||
if (zoomSettleHolding(landedMs, tilesLoaded)) {
|
||||
return {
|
||||
fov: target,
|
||||
transition: {
|
||||
active: true,
|
||||
blurPx: ORBITAL_SETTLE_BLUR_PX,
|
||||
lockTick: false,
|
||||
},
|
||||
moving: true,
|
||||
};
|
||||
}
|
||||
step.heldMs = landedMs;
|
||||
}
|
||||
// The lock tick runs from the end of the hold, not the end of the move.
|
||||
const now = zoomTransitionState(elapsedMs - (step.heldMs ?? 0));
|
||||
const fov = interpolateZoomFov(
|
||||
fovForZoom(baseFov, step.fromZoom),
|
||||
target,
|
||||
now.progress,
|
||||
);
|
||||
return {
|
||||
fov,
|
||||
transition: {
|
||||
active: now.active,
|
||||
// Settled steps carry no residue of the blur curve (sin π ≠ 0).
|
||||
blurPx: now.active ? now.blurPx : 0,
|
||||
lockTick: now.lockTick,
|
||||
},
|
||||
moving: now.active || now.lockTick,
|
||||
};
|
||||
}
|
||||
|
||||
/** Apply the field of view for the altitude and time; returns the HUD state. */
|
||||
function applyFov(state, altitudeM, nowMs) {
|
||||
const baseFov = orbitalBaseFovRad(altitudeM);
|
||||
const reading = verticalFovAt(
|
||||
state,
|
||||
baseFov,
|
||||
nowMs,
|
||||
tilesLoaded(this.viewer),
|
||||
);
|
||||
// The step's last frame (its lock tick over) publishes the idle state.
|
||||
if (state.transition && !reading.moving) {
|
||||
state.transition = null;
|
||||
reading.transition = IDLE_TRANSITION;
|
||||
}
|
||||
state.verticalFov = reading.fov;
|
||||
const frustum = this.viewer.camera?.frustum;
|
||||
if (frustum && 'fov' in frustum) {
|
||||
const aspect = Number.isFinite(frustum.aspectRatio)
|
||||
? frustum.aspectRatio
|
||||
: canvasAspect(this.viewer);
|
||||
frustum.fov = cesiumFrustumFovRad(reading.fov, aspect);
|
||||
}
|
||||
return reading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the imagery under the view has loaded. Flat imagery drapes the
|
||||
* globe; with the globe hidden (Google 3D kept) there is nothing to wait for.
|
||||
*/
|
||||
function tilesLoaded(viewer) {
|
||||
const globe = viewer.scene?.globe;
|
||||
return !globe?.show || globe.tilesLoaded !== false;
|
||||
}
|
||||
|
||||
function canvasAspect(viewer) {
|
||||
const canvas = viewer.scene?.canvas;
|
||||
const width = canvas?.clientWidth;
|
||||
const height = canvas?.clientHeight;
|
||||
return width > 0 && height > 0 ? width / height : 1;
|
||||
}
|
||||
|
||||
/** Copy a plain vector into a Cesium scratch. */
|
||||
function intoCartesian(vector, result) {
|
||||
result.x = vector.x;
|
||||
result.y = vector.y;
|
||||
result.z = vector.z;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drive the orbital camera for one rendered frame: at the satellite's own
|
||||
* per-frame position, looking at the Earth's centre with the ground track at
|
||||
* the top (north at the top for a satellite with none), tilted by the
|
||||
* off-nadir look. A low orbit moves ~7.6 km/s, so there is no cadence
|
||||
* gate here; only the HUD and briefing keep theirs.
|
||||
* @param {number} nowMs Frame time.
|
||||
*/
|
||||
export function updateOrbital(nowMs) {
|
||||
// Tracking anything from orbit (an aircraft, another satellite) ends the
|
||||
// view and leaves Cesium tracking with that target.
|
||||
if (this.viewer.trackedEntity?.position) {
|
||||
this.exit({ restoreTracking: false });
|
||||
return;
|
||||
}
|
||||
const info = this.readSatelliteInfo();
|
||||
if (!info || info.noradId !== this.subjectId || !this.orbital) {
|
||||
this.exit({ restoreTracking: false });
|
||||
return;
|
||||
}
|
||||
const position = this.services.satellitesLayer?.getCockpitPosition?.(
|
||||
this.scratchTarget,
|
||||
);
|
||||
if (!position) return;
|
||||
const state = this.orbital;
|
||||
// On the satellite, or on the way to it after Previous/Next.
|
||||
const eye = orbitalEyePosition(state, position, nowMs);
|
||||
// Track-up: the ground track at the top, so the picture scrolls along it.
|
||||
// A geostationary satellite has no track and stays north-up.
|
||||
const nadir = nadirOrientation(eye, {
|
||||
previousUp: state.previousUp,
|
||||
headingDeg: Number.isFinite(info.groundTrackDeg)
|
||||
? info.groundTrackDeg
|
||||
: null,
|
||||
});
|
||||
if (!nadir) return;
|
||||
state.previousUp = nadir.north;
|
||||
state.altitudeM = info.altitudeM;
|
||||
// The top step follows live altitude and the window's shape: when it
|
||||
// falls below the zoom shown, step back to it rather than show finer
|
||||
// ground than the sensor images.
|
||||
const maxZoom = orbitalMaxZoomFor.call(this, info);
|
||||
if (state.zoom > maxZoom) {
|
||||
this.lastSubjectInfo = info;
|
||||
goToZoom.call(this, maxZoom);
|
||||
}
|
||||
// A ground focus aims the look itself (src/ui/cockpitOrbitalFocus.js).
|
||||
if (!updateOrbitalFocus.call(this, state, nadir, eye, nowMs))
|
||||
state.lookView = easeOrbitalLook(
|
||||
state,
|
||||
nowMs - (state.lookLastMs || nowMs),
|
||||
{ immediate: prefersReducedMotion() },
|
||||
);
|
||||
state.lookLastMs = nowMs;
|
||||
const view = offNadirOrientation(nadir, {
|
||||
northDeg: state.lookView.pitchDeg,
|
||||
eastDeg: state.lookView.yawDeg,
|
||||
});
|
||||
const zoomStepping = Boolean(state.transition);
|
||||
const reading = applyFov.call(this, state, info.altitudeM, nowMs);
|
||||
this.viewer.camera.setView({
|
||||
destination: eye,
|
||||
orientation: {
|
||||
direction: intoCartesian(view.direction, this.scratchForward),
|
||||
up: intoCartesian(view.up, this.scratchUp),
|
||||
},
|
||||
});
|
||||
this.lastSubjectInfo = info;
|
||||
if (
|
||||
zoomStepping ||
|
||||
cockpitUiUpdateDue(nowMs, this.lastHudUpdateMs, COCKPIT_HUD_UPDATE_MS)
|
||||
) {
|
||||
this.lastHudUpdateMs = nowMs;
|
||||
trackPlace.call(this, info, nowMs);
|
||||
publishOrbitalView.call(this, info, reading.transition);
|
||||
}
|
||||
if (
|
||||
cockpitUiUpdateDue(
|
||||
nowMs,
|
||||
this.lastContextUpdateMs,
|
||||
COCKPIT_CONTEXT_UPDATE_MS,
|
||||
)
|
||||
) {
|
||||
this.lastContextUpdateMs = nowMs;
|
||||
updateOrbitalContext.call(this, info, nowMs);
|
||||
}
|
||||
prefetchImageryAhead.call(this, info, nowMs);
|
||||
}
|
||||
|
||||
/** Tiles remembered as asked for in one orbital session. */
|
||||
const PREFETCH_MEMORY = 512;
|
||||
|
||||
/** How far the shown time may be from now for the look-ahead to run, ms. */
|
||||
const PREFETCH_LIVE_TOLERANCE_MS = 60_000;
|
||||
|
||||
/**
|
||||
* From 16x the view is 10 to 40 km wide while the ground track moves about
|
||||
* 7 km/s, so the imagery under it arrives late. Every
|
||||
* ORBITAL_PREFETCH_INTERVAL_MS ask the globe's base imagery for the tiles
|
||||
* the view will need 5 to 20 s ahead (`groundTrackAhead`), at the level
|
||||
* Cesium will draw there (`imageryLevelForView`), so the browser has them
|
||||
* cached when the view gets there. The requests are throttled at the
|
||||
* lowest priority: Cesium's request scheduler declines one while the
|
||||
* imagery server's slots are taken by the tiles on screen or the scheduler
|
||||
* is full, and a declined tile is asked again on a later look-ahead. At most
|
||||
* ORBITAL_PREFETCH_MAX_TILES a time; the last PREFETCH_MEMORY tiles asked
|
||||
* for are not asked again unless their request failed, and a new base map
|
||||
* starts the memory over. Exit cancels the requests still pending. Nothing
|
||||
* below 16x, while the view is tilted off nadir (it no longer looks at the
|
||||
* track), with the world clock away from now (paused, played back), after
|
||||
* the exit, or with the globe hidden (Google 3D tiles drawn instead).
|
||||
* @returns {number} The tiles asked for.
|
||||
*/
|
||||
export function prefetchImageryAhead(info, nowMs) {
|
||||
const state = this.orbital;
|
||||
if (!state || !(state.zoom >= ORBITAL_PREFETCH_MIN_ZOOM)) return 0;
|
||||
// Tilted, the view looks off the track the pre-load follows.
|
||||
if (lookIsOffset(state.lookTarget, 0) || lookIsOffset(state.lookView, 0))
|
||||
return 0;
|
||||
if (nowMs - state.prefetchMs < ORBITAL_PREFETCH_INTERVAL_MS) return 0;
|
||||
// The look-ahead runs at live speed: with the world clock paused, played
|
||||
// back or moved, the view will not pass where it points.
|
||||
if (
|
||||
Number.isFinite(info.atMs) &&
|
||||
Math.abs(info.atMs - Date.now()) > PREFETCH_LIVE_TOLERANCE_MS
|
||||
)
|
||||
return 0;
|
||||
state.prefetchMs = nowMs;
|
||||
try {
|
||||
const globe = this.viewer.scene?.globe;
|
||||
if (!globe || globe.show === false) return 0;
|
||||
const provider = baseImageryProvider(this.viewer);
|
||||
if (!provider) return 0;
|
||||
// Another base map: its tiles have not been asked for.
|
||||
// A fresh set, so a late failure from the old map's requests cannot
|
||||
// drop a tile the new one has fetched.
|
||||
if (provider !== state.prefetchProvider) {
|
||||
for (const request of state.prefetchRequests) request.cancel?.();
|
||||
state.prefetchRequests = new Set();
|
||||
state.prefetched = new Set();
|
||||
state.prefetchProvider = provider;
|
||||
}
|
||||
const fov = fovForZoom(orbitalBaseFovRad(info.altitudeM), state.zoom);
|
||||
const viewKm = footprintWidthKm(
|
||||
info.altitudeM,
|
||||
fov,
|
||||
viewAspect(this.viewer),
|
||||
);
|
||||
// The ground one CSS pixel covers at the nadir point, as Cesium's
|
||||
// screen-space error measures it: the vertical field of view over the
|
||||
// canvas height, at the satellite's altitude.
|
||||
const canvas = this.viewer.scene?.canvas;
|
||||
const heightPx = canvas?.clientHeight || canvas?.height;
|
||||
const terrain =
|
||||
this.viewer.terrainProvider ?? this.viewer.scene?.globe?.terrainProvider;
|
||||
const level = imageryLevelForView(provider.tilingScheme, {
|
||||
metresPerPixel: (info.altitudeM * 2 * Math.tan(fov / 2)) / heightPx,
|
||||
latitudeDeg: info.latitude,
|
||||
geographic:
|
||||
provider.tilingScheme.projection instanceof Cesium.GeographicProjection,
|
||||
tileWidthPx: provider.tileWidth,
|
||||
minimumLevel: provider.minimumLevel,
|
||||
maximumLevel: provider.maximumLevel,
|
||||
maximumScreenSpaceError: globe.maximumScreenSpaceError,
|
||||
terrainLevelErrorM:
|
||||
typeof terrain?.getLevelMaximumGeometricError === 'function'
|
||||
? (terrainLevel) =>
|
||||
terrain.getLevelMaximumGeometricError(terrainLevel)
|
||||
: undefined,
|
||||
});
|
||||
if (level === null) return 0;
|
||||
const memory = state.prefetched;
|
||||
const tiles = tilesForPoints(
|
||||
provider.tilingScheme,
|
||||
centreLinesFirst(groundTrackAhead(info, viewKm)),
|
||||
level,
|
||||
{
|
||||
maxTiles: ORBITAL_PREFETCH_MAX_TILES,
|
||||
skip: (key) => memory.has(key),
|
||||
},
|
||||
);
|
||||
let asked = 0;
|
||||
for (const tile of tiles) {
|
||||
let pending;
|
||||
let request;
|
||||
try {
|
||||
// The tiles on screen keep their slots: Cesium's scheduler declines
|
||||
// this request while the imagery server's slots are taken (shared
|
||||
// with the globe's own tile requests, throttleByServer) or the
|
||||
// scheduler is full, and at the lowest priority it is the first
|
||||
// dropped from the priority heap, never one the screen asked for.
|
||||
pending = provider.requestImage(
|
||||
tile.x,
|
||||
tile.y,
|
||||
tile.level,
|
||||
(request = new Cesium.Request({
|
||||
throttle: true,
|
||||
throttleByServer: true,
|
||||
priority: Number.MAX_VALUE,
|
||||
type: Cesium.RequestType.IMAGERY,
|
||||
})),
|
||||
);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
// A provider that declines now (throttled) is asked again later.
|
||||
if (!pending) continue;
|
||||
const requests = state.prefetchRequests;
|
||||
requests.add(request);
|
||||
Promise.resolve(pending).then(
|
||||
() => requests.delete(request),
|
||||
(error) => {
|
||||
requests.delete(request);
|
||||
// Dropped by the scheduler (rejected with no error): asked again
|
||||
// later. A tile that failed to load stays remembered, so one
|
||||
// missing from the map is not asked for every look-ahead.
|
||||
if (error === undefined) memory.delete(tile.key);
|
||||
},
|
||||
);
|
||||
memory.add(tile.key);
|
||||
if (memory.size > PREFETCH_MEMORY)
|
||||
memory.delete(memory.values().next().value);
|
||||
asked += 1;
|
||||
}
|
||||
return asked;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The provider of the lowest shown imagery layer, the base map the globe
|
||||
* drapes, when it can be asked for a tile; else null.
|
||||
*/
|
||||
function baseImageryProvider(viewer) {
|
||||
const layers = viewer.imageryLayers ?? viewer.scene?.imageryLayers;
|
||||
const count = Number.isInteger(layers?.length) ? layers.length : 0;
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
const layer = layers.get(i);
|
||||
if (!layer || layer.show === false || layer.alpha === 0) continue;
|
||||
const provider = layer.imageryProvider;
|
||||
if (
|
||||
typeof provider?.requestImage === 'function' &&
|
||||
typeof provider.tilingScheme?.positionToTileXY === 'function'
|
||||
)
|
||||
return provider;
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Brief the sub-satellite point: the local page every context beat, the
|
||||
* regional brief on its own slower clock.
|
||||
*/
|
||||
function updateOrbitalContext(info, nowMs, force = false) {
|
||||
this.updateLocalPosition(info);
|
||||
const state = this.orbital;
|
||||
if (
|
||||
state &&
|
||||
(force || nowMs - state.lastBriefMs >= ORBITAL_BRIEF_REFRESH_MS)
|
||||
) {
|
||||
state.lastBriefMs = nowMs;
|
||||
this.maybeRefreshRegionalBrief(info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A track-up view tilts along and across the ground track, not toward the
|
||||
* compass: the look's north/east axes are the frame's top and right.
|
||||
*/
|
||||
const TRACK_LOOK_LABELS = Object.freeze({
|
||||
N: msg('FWD'),
|
||||
S: msg('AFT'),
|
||||
E: msg('RIGHT'),
|
||||
W: msg('LEFT'),
|
||||
});
|
||||
|
||||
function lookDirectionLabel(code, trackUp) {
|
||||
return trackUp ? t(TRACK_LOOK_LABELS[code]) : compassPointLabel(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Word the off-nadir look with its total angle from nadir first, or '' at
|
||||
* nadir: `OFF-NADIR 18.0° · FWD 15° · RIGHT 10°`.
|
||||
*/
|
||||
function wordOffNadir(look, { trackUp = false } = {}) {
|
||||
const parts = orbitalLookReadoutParts(look);
|
||||
const words = [];
|
||||
if (parts.northSouth)
|
||||
words.push(
|
||||
t('{direction} {angle}°', {
|
||||
direction: lookDirectionLabel(parts.northSouth, trackUp),
|
||||
angle: formatNumber(parts.northSouthDeg),
|
||||
}),
|
||||
);
|
||||
if (parts.eastWest)
|
||||
words.push(
|
||||
t('{direction} {angle}°', {
|
||||
direction: lookDirectionLabel(parts.eastWest, trackUp),
|
||||
angle: formatNumber(parts.eastWestDeg),
|
||||
}),
|
||||
);
|
||||
if (!words.length) return '';
|
||||
return t('OFF-NADIR {angle}° · {offset}', {
|
||||
angle: formatNumber(offNadirAngleDeg(lookTilt(parts)), {
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1,
|
||||
}),
|
||||
offset: words.join(' · '),
|
||||
});
|
||||
}
|
||||
|
||||
/** The look's tilt as worded: whole degrees, signed north and east. */
|
||||
function lookTilt(parts) {
|
||||
return {
|
||||
northDeg: (parts.northSouth === 'S' ? -1 : 1) * parts.northSouthDeg,
|
||||
eastDeg: (parts.eastWest === 'W' ? -1 : 1) * parts.eastWestDeg,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Word a ground focus's off-nadir angle, as image metadata gives it:
|
||||
* `OFF-NADIR 23.4°`.
|
||||
*/
|
||||
function wordFocusOffNadir(focus) {
|
||||
return t('OFF-NADIR {angle}°', {
|
||||
angle: formatNumber(focus.offNadirDeg, {
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the orbital HUD. The swath is the nadir footprint, so it is left
|
||||
* out while the view is tilted off nadir. A ground focus reads the single
|
||||
* off-nadir angle to its target and scales the swath by the tilt onto it.
|
||||
* @param {object} info Satellite subject (`readSatelliteInfo`).
|
||||
* @param {{active: boolean, blurPx: number, lockTick: boolean}} transition
|
||||
*/
|
||||
export function publishOrbitalView(info, transition = IDLE_TRANSITION) {
|
||||
const state = this.orbital;
|
||||
if (!state || !info) return;
|
||||
const focus = orbitalFocusReadout.call(this);
|
||||
const offset = Boolean(focus) || lookIsOffset(state.lookTarget, 0);
|
||||
const aspect = Number.isFinite(this.viewer.camera?.frustum?.aspectRatio)
|
||||
? this.viewer.camera.frustum.aspectRatio
|
||||
: canvasAspect(this.viewer);
|
||||
const settledFov = fovForZoom(orbitalBaseFovRad(info.altitudeM), state.zoom);
|
||||
const footprintKm = footprintWidthKm(info.altitudeM, settledFov, aspect);
|
||||
// The strip is drawn over the picture, so it follows the view as a step
|
||||
// zooms (republished every frame then), not the step it is heading for.
|
||||
const shownKm = Number.isFinite(state.verticalFov)
|
||||
? footprintWidthKm(info.altitudeM, state.verticalFov, aspect)
|
||||
: footprintKm;
|
||||
const maxZoom = orbitalMaxZoomFor.call(this, info);
|
||||
const swathKm = sensorSwathKm(info);
|
||||
const trackUp = Number.isFinite(info.groundTrackDeg);
|
||||
// A ground focus sets the tilt; otherwise the look target does.
|
||||
const tilt = focus
|
||||
? { northDeg: focus.pitchDeg, eastDeg: focus.yawDeg }
|
||||
: offset
|
||||
? lookTilt(orbitalLookReadoutParts(state.lookTarget))
|
||||
: null;
|
||||
const swathScale = tilt ? offNadirSwathScale(tilt) : 1;
|
||||
// Tilted past the limb, the view's centre looks into space: no swath. The
|
||||
// camera eases toward the target, so both must meet the Earth; the HUD
|
||||
// republishes on its cadence, so the swath appears once the view arrives.
|
||||
// Exact angles here, not the whole degrees the readout rounds to; a ground
|
||||
// focus aims the look itself, so its angles are the target.
|
||||
const target = focus
|
||||
? { pitchDeg: focus.pitchDeg, yawDeg: focus.yawDeg }
|
||||
: clampOrbitalLook(state.lookTarget);
|
||||
// The eased view is tested even with the target at nadir: on the way back
|
||||
// from past the limb it still looks into space.
|
||||
const seesEarth =
|
||||
(!offset ||
|
||||
offNadirCentreMeetsEarth(info.altitudeM, {
|
||||
northDeg: target.pitchDeg,
|
||||
eastDeg: target.yawDeg,
|
||||
})) &&
|
||||
offNadirCentreMeetsEarth(info.altitudeM, {
|
||||
northDeg: state.lookView?.pitchDeg ?? 0,
|
||||
eastDeg: state.lookView?.yawDeg ?? 0,
|
||||
});
|
||||
this.publishOrbital({
|
||||
name: info.name,
|
||||
classLabel: info.classLabel || '',
|
||||
altitudeM: info.altitudeM,
|
||||
velocityMps: Number.isFinite(info.velocityMps) ? info.velocityMps : null,
|
||||
latitude: info.latitude,
|
||||
longitude: info.longitude,
|
||||
zoom: state.zoom,
|
||||
zoomSteps: ORBITAL_ZOOM_LADDER.filter((step) => step <= maxZoom),
|
||||
maxZoom,
|
||||
footprintKm: offset ? null : footprintKm,
|
||||
// The imaging sensor's swath, drawn to scale; null without one. The
|
||||
// SENSOR step's zoom is null when the swath lies outside 1x..maxZoom.
|
||||
// Looking past the limb there is no ground for it to cover: no sensor.
|
||||
sensor:
|
||||
swathKm === null || !seesEarth
|
||||
? null
|
||||
: {
|
||||
label: info.sensor?.label ?? null,
|
||||
swathKm,
|
||||
// Off nadir the view and the swath widen alike: the strip
|
||||
// keeps its share of the frame. No strip where it would
|
||||
// mislead: a geostationary view has no ground track to run
|
||||
// along, and a SAR images to one side of nadir, not under it.
|
||||
stripFraction:
|
||||
trackUp && info.sensor?.type !== 'SAR'
|
||||
? sensorStripFraction(swathKm, shownKm)
|
||||
: null,
|
||||
zoom: sensorSwathZoom(info.altitudeM, swathKm, aspect, maxZoom),
|
||||
},
|
||||
transition: { ...transition },
|
||||
look: {
|
||||
offset,
|
||||
readout: focus
|
||||
? wordFocusOffNadir(focus)
|
||||
: offset
|
||||
? wordOffNadir(state.lookTarget, { trackUp })
|
||||
: '',
|
||||
// The mapped point the view is held on, or null.
|
||||
focus: focus ? { key: focus.key, label: focus.label } : null,
|
||||
// Off nadir, the ground width at the view's centre, approximated from
|
||||
// the nadir footprint (`offNadirSwathScale`); 1 and null at nadir.
|
||||
swathScale,
|
||||
swathKm:
|
||||
offset && seesEarth && Number.isFinite(footprintKm)
|
||||
? footprintKm * swathScale
|
||||
: null,
|
||||
},
|
||||
// Track-up turns the frame to the ground track; north then sits at
|
||||
// `northDeg` clockwise from the top. A geostationary view stays north-up.
|
||||
trackUp,
|
||||
northDeg: trackUp ? (360 - info.groundTrackDeg) % 360 : 0,
|
||||
place: state.place,
|
||||
noradId: info.noradId ?? null,
|
||||
cosparId: info.cosparId ?? null,
|
||||
tle: info.tle ?? null,
|
||||
// Read on the HUD's cadence, so the age stays current without a timer.
|
||||
// The gap between the TLE's epoch and the time the satellite is shown
|
||||
// at (the world clock's), either side: SGP4 drifts both ways.
|
||||
tleAgeMs: Number.isFinite(info.tle?.epochMs)
|
||||
? Math.abs(
|
||||
(Number.isFinite(info.atMs) ? info.atMs : Date.now()) -
|
||||
info.tle.epochMs,
|
||||
)
|
||||
: null,
|
||||
owner: info.owner ?? null,
|
||||
operator: info.operator ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the orbital view on entry and after a language switch: the HUD,
|
||||
* the local page and a regional brief for the sub-satellite point.
|
||||
* @param {object} info Satellite subject.
|
||||
*/
|
||||
export function updateOrbitalHud(info, nowMs = performance.now()) {
|
||||
this.lastSubjectInfo = info;
|
||||
// A satellite has no flight plan and no Contact card.
|
||||
this.routeView.visible = false;
|
||||
this.clearPredictiveRoute();
|
||||
this.showContextCard(false);
|
||||
trackPlace.call(this, info, nowMs);
|
||||
publishOrbitalView.call(this, info);
|
||||
updateOrbitalContext.call(this, info, nowMs, true);
|
||||
}
|
||||
|
||||
/** Re-apply the field of view and publish after a zoom or look change. */
|
||||
function presentNow() {
|
||||
const state = this.orbital;
|
||||
const info = this.lastSubjectInfo;
|
||||
if (!state || info?.kind !== 'satellite') return;
|
||||
const nowMs = performance.now();
|
||||
const reading = Number.isFinite(state.altitudeM ?? info.altitudeM)
|
||||
? applyFov.call(this, state, state.altitudeM ?? info.altitudeM, nowMs)
|
||||
: null;
|
||||
publishOrbitalView.call(this, info, reading?.transition ?? IDLE_TRANSITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step the optical zoom one step in (`direction` > 0) or out. The step
|
||||
* animates over ORBITAL_ZOOM_TRANSITION_MS with a focus-pull blur and a
|
||||
* lock tick, or cuts at once under reduced motion. The ends stay put.
|
||||
* @param {number} direction Positive to zoom in, negative to zoom out.
|
||||
* @returns {boolean} True when the zoom changed.
|
||||
*/
|
||||
export function stepOrbitalZoom(direction) {
|
||||
if (!this.active || this.subjectKind !== 'satellite' || !this.orbital)
|
||||
return false;
|
||||
const state = this.orbital;
|
||||
const next =
|
||||
direction > 0
|
||||
? nextOrbitalZoom(
|
||||
state.zoom,
|
||||
orbitalMaxZoomFor.call(this, this.lastSubjectInfo),
|
||||
)
|
||||
: previousOrbitalZoom(state.zoom);
|
||||
return goToZoom.call(this, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jump to the zoom at which the view is exactly as wide as the imaging
|
||||
* sensor's swath (the SENSOR step), when that zoom is in range.
|
||||
* @returns {boolean} True when the zoom changed.
|
||||
*/
|
||||
export function jumpToSensorSwath() {
|
||||
if (!this.active || this.subjectKind !== 'satellite' || !this.orbital)
|
||||
return false;
|
||||
const info = this.lastSubjectInfo;
|
||||
const swathKm = sensorSwathKm(info);
|
||||
if (swathKm === null || !Number.isFinite(info?.altitudeM)) return false;
|
||||
const zoom = sensorSwathZoom(
|
||||
info.altitudeM,
|
||||
swathKm,
|
||||
viewAspect(this.viewer),
|
||||
orbitalMaxZoomFor.call(this, info),
|
||||
);
|
||||
return zoom === null ? false : goToZoom.call(this, zoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step the zoom with the mouse wheel over the picture: one step per notch,
|
||||
* trackpad scrolling summed to a step (`wheelZoomStep`). Only in orbit, and
|
||||
* never while a tool owns the pointer.
|
||||
* @param {WheelEvent} event
|
||||
* @returns {boolean} True when the zoom changed.
|
||||
*/
|
||||
export function onOrbitalWheel(event) {
|
||||
if (!this.active || this.subjectKind !== 'satellite' || !this.orbital)
|
||||
return false;
|
||||
if (!isPointerFree()) return false;
|
||||
const state = this.orbital;
|
||||
const { accumulator, step } = wheelZoomStep(
|
||||
state.wheel,
|
||||
event,
|
||||
performance.now(),
|
||||
);
|
||||
state.wheel = accumulator;
|
||||
if (!step) return false;
|
||||
const changed = stepOrbitalZoom.call(this, step);
|
||||
if (changed) event.preventDefault?.();
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** The sensor swath the view draws and the SENSOR step targets, km, or null. */
|
||||
function sensorSwathKm(info) {
|
||||
const swathKm = info?.sensor?.narrowestSwathKm;
|
||||
return Number.isFinite(swathKm) && swathKm > 0 ? swathKm : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The satellite's tightest zoom step at its live altitude. Only a swath
|
||||
* confirmed on a cited page opens steps past 8x.
|
||||
*/
|
||||
function orbitalMaxZoomFor(info) {
|
||||
return orbitalMaxZoom(
|
||||
info?.altitudeM,
|
||||
zoomableSwathKm(info?.sensor),
|
||||
viewAspect(this.viewer),
|
||||
);
|
||||
}
|
||||
|
||||
function viewAspect(viewer) {
|
||||
return Number.isFinite(viewer.camera?.frustum?.aspectRatio)
|
||||
? viewer.camera.frustum.aspectRatio
|
||||
: canvasAspect(viewer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the zoom to `next`, animated from the magnification shown now unless
|
||||
* reduced motion is on.
|
||||
* @returns {boolean} True when the zoom changed.
|
||||
*/
|
||||
function goToZoom(next) {
|
||||
const state = this.orbital;
|
||||
if (!Number.isFinite(next) || next === state.zoom) return false;
|
||||
const nowMs = performance.now();
|
||||
const altitudeM = state.altitudeM ?? this.lastSubjectInfo?.altitudeM;
|
||||
const fromZoom = Number.isFinite(altitudeM)
|
||||
? currentMagnification(state, orbitalBaseFovRad(altitudeM), nowMs)
|
||||
: state.zoom;
|
||||
state.zoom = next;
|
||||
state.transition = prefersReducedMotion()
|
||||
? null
|
||||
: { fromZoom, startMs: nowMs };
|
||||
presentNow.call(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tilt the orbital view one arrow step off nadir (see `lookKeyStep`); each
|
||||
* axis stops at ±45°. The view eases there unless reduced motion is on.
|
||||
* @param {{axis: 'yaw'|'pitch', sign: number, stepDeg: number}} step
|
||||
* @returns {boolean} True in an orbital view.
|
||||
*/
|
||||
export function turnOrbitalLook(step) {
|
||||
if (!this.active || this.subjectKind !== 'satellite' || !this.orbital)
|
||||
return false;
|
||||
if (!step) return false;
|
||||
const state = this.orbital;
|
||||
// An arrow takes the view over from a ground focus where it is.
|
||||
releaseOrbitalFocus.call(this, { handOver: true });
|
||||
state.lookTarget = stepOrbitalLook(state.lookTarget, step);
|
||||
if (prefersReducedMotion()) state.lookView = { ...state.lookTarget };
|
||||
presentNow.call(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the orbital view back to pure nadir (Home, 0 or the NADIR button).
|
||||
* @param {{immediate?: boolean}} [options] Jump instead of easing.
|
||||
* @returns {boolean} True in an orbital view.
|
||||
*/
|
||||
export function resetOrbitalLook({ immediate = false } = {}) {
|
||||
if (!this.active || this.subjectKind !== 'satellite' || !this.orbital)
|
||||
return false;
|
||||
const state = this.orbital;
|
||||
// Ends a ground focus too, easing back on its clock.
|
||||
releaseOrbitalFocus.call(this);
|
||||
state.lookTarget = { ...NADIR_LOOK };
|
||||
if (immediate || prefersReducedMotion()) state.lookView = { ...NADIR_LOOK };
|
||||
presentNow.call(this);
|
||||
return true;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -146,18 +146,46 @@ export function formatCockpitWindDirection(value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cockpit entry for each subject it can ride: an aircraft's cockpit or a
|
||||
* vessel's bridge. Both entry buttons (Contacts and
|
||||
* A TLE epoch as compact UTC, `2026-11-04 08:12Z`, or '' when unknown.
|
||||
* @param {number|null|undefined} epochMs
|
||||
*/
|
||||
export function formatTleEpochUtc(epochMs) {
|
||||
// Beyond ±8.64e15 ms a Date is invalid and toISOString throws.
|
||||
if (!Number.isFinite(epochMs) || Math.abs(epochMs) > 8.64e15) return '';
|
||||
const iso = new Date(epochMs).toISOString();
|
||||
return `${iso.slice(0, 10)} ${iso.slice(11, 16)}Z`;
|
||||
}
|
||||
|
||||
/**
|
||||
* How old a TLE is, in the identifier line's compact units: under an hour,
|
||||
* whole hours under a day, then whole days. A TLE's propagation error grows
|
||||
* with its age, so the age is shown beside the epoch.
|
||||
* @param {number|null|undefined} ageMs Now minus the TLE epoch.
|
||||
* @returns {{unit: 'under-hour'}|{unit: 'hours'|'days', value: number}|null}
|
||||
* Null without a usable age.
|
||||
*/
|
||||
export function tleAgeParts(ageMs) {
|
||||
if (!Number.isFinite(ageMs)) return null;
|
||||
const hours = Math.max(0, ageMs) / 3_600_000;
|
||||
if (hours < 1) return { unit: 'under-hour' };
|
||||
if (hours < 24) return { unit: 'hours', value: Math.floor(hours) };
|
||||
return { unit: 'days', value: Math.floor(hours / 24) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cockpit entry for each subject it can ride: an aircraft's cockpit, a
|
||||
* vessel's bridge or a satellite's orbit. Both entry buttons (Contacts and
|
||||
* the Intel HUD readout) show it.
|
||||
*/
|
||||
const COCKPIT_ENTRY_FACES = Object.freeze({
|
||||
aircraft: Object.freeze({ icon: 'flight', label: msg('COCKPIT') }),
|
||||
vessel: Object.freeze({ icon: 'directions_boat', label: msg('BRIDGE') }),
|
||||
satellite: Object.freeze({ icon: 'satellite_alt', label: msg('ORBIT') }),
|
||||
});
|
||||
|
||||
/**
|
||||
* The entry's glyph and localized label for the subject it would ride.
|
||||
* @param {'aircraft'|'vessel'|null|undefined} kind
|
||||
* @param {'aircraft'|'vessel'|'satellite'|null|undefined} kind
|
||||
* @returns {{icon: string, label: string}}
|
||||
*/
|
||||
export function cockpitEntryFace(kind) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import {
|
||||
formatCockpitDistance,
|
||||
formatCockpitWindDirection,
|
||||
tleAgeParts,
|
||||
} from './cockpitPresentation.js';
|
||||
|
||||
test('wind just west of north reads 0°, not 360°', () => {
|
||||
@@ -16,3 +17,18 @@ test('a cockpit distance that rounds to 10.0 km drops the decimal', () => {
|
||||
assert.match(formatCockpitDistance(9949), /^9\.9\s?KM$/);
|
||||
assert.match(formatCockpitDistance(9960), /^10\s?KM$/);
|
||||
});
|
||||
|
||||
test('a TLE age reads under an hour, then whole hours, then whole days', () => {
|
||||
const HOUR = 3_600_000;
|
||||
assert.deepEqual(tleAgeParts(0), { unit: 'under-hour' });
|
||||
assert.deepEqual(tleAgeParts(59 * 60_000), { unit: 'under-hour' });
|
||||
assert.deepEqual(tleAgeParts(HOUR), { unit: 'hours', value: 1 });
|
||||
assert.deepEqual(tleAgeParts(13.9 * HOUR), { unit: 'hours', value: 13 });
|
||||
assert.deepEqual(tleAgeParts(24 * HOUR - 1), { unit: 'hours', value: 23 });
|
||||
assert.deepEqual(tleAgeParts(24 * HOUR), { unit: 'days', value: 1 });
|
||||
assert.deepEqual(tleAgeParts(50 * HOUR), { unit: 'days', value: 2 });
|
||||
// A clock a little behind the epoch is still fresh, not negative.
|
||||
assert.deepEqual(tleAgeParts(-5 * 60_000), { unit: 'under-hour' });
|
||||
assert.equal(tleAgeParts(null), null);
|
||||
assert.equal(tleAgeParts(Number.NaN), null);
|
||||
});
|
||||
@@ -28,7 +28,10 @@ export function publishCockpitSignals() {
|
||||
target: item.target && {
|
||||
layerId: item.target.layerId,
|
||||
id: item.target.id,
|
||||
label: t('Select flight {title}', { title: item.title }),
|
||||
// Orbit's site and satellite rows name their own action.
|
||||
label:
|
||||
item.target.label ??
|
||||
t('Select flight {title}', { title: item.title }),
|
||||
},
|
||||
};
|
||||
}),
|
||||
@@ -212,6 +215,14 @@ export function handleSignalClick(event) {
|
||||
);
|
||||
if (!target) return;
|
||||
event.preventDefault();
|
||||
// In orbit the rows are sites and satellites (cockpitOrbitalSignals.js).
|
||||
if (
|
||||
this.handleOrbitalSignalClick?.(
|
||||
target.dataset.signalLayer,
|
||||
target.dataset.signalId,
|
||||
)
|
||||
)
|
||||
return;
|
||||
this.services.militaryAwarenessLayer.focusTarget?.(
|
||||
target.dataset.signalLayer,
|
||||
target.dataset.signalId,
|
||||
|
||||
@@ -28,15 +28,22 @@ export function readVesselInfo() {
|
||||
return this.services.aisLiveVesselsLayer?.getCockpitSubject?.() || null;
|
||||
}
|
||||
|
||||
/** The tracked satellite the orbital view would ride, or rides; null without one. */
|
||||
export function readSatelliteInfo() {
|
||||
return this.services.satellitesLayer?.getCockpitSubject?.() || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The layer the active view rides: Live AIS Vessels on a bridge, else the
|
||||
* aircraft's own layer. It is read from the tracked entity's id once the
|
||||
* layer has dropped its tracking, so a layer turned off still names itself.
|
||||
* @returns {'flights'|'military'|'ais-live-vessels'|null}
|
||||
* The layer the active view rides: Live AIS Vessels on a bridge, Satellites
|
||||
* in orbit, else the aircraft's own layer. It is read from the tracked
|
||||
* entity's id once the layer has dropped its tracking, so a layer turned off
|
||||
* still names itself.
|
||||
* @returns {'flights'|'military'|'ais-live-vessels'|'satellites'|null}
|
||||
*/
|
||||
export function readSubjectLayerId() {
|
||||
if (!this.active) return null;
|
||||
if (this.subjectKind === 'vessel') return 'ais-live-vessels';
|
||||
if (this.subjectKind === 'satellite') return 'satellites';
|
||||
const layerId = this.readAircraftInfo()?.layerId;
|
||||
if (layerId) return layerId;
|
||||
const [prefix] = String(this.trackedEntity?.gevTrackedId || '').split(':');
|
||||
@@ -44,26 +51,29 @@ export function readSubjectLayerId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The subject entry would take: a Cesium-tracked aircraft first, else the
|
||||
* selected vessel. Vessels never take Cesium tracking, so an aircraft and a
|
||||
* vessel cannot be live through the same owner.
|
||||
* @returns {'aircraft'|'vessel'|null}
|
||||
* The subject entry would take: a Cesium-tracked aircraft first, then the
|
||||
* tracked satellite, else the selected vessel. Vessels never take Cesium
|
||||
* tracking, so an aircraft and a vessel cannot be live through the same owner.
|
||||
* @returns {'aircraft'|'satellite'|'vessel'|null}
|
||||
*/
|
||||
export function resolveEntryKind() {
|
||||
if (this.readAircraftInfo() && this.viewer.trackedEntity?.position)
|
||||
return 'aircraft';
|
||||
if (this.readSatelliteInfo()) return 'satellite';
|
||||
return this.readVesselInfo() ? 'vessel' : null;
|
||||
}
|
||||
|
||||
export function dispatchCockpitModeChanged(active, info = null) {
|
||||
const subjectId = active
|
||||
? String(info?.icao24 || info?.mmsi || '')
|
||||
? String(info?.icao24 || info?.mmsi || info?.noradId || '')
|
||||
.trim()
|
||||
.toLowerCase() || null
|
||||
: null;
|
||||
const layerId =
|
||||
active &&
|
||||
['flights', 'military', 'ais-live-vessels'].includes(info?.layerId)
|
||||
['flights', 'military', 'ais-live-vessels', 'satellites'].includes(
|
||||
info?.layerId,
|
||||
)
|
||||
? info.layerId
|
||||
: null;
|
||||
window.dispatchEvent(
|
||||
@@ -118,9 +128,13 @@ export function syncEntry() {
|
||||
const info = this.readAircraftInfo();
|
||||
const trackedContact = !!(info && this.viewer.trackedEntity?.position);
|
||||
this.syncTr3bToggle(trackedContact ? info : null);
|
||||
const bridgeContact = !trackedContact && !!this.readVesselInfo();
|
||||
const orbitContact = !trackedContact && !!this.readSatelliteInfo();
|
||||
const bridgeContact =
|
||||
!trackedContact && !orbitContact && !!this.readVesselInfo();
|
||||
let entryKind = null;
|
||||
if (trackedContact) entryKind = this.isEntryAllowed() ? 'aircraft' : null;
|
||||
else if (orbitContact)
|
||||
entryKind = this.isOrbitEntryAllowed() ? 'satellite' : null;
|
||||
else if (bridgeContact)
|
||||
entryKind = this.isBridgeEntryAllowed() ? 'vessel' : null;
|
||||
const available = entryKind !== null;
|
||||
@@ -139,8 +153,10 @@ export function syncEntry() {
|
||||
|
||||
export function navigateContext(direction, options = {}) {
|
||||
if (this.destroyed) return false;
|
||||
// Contact navigation moves between aircraft; a bridge does not jump ship.
|
||||
if (this.subjectKind === 'vessel') return false;
|
||||
// Contact navigation moves between aircraft; a bridge does not jump ship
|
||||
// and an orbital view stays with its satellite.
|
||||
if (this.subjectKind === 'vessel' || this.subjectKind === 'satellite')
|
||||
return false;
|
||||
const method = direction < 0 ? 'navigatePrevious' : 'navigateNext';
|
||||
const wasActive = this.active;
|
||||
if (wasActive) this.contextNavigationDeadlineMs = performance.now() + 1500;
|
||||
@@ -159,9 +175,10 @@ export function navigateContext(direction, options = {}) {
|
||||
}
|
||||
|
||||
export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
// An aircraft tracked from the bridge ends it (see the vessel camera
|
||||
// update); it is never adopted as the bridge's subject.
|
||||
if (this.subjectKind === 'vessel') return false;
|
||||
// An aircraft tracked from the bridge or from orbit ends that view (see the
|
||||
// vessel and orbital camera updates); it is never adopted as its subject.
|
||||
if (this.subjectKind === 'vessel' || this.subjectKind === 'satellite')
|
||||
return false;
|
||||
const nextEntity = this.viewer.trackedEntity;
|
||||
if (
|
||||
!this.active ||
|
||||
@@ -192,8 +209,8 @@ export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
|
||||
/**
|
||||
* Enter first person on a tracked aircraft or, with none tracked, the
|
||||
* selected vessel's bridge.
|
||||
* @param {{kind?: 'aircraft'|'vessel'|null}} [options] Restrict
|
||||
* tracked satellite's orbital view or the selected vessel's bridge.
|
||||
* @param {{kind?: 'aircraft'|'satellite'|'vessel'|null}} [options] Restrict
|
||||
* entry to one subject kind; voice entry is aircraft-only.
|
||||
* @returns {boolean} True when the view was entered.
|
||||
*/
|
||||
@@ -202,12 +219,21 @@ export function enter({ kind = null } = {}) {
|
||||
if (this.active) return false;
|
||||
const subjectKind = kind ?? this.resolveEntryKind() ?? 'aircraft';
|
||||
const vessel = subjectKind === 'vessel';
|
||||
const allowed = vessel ? this.isBridgeEntryAllowed() : this.isEntryAllowed();
|
||||
const satellite = subjectKind === 'satellite';
|
||||
const allowed = vessel
|
||||
? this.isBridgeEntryAllowed()
|
||||
: satellite
|
||||
? this.isOrbitEntryAllowed()
|
||||
: this.isEntryAllowed();
|
||||
if (!allowed) return false;
|
||||
const info = vessel ? this.readVesselInfo() : this.readAircraftInfo();
|
||||
const info = vessel
|
||||
? this.readVesselInfo()
|
||||
: satellite
|
||||
? this.readSatelliteInfo()
|
||||
: this.readAircraftInfo();
|
||||
// Only an aircraft is ridden through its Cesium entity.
|
||||
const entity = vessel ? null : this.viewer.trackedEntity;
|
||||
if (!info || (!vessel && !entity?.position)) return false;
|
||||
const entity = vessel || satellite ? null : this.viewer.trackedEntity;
|
||||
if (!info || (!vessel && !satellite && !entity?.position)) return false;
|
||||
this.entryFocusOrigin =
|
||||
document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
@@ -219,11 +245,15 @@ export function enter({ kind = null } = {}) {
|
||||
// Each session reads its own water: never a height left from the last.
|
||||
this.vesselWaterline = null;
|
||||
this.vesselFix = null;
|
||||
this.subjectId = vessel ? info.mmsi : null;
|
||||
this.subjectId = vessel ? info.mmsi : satellite ? info.noradId : null;
|
||||
this.trackedEntity = entity;
|
||||
if (entity) {
|
||||
this.trackedEntityWasShown = entity.show;
|
||||
entity.show = false;
|
||||
} else if (satellite) {
|
||||
// The layer hides the satellite's own marks and dims the other orbits.
|
||||
this.services.satellitesLayer?.setCockpitSubject?.(info.noradId);
|
||||
this.beginOrbital();
|
||||
} else {
|
||||
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(info.mmsi);
|
||||
}
|
||||
@@ -259,6 +289,7 @@ export function enter({ kind = null } = {}) {
|
||||
document.body.classList.add('cockpit-mode');
|
||||
// Bridge styling reaches surfaces outside the HUD (exit row, side panels).
|
||||
if (vessel) document.body.classList.add('cockpit-bridge');
|
||||
if (satellite) document.body.classList.add('cockpit-orbit');
|
||||
// Activation hides the entry and TR-3B chip; clearing the chip's signature
|
||||
// lets the exit-path syncEntry publish it again.
|
||||
this._tr3bSignature = null;
|
||||
@@ -277,7 +308,14 @@ export function enter({ kind = null } = {}) {
|
||||
this.showBriefPage(0);
|
||||
this.startBriefRotation();
|
||||
const trackHeading = formatHeadingReadout(info.track ?? 0);
|
||||
if (vessel) {
|
||||
if (satellite) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · NADIR VIEW', { label: info.name }),
|
||||
);
|
||||
} else if (vessel) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
@@ -310,7 +348,9 @@ export function enter({ kind = null } = {}) {
|
||||
);
|
||||
}
|
||||
this.updateHud(info, performance.now(), true);
|
||||
this.setVisionMode(this.getInitialVisionMode());
|
||||
// Orbit always opens in the plain optical picture; the vision styles stay
|
||||
// one click away.
|
||||
this.setVisionMode(satellite ? 'optical' : this.getInitialVisionMode());
|
||||
this.scheduleContextLayout();
|
||||
// The exit button shows when Vue flushes the presence; focus it after.
|
||||
Promise.resolve().then(() => {
|
||||
@@ -327,6 +367,8 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
if (!this.active) return false;
|
||||
const entity = this.trackedEntity;
|
||||
const vesselSubject = this.subjectKind === 'vessel' ? this.subjectId : null;
|
||||
const satelliteSubject =
|
||||
this.subjectKind === 'satellite' ? this.subjectId : null;
|
||||
this.active = false;
|
||||
this.subjectKind = null;
|
||||
this.vesselWaterline = null;
|
||||
@@ -348,7 +390,13 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
this.regionalBriefAbort = null;
|
||||
this.regionalBriefRequestToken += 1;
|
||||
this.regionalBriefSubjectId = null;
|
||||
document.body.classList.remove('cockpit-mode', 'cockpit-bridge');
|
||||
document.body.classList.remove(
|
||||
'cockpit-mode',
|
||||
'cockpit-bridge',
|
||||
'cockpit-orbit',
|
||||
);
|
||||
// The camera's own field of view returns before any follow resumes.
|
||||
this.endOrbital();
|
||||
this.onExited?.();
|
||||
this.publishUtilityLayout(null);
|
||||
this.presence.active = false;
|
||||
@@ -364,6 +412,8 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
this.trackedEntityWasShown = true;
|
||||
if (vesselSubject)
|
||||
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(null);
|
||||
if (satelliteSubject !== null)
|
||||
this.services.satellitesLayer?.setCockpitSubject?.(null);
|
||||
this.dispatchCockpitModeChanged(false);
|
||||
if (restoreTracking && entity && this.viewer.entities.contains(entity)) {
|
||||
this.viewer.trackedEntity = entity;
|
||||
@@ -371,6 +421,9 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
} else if (restoreTracking && vesselSubject) {
|
||||
// Back to the selected vessel's map view, through the layer's own focus.
|
||||
this.services.aisLiveVesselsLayer?.focusSelectedVessel?.();
|
||||
} else if (restoreTracking && satelliteSubject !== null) {
|
||||
// Back to the satellite's follow camera, through the layer's own refocus.
|
||||
this.services.satellitesLayer?.refocusTrackedById?.(satelliteSubject);
|
||||
}
|
||||
this.syncEntry();
|
||||
// Back to whichever entry was used: the Contacts button or the readout's.
|
||||
|
||||
+10
-3
@@ -61,12 +61,19 @@ export const PANEL_LABEL_KEYS = Object.freeze({
|
||||
'local-firms': msg('Active Fires'),
|
||||
});
|
||||
|
||||
/** What the loading status names for a load that is not a layer's. */
|
||||
export const LOADING_NAME_KEYS = Object.freeze({
|
||||
'place-names': msg('Place names'),
|
||||
});
|
||||
|
||||
// Looked up by the English text, so a surface that holds `layer.name` keeps
|
||||
// its English data and only the shown text translates.
|
||||
const MODULE_NAME_KEYS = new Map(
|
||||
[...Object.values(LAYER_NAME_KEYS), ...Object.values(PANEL_LABEL_KEYS)].map(
|
||||
(key) => [key, key],
|
||||
),
|
||||
[
|
||||
...Object.values(LAYER_NAME_KEYS),
|
||||
...Object.values(PANEL_LABEL_KEYS),
|
||||
...Object.values(LOADING_NAME_KEYS),
|
||||
].map((key) => [key, key]),
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,14 +11,17 @@ import {
|
||||
} from './layerNames.js';
|
||||
export { localizeLayerName } from './layerNames.js';
|
||||
import { createWeatherPanel } from './weatherPanel.js';
|
||||
import { translateFeedError, translateStatusLine } from './statusText.js';
|
||||
import {
|
||||
translateFeedError,
|
||||
translateStatusLine,
|
||||
translateStatusMessage,
|
||||
} from './statusText.js';
|
||||
import {
|
||||
formatNumber,
|
||||
getLocale,
|
||||
msg,
|
||||
onLocaleChange,
|
||||
t,
|
||||
translateKnown,
|
||||
} from '../i18n/index.js';
|
||||
|
||||
// Feed-state values are machine ids (QA hooks, CSS feed-* classes); only the
|
||||
@@ -695,7 +698,7 @@ export class LayerPanel {
|
||||
typeof stats.statusMessage === 'string' &&
|
||||
stats.statusMessage.trim()
|
||||
) {
|
||||
return `${source} · ${translateKnown(stats.statusMessage.trim())}`;
|
||||
return `${source} · ${translateStatusMessage(stats.statusMessage.trim())}`;
|
||||
}
|
||||
const ago = stats.lastUpdate ? this._timeAgo(stats.lastUpdate) : t('never');
|
||||
if (stats.loading) {
|
||||
|
||||
@@ -452,3 +452,57 @@ test('without the Utilities list, Directions stays in Data Layers under Utilitie
|
||||
restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('a layer with no feed in view says why instead of "never"', async () => {
|
||||
const { LayerPanel, presentLayerCount, presentLayerToggle } =
|
||||
await import('./layerPanel.js');
|
||||
const { setLocale } = await import('../i18n/index.js');
|
||||
const panel = LayerPanel.prototype;
|
||||
const rows = [
|
||||
{
|
||||
id: 'transit',
|
||||
name: 'Transit',
|
||||
source: 'GTFS-RT',
|
||||
enabled: true,
|
||||
stats: {
|
||||
count: 0,
|
||||
lastUpdate: null,
|
||||
source: 'GTFS-RT',
|
||||
status: 'zoom-in',
|
||||
statusMessage: 'No feed here yet · 16 regions available',
|
||||
},
|
||||
meta: 'GTFS-RT · No feed here yet · 16 regions available',
|
||||
},
|
||||
{
|
||||
id: 'bikeshare',
|
||||
name: 'Bikeshare',
|
||||
source: 'GBFS',
|
||||
enabled: true,
|
||||
stats: {
|
||||
count: 0,
|
||||
lastUpdate: null,
|
||||
loading: false,
|
||||
status: 'zoom-in',
|
||||
statusMessage: 'Fly below 48 km to a covered city',
|
||||
},
|
||||
meta: 'GBFS · Fly below 48 km to a covered city',
|
||||
},
|
||||
];
|
||||
for (const layer of rows) {
|
||||
// Guidance is normal operation: the layer is on and nothing has failed.
|
||||
assert.equal(presentLayerToggle(layer).text, 'ON');
|
||||
assert.equal(presentLayerCount(layer.stats).empty, true);
|
||||
assert.equal(panel._buildMetaText(layer), layer.meta);
|
||||
}
|
||||
|
||||
setLocale('ru');
|
||||
try {
|
||||
for (const layer of rows) {
|
||||
const meta = panel._buildMetaText(layer);
|
||||
assert.doesNotMatch(meta, /never|Fly below|No feed|covered/, meta);
|
||||
assert.match(meta, /^(GTFS-RT|GBFS) · /, meta);
|
||||
}
|
||||
} finally {
|
||||
setLocale('en');
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* The owner mark beside a satellite's name: the owner country's flag, or a
|
||||
* short text badge for an organisation without one (ESA, EUMETSAT,
|
||||
* "Multinational"). Windows draws no flag emoji, so the flags are pictures:
|
||||
* one sheet of every owner country's flag (`scripts/build-owner-flags.mjs`,
|
||||
* from flag-icons), loaded once at startup (`preloadOwnerFlags`), so riding
|
||||
* a satellite never waits for its flag.
|
||||
*/
|
||||
|
||||
import { OWNER_FLAG_SHEET } from './ownerFlagSheet.js';
|
||||
|
||||
/** The flag sheet's URL. */
|
||||
export const OWNER_FLAG_SHEET_URL = new URL(
|
||||
'../data/local_data/owner_flags/owner_flags.png',
|
||||
import.meta.url,
|
||||
).href;
|
||||
|
||||
/** Each flag's place on the sheet, by ISO code. */
|
||||
const SHEET_INDEX = new Map(
|
||||
OWNER_FLAG_SHEET.codes.map((code, index) => [code, index]),
|
||||
);
|
||||
|
||||
let sheetLoad = null;
|
||||
|
||||
/**
|
||||
* Load the flag sheet, once; the app calls this at startup. A failed load
|
||||
* is asked again by the next caller, so a flag shown later can still come.
|
||||
* @param {{createImage?: () => {onload: Function|null, onerror: Function|null,
|
||||
* src: string}}} [options] Test seam.
|
||||
* @returns {Promise<boolean>} Whether the sheet is ready to draw from.
|
||||
*/
|
||||
export function preloadOwnerFlags({
|
||||
createImage = () => new globalThis.Image(),
|
||||
} = {}) {
|
||||
if (sheetLoad) return sheetLoad;
|
||||
let image;
|
||||
try {
|
||||
image = createImage();
|
||||
} catch {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
const load = new Promise((resolve) => {
|
||||
image.onload = () => resolve(true);
|
||||
image.onerror = () => {
|
||||
if (sheetLoad === load) sheetLoad = null;
|
||||
resolve(false);
|
||||
};
|
||||
});
|
||||
sheetLoad = load;
|
||||
image.src = OWNER_FLAG_SHEET_URL;
|
||||
return load;
|
||||
}
|
||||
|
||||
/**
|
||||
* How to draw a flag from the sheet at a size: the sheet as the element's
|
||||
* background, scaled and shifted onto the flag's cell.
|
||||
* @param {string} code ISO 3166-1 alpha-2, upper case.
|
||||
* @param {{widthPx?: number, heightPx?: number}} [size] CSS pixels.
|
||||
* @returns {{backgroundImage: string, backgroundSize: string,
|
||||
* backgroundPosition: string}|null} Null for a code not on the sheet.
|
||||
*/
|
||||
export function ownerFlagStyle(code, { widthPx = 20, heightPx = 15 } = {}) {
|
||||
const index = SHEET_INDEX.get(code);
|
||||
if (index === undefined) return null;
|
||||
const sheet = OWNER_FLAG_SHEET;
|
||||
const column = index % sheet.columns;
|
||||
const row = Math.floor(index / sheet.columns);
|
||||
// A cell and its gutter, in CSS pixels at this size.
|
||||
const pitchX =
|
||||
(widthPx * (sheet.cellWidthPx + sheet.gutterPx)) / sheet.cellWidthPx;
|
||||
const pitchY =
|
||||
(heightPx * (sheet.cellHeightPx + sheet.gutterPx)) / sheet.cellHeightPx;
|
||||
return {
|
||||
backgroundImage: `url("${OWNER_FLAG_SHEET_URL}")`,
|
||||
backgroundSize: `${sheet.columns * pitchX}px ${sheet.rows * pitchY}px`,
|
||||
backgroundPosition: `${-column * pitchX}px ${-row * pitchY}px`,
|
||||
};
|
||||
}
|
||||
|
||||
/** An ISO 3166-1 alpha-2 code, upper case, or null. */
|
||||
function isoCode(value) {
|
||||
const code = String(value ?? '').trim();
|
||||
return /^[A-Za-z]{2}$/.test(code) ? code.toUpperCase() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A region's name in the locale, from the browser's own table.
|
||||
* @param {string} code ISO 3166-1 alpha-2.
|
||||
* @param {string} locale BCP 47 tag.
|
||||
* @returns {string|null}
|
||||
*/
|
||||
export function regionName(code, locale) {
|
||||
try {
|
||||
const name = new Intl.DisplayNames([locale || 'en'], {
|
||||
type: 'region',
|
||||
}).of(code);
|
||||
return name && name !== code ? name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How to mark a satellite's owner.
|
||||
* @param {{countryCode: string|null, label: string|null}|null|undefined} owner
|
||||
* @param {{locale?: string, flags?: {has: (code: string) => boolean}}}
|
||||
* [options] `flags`: the codes with a flag (the sheet's).
|
||||
* @returns {{kind: 'flag', code: string, label: string}
|
||||
* | {kind: 'badge', label: string, title: string}
|
||||
* | null} A flag (with the country's localized name as its label), a text
|
||||
* badge for an owner with no flag to show, or nothing when unknown.
|
||||
*/
|
||||
export function ownerMark(owner, { locale = 'en', flags = SHEET_INDEX } = {}) {
|
||||
const code = isoCode(owner?.countryCode);
|
||||
const label = String(owner?.label ?? '').trim();
|
||||
if (code) {
|
||||
const name = regionName(code, locale) || label || code;
|
||||
if (flags.has(code)) return { kind: 'flag', code, label: name };
|
||||
return { kind: 'badge', label: label || code, title: name };
|
||||
}
|
||||
return label ? { kind: 'badge', label, title: label } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the readout shows for an owner once the flag sheet has loaded or
|
||||
* failed: the flag, or a badge (the country code when the sheet would not
|
||||
* load, so the owner never disappears), or nothing for an unknown owner.
|
||||
* @param {ReturnType<typeof ownerMark>} mark
|
||||
* @param {{ready?: boolean, failed?: boolean}} [sheet] The sheet's state.
|
||||
* @returns {{kind: 'flag', style: object, label: string}
|
||||
* | {kind: 'badge', label: string, title: string} | null}
|
||||
*/
|
||||
export function shownOwnerMark(mark, { ready = false, failed = false } = {}) {
|
||||
if (!mark) return null;
|
||||
if (mark.kind === 'badge') return mark;
|
||||
const style = ownerFlagStyle(mark.code);
|
||||
if (failed || !style) {
|
||||
return { kind: 'badge', label: mark.code.toUpperCase(), title: mark.label };
|
||||
}
|
||||
return ready ? { kind: 'flag', style, label: mark.label } : null;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
// src/ui/ownerFlag.test.mjs — a satellite owner's mark: a country's flag with
|
||||
// its localized name, drawn from the owner flag sheet; a text badge for an
|
||||
// organisation; nothing when unknown.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { OWNER_COUNTRY_CODES } from '../layers/satellites/classes.js';
|
||||
import { OWNER_FLAG_SHEET } from './ownerFlagSheet.js';
|
||||
import {
|
||||
OWNER_FLAG_SHEET_URL,
|
||||
ownerFlagStyle,
|
||||
ownerMark,
|
||||
preloadOwnerFlags,
|
||||
regionName,
|
||||
shownOwnerMark,
|
||||
} from './ownerFlag.js';
|
||||
|
||||
test('an owner country shows its flag, named in the reader language', () => {
|
||||
assert.deepEqual(ownerMark({ countryCode: 'us', label: 'USA' }), {
|
||||
kind: 'flag',
|
||||
code: 'US',
|
||||
label: 'United States',
|
||||
});
|
||||
assert.equal(
|
||||
ownerMark({ countryCode: 'FR', label: null }, { locale: 'de' }).label,
|
||||
'Frankreich',
|
||||
);
|
||||
});
|
||||
|
||||
test('an organisation without a country shows a text badge', () => {
|
||||
assert.deepEqual(ownerMark({ countryCode: null, label: 'ESA' }), {
|
||||
kind: 'badge',
|
||||
label: 'ESA',
|
||||
title: 'ESA',
|
||||
});
|
||||
});
|
||||
|
||||
test('a country with no flag on the sheet falls back to a badge', () => {
|
||||
assert.deepEqual(
|
||||
ownerMark(
|
||||
{ countryCode: 'DE', label: 'Germany' },
|
||||
{ flags: new Set(['US']) },
|
||||
),
|
||||
{ kind: 'badge', label: 'Germany', title: 'Germany' },
|
||||
);
|
||||
// Natural Earth and UCS write -99 or names, never a flag code.
|
||||
assert.deepEqual(ownerMark({ countryCode: '-99', label: 'Multinational' }), {
|
||||
kind: 'badge',
|
||||
label: 'Multinational',
|
||||
title: 'Multinational',
|
||||
});
|
||||
});
|
||||
|
||||
test('an unknown owner shows nothing', () => {
|
||||
assert.equal(ownerMark(null), null);
|
||||
assert.equal(ownerMark({ countryCode: null, label: ' ' }), null);
|
||||
});
|
||||
|
||||
test('a region name comes from Intl, never the bare code', () => {
|
||||
assert.equal(regionName('JP', 'en'), 'Japan');
|
||||
assert.equal(regionName('XX', 'en'), null);
|
||||
});
|
||||
|
||||
test('the sheet holds every owner country a satellite can be marked with', () => {
|
||||
assert.deepEqual([...OWNER_FLAG_SHEET.codes], [...OWNER_COUNTRY_CODES]);
|
||||
assert.equal(
|
||||
OWNER_FLAG_SHEET.rows,
|
||||
Math.ceil(OWNER_FLAG_SHEET.codes.length / OWNER_FLAG_SHEET.columns),
|
||||
);
|
||||
// The PNG is as large as its layout says (width and height at bytes 16-23).
|
||||
const png = readFileSync(new URL(OWNER_FLAG_SHEET_URL));
|
||||
const { cellWidthPx, cellHeightPx, gutterPx } = OWNER_FLAG_SHEET;
|
||||
assert.equal(
|
||||
png.readUInt32BE(16),
|
||||
OWNER_FLAG_SHEET.columns * (cellWidthPx + gutterPx),
|
||||
);
|
||||
assert.equal(
|
||||
png.readUInt32BE(20),
|
||||
OWNER_FLAG_SHEET.rows * (cellHeightPx + gutterPx),
|
||||
);
|
||||
});
|
||||
|
||||
test('a flag is drawn from its cell of the sheet, at the size asked', () => {
|
||||
// 40 × 30 sheet cells with a 2 px gutter, drawn at 20 × 15: each cell and
|
||||
// its gutter is 21 × 16 CSS pixels.
|
||||
assert.equal(OWNER_FLAG_SHEET.cellWidthPx, 40);
|
||||
assert.equal(OWNER_FLAG_SHEET.cellHeightPx, 30);
|
||||
assert.equal(OWNER_FLAG_SHEET.gutterPx, 2);
|
||||
const columns = OWNER_FLAG_SHEET.columns;
|
||||
const index = OWNER_FLAG_SHEET.codes.indexOf('US');
|
||||
const style = ownerFlagStyle('US');
|
||||
assert.equal(style.backgroundImage, `url("${OWNER_FLAG_SHEET_URL}")`);
|
||||
assert.equal(
|
||||
style.backgroundSize,
|
||||
`${columns * 21}px ${OWNER_FLAG_SHEET.rows * 16}px`,
|
||||
);
|
||||
assert.equal(
|
||||
style.backgroundPosition,
|
||||
`${-(index % columns) * 21}px ${-Math.floor(index / columns) * 16}px`,
|
||||
);
|
||||
// The first flag sits at the corner.
|
||||
assert.equal(
|
||||
ownerFlagStyle(OWNER_FLAG_SHEET.codes[0]).backgroundPosition,
|
||||
'0px 0px',
|
||||
);
|
||||
assert.equal(ownerFlagStyle('XX'), null);
|
||||
});
|
||||
|
||||
test('the flag shows once the sheet is ready; a failed sheet shows the code', () => {
|
||||
const flag = { kind: 'flag', code: 'US', label: 'United States' };
|
||||
assert.equal(shownOwnerMark(flag), null, 'nothing while it loads');
|
||||
assert.deepEqual(shownOwnerMark(flag, { ready: true }), {
|
||||
kind: 'flag',
|
||||
style: ownerFlagStyle('US'),
|
||||
label: 'United States',
|
||||
});
|
||||
assert.deepEqual(shownOwnerMark(flag, { failed: true }), {
|
||||
kind: 'badge',
|
||||
label: 'US',
|
||||
title: 'United States',
|
||||
});
|
||||
const badge = { kind: 'badge', label: 'ESA', title: 'ESA' };
|
||||
assert.equal(shownOwnerMark(badge, { failed: true }), badge);
|
||||
assert.equal(shownOwnerMark(null), null);
|
||||
});
|
||||
|
||||
test('the sheet loads once; a failed load is asked again', async () => {
|
||||
const images = [];
|
||||
const createImage = () => {
|
||||
const image = { onload: null, onerror: null, src: '' };
|
||||
images.push(image);
|
||||
return image;
|
||||
};
|
||||
const first = preloadOwnerFlags({ createImage });
|
||||
assert.equal(images.length, 1);
|
||||
assert.equal(images[0].src, OWNER_FLAG_SHEET_URL);
|
||||
assert.equal(preloadOwnerFlags({ createImage }), first, 'one load at a time');
|
||||
images[0].onerror();
|
||||
assert.equal(await first, false);
|
||||
const second = preloadOwnerFlags({ createImage });
|
||||
assert.equal(images.length, 2, 'asked again after a failure');
|
||||
images[1].onload();
|
||||
assert.equal(await second, true);
|
||||
assert.equal(preloadOwnerFlags({ createImage }), second, 'kept once loaded');
|
||||
assert.equal(images.length, 2);
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
// Generated by scripts/build-owner-flags.mjs from flag-icons 7.5.0; do not edit.
|
||||
/** The owner flag sheet's layout: flag i at column i % columns, row i / columns. */
|
||||
export const OWNER_FLAG_SHEET = Object.freeze({
|
||||
cellWidthPx: 40,
|
||||
cellHeightPx: 30,
|
||||
gutterPx: 2,
|
||||
columns: 16,
|
||||
rows: 7,
|
||||
codes: Object.freeze([
|
||||
'AE',
|
||||
'AM',
|
||||
'AO',
|
||||
'AR',
|
||||
'AT',
|
||||
'AU',
|
||||
'AZ',
|
||||
'BD',
|
||||
'BE',
|
||||
'BG',
|
||||
'BH',
|
||||
'BM',
|
||||
'BO',
|
||||
'BR',
|
||||
'BT',
|
||||
'BW',
|
||||
'BY',
|
||||
'CA',
|
||||
'CH',
|
||||
'CL',
|
||||
'CN',
|
||||
'CO',
|
||||
'CR',
|
||||
'CZ',
|
||||
'DE',
|
||||
'DJ',
|
||||
'DK',
|
||||
'DZ',
|
||||
'EC',
|
||||
'EE',
|
||||
'EG',
|
||||
'ES',
|
||||
'ET',
|
||||
'FI',
|
||||
'FR',
|
||||
'GB',
|
||||
'GH',
|
||||
'GR',
|
||||
'GT',
|
||||
'HR',
|
||||
'HU',
|
||||
'ID',
|
||||
'IE',
|
||||
'IL',
|
||||
'IN',
|
||||
'IQ',
|
||||
'IR',
|
||||
'IT',
|
||||
'JO',
|
||||
'JP',
|
||||
'KE',
|
||||
'KP',
|
||||
'KR',
|
||||
'KW',
|
||||
'KZ',
|
||||
'LA',
|
||||
'LK',
|
||||
'LT',
|
||||
'LU',
|
||||
'MA',
|
||||
'MC',
|
||||
'MD',
|
||||
'ME',
|
||||
'MM',
|
||||
'MN',
|
||||
'MU',
|
||||
'MX',
|
||||
'MY',
|
||||
'NG',
|
||||
'NL',
|
||||
'NO',
|
||||
'NP',
|
||||
'NZ',
|
||||
'PE',
|
||||
'PH',
|
||||
'PK',
|
||||
'PL',
|
||||
'PT',
|
||||
'PY',
|
||||
'QA',
|
||||
'RO',
|
||||
'RU',
|
||||
'RW',
|
||||
'SA',
|
||||
'SB',
|
||||
'SD',
|
||||
'SE',
|
||||
'SG',
|
||||
'SI',
|
||||
'SN',
|
||||
'TH',
|
||||
'TM',
|
||||
'TN',
|
||||
'TR',
|
||||
'TW',
|
||||
'UA',
|
||||
'US',
|
||||
'UY',
|
||||
'VA',
|
||||
'VE',
|
||||
'VN',
|
||||
'ZA',
|
||||
'ZW',
|
||||
]),
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* The place packs in the top-centre loading status: they load lazily, on the
|
||||
* Cockpit's first place lookup (`src/data/placeBelow.js`), so while one is on
|
||||
* its way the status names them beside the layers, and a pack that would not
|
||||
* load makes the batch end LOAD FAILED.
|
||||
*/
|
||||
|
||||
import { placePacksStatus } from '../data/placeBelow.js';
|
||||
import { LOADING_NAME_KEYS } from './layerNames.js';
|
||||
|
||||
/**
|
||||
* The data layers, with the place packs as one more entry while they load
|
||||
* or after one would not load, so a batch they join ends LOAD FAILED rather
|
||||
* than LOAD COMPLETE.
|
||||
*/
|
||||
export function withPlacePacks(
|
||||
layers,
|
||||
{ loading, failed } = placePacksStatus(),
|
||||
) {
|
||||
if (!loading && !failed) return layers;
|
||||
return [
|
||||
...layers,
|
||||
{
|
||||
id: 'place-names',
|
||||
name: LOADING_NAME_KEYS['place-names'],
|
||||
enabled: true,
|
||||
stats: { loading, error: failed ? 'Place names did not load' : null },
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// src/ui/placePacksLoading.test.mjs — the loading status names the place
|
||||
// packs while they load, and a failed pack ends the batch as failed.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
aggregateLayerLoading,
|
||||
createLoadingFeedbackState,
|
||||
reduceLoadingFeedback,
|
||||
} from '../loadingFeedback.js';
|
||||
import { withPlacePacks } from './placePacksLoading.js';
|
||||
|
||||
const SATELLITES = Object.freeze({
|
||||
id: 'satellites',
|
||||
name: 'Satellites',
|
||||
enabled: true,
|
||||
stats: { count: 9000, lastUpdate: 1 },
|
||||
});
|
||||
|
||||
function batch(states) {
|
||||
let state = createLoadingFeedbackState();
|
||||
let now = 0;
|
||||
for (const status of states) {
|
||||
now += 1000;
|
||||
state = reduceLoadingFeedback(
|
||||
state,
|
||||
aggregateLayerLoading(withPlacePacks([SATELLITES], status)),
|
||||
now,
|
||||
);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
test('nothing extra while the packs are idle', () => {
|
||||
const layers = [SATELLITES];
|
||||
assert.equal(
|
||||
withPlacePacks(layers, { loading: false, failed: false }),
|
||||
layers,
|
||||
);
|
||||
});
|
||||
|
||||
test('the packs are named while they load', () => {
|
||||
const summary = aggregateLayerLoading(
|
||||
withPlacePacks([SATELLITES], { loading: true, failed: false }),
|
||||
);
|
||||
assert.deepEqual(summary.activeIds, ['place-names']);
|
||||
assert.equal(summary.active[0].label, 'Place names');
|
||||
});
|
||||
|
||||
test('a load that lands ends complete; one that fails ends failed', () => {
|
||||
const loading = { loading: true, failed: false };
|
||||
assert.equal(
|
||||
batch([loading, { loading: false, failed: false }]).terminal,
|
||||
'complete',
|
||||
);
|
||||
assert.equal(
|
||||
batch([loading, { loading: false, failed: true }]).terminal,
|
||||
'error',
|
||||
);
|
||||
// A retry after a failure that lands ends complete.
|
||||
assert.equal(
|
||||
batch([
|
||||
{ loading: false, failed: true },
|
||||
loading,
|
||||
{ loading: false, failed: false },
|
||||
]).terminal,
|
||||
'complete',
|
||||
);
|
||||
});
|
||||
@@ -140,3 +140,14 @@ for (const locale of ['es', 'ru']) {
|
||||
assert.equal(shown.label, t(error).toLocaleUpperCase(locale));
|
||||
});
|
||||
}
|
||||
|
||||
test('the place names loading beside the layers are named in the language', () => {
|
||||
setLocale('de');
|
||||
const localized = localizeLoadingPresentation({
|
||||
state: 'loading',
|
||||
label: 'LOADING LIVE DATA',
|
||||
detail: 'Satellites · Place names',
|
||||
});
|
||||
assert.equal(localized.detail, 'Satelliten · Ortsnamen');
|
||||
setLocale('en');
|
||||
});
|
||||
@@ -265,3 +265,64 @@ export function translateStatusLine(text) {
|
||||
.map(translateStatusPiece)
|
||||
.join(STATUS_SEPARATOR);
|
||||
}
|
||||
|
||||
/** Thousands separators out of an English number ("3,000" → 3000). */
|
||||
const englishNumber = (text) => Number(text.replace(/,/g, ''));
|
||||
|
||||
// Coverage notes (transit/queries.js, bikeshare/controls.js). Their " · " is
|
||||
// inside one sentence, so they match whole before the line is split.
|
||||
const COVERAGE_NOTE_PATTERNS = [
|
||||
[
|
||||
/^Fly below ([\d,]+) km to a covered region$/,
|
||||
([, km]) =>
|
||||
t('Fly below {km} km to a covered region', {
|
||||
km: formatNumber(englishNumber(km)),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^No feed here yet · ([\d,]+) regions available$/,
|
||||
([, regions]) => {
|
||||
const count = englishNumber(regions);
|
||||
return tn(
|
||||
count,
|
||||
'No feed here yet · {n} region available',
|
||||
'No feed here yet · {n} regions available',
|
||||
{ n: formatNumber(count) },
|
||||
);
|
||||
},
|
||||
],
|
||||
[
|
||||
/^Fly below ([\d,]+) km to a covered city$/,
|
||||
([, km]) =>
|
||||
t('Fly below {km} km to a covered city', {
|
||||
km: formatNumber(englishNumber(km)),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^No bike share here yet · ([\d,]+) systems available$/,
|
||||
([, systems]) => {
|
||||
const count = englishNumber(systems);
|
||||
return tn(
|
||||
count,
|
||||
'No bike share here yet · {n} system available',
|
||||
'No bike share here yet · {n} systems available',
|
||||
{ n: formatNumber(count) },
|
||||
);
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* A layer's status message in the UI language: its catalog entry, a coverage
|
||||
* note by its shape, or a status line translated piece by piece.
|
||||
*/
|
||||
export function translateStatusMessage(text) {
|
||||
if (typeof text !== 'string') return text;
|
||||
const known = translateKnown(text);
|
||||
if (known !== text) return known;
|
||||
for (const [pattern, format] of COVERAGE_NOTE_PATTERNS) {
|
||||
const match = pattern.exec(text);
|
||||
if (match) return format(match);
|
||||
}
|
||||
return translateStatusLine(text);
|
||||
}
|
||||
@@ -3,7 +3,11 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { setLocale, t } from '../i18n/index.js';
|
||||
import { translateFeedError, translateStatusLine } from './statusText.js';
|
||||
import {
|
||||
translateFeedError,
|
||||
translateStatusLine,
|
||||
translateStatusMessage,
|
||||
} from './statusText.js';
|
||||
|
||||
function inLocale(locale, run) {
|
||||
setLocale(locale);
|
||||
@@ -75,3 +79,55 @@ for (const locale of ['es', 'ru']) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// A layer's coverage note when no feed covers the view: one sentence with a
|
||||
// " · " in it (transit/queries.js, bikeshare/controls.js).
|
||||
const COVERAGE_NOTES = [
|
||||
'Fly below 2,850 km to a covered region',
|
||||
'No feed here yet · 16 regions available',
|
||||
'Fly below 48 km to a covered city',
|
||||
'No bike share here yet · 61 systems available',
|
||||
];
|
||||
|
||||
test('en: coverage notes show as they came', () => {
|
||||
setLocale('en');
|
||||
for (const text of COVERAGE_NOTES)
|
||||
assert.equal(translateStatusMessage(text), text);
|
||||
assert.equal(
|
||||
translateStatusMessage('No bike share here yet · 1 systems available'),
|
||||
'No bike share here yet · 1 system available',
|
||||
);
|
||||
});
|
||||
|
||||
for (const locale of ['es', 'ru', 'ja']) {
|
||||
test(`${locale}: a coverage note translates whole, numbers kept`, () => {
|
||||
inLocale(locale, () => {
|
||||
for (const text of COVERAGE_NOTES) {
|
||||
const shown = translateStatusMessage(text);
|
||||
assert.doesNotMatch(
|
||||
shown,
|
||||
/\b(Fly|below|covered|feed|bike share|available)\b/,
|
||||
shown,
|
||||
);
|
||||
const number = /[\d,]+(?= km| regions| systems)/.exec(text)[0];
|
||||
assert.ok(
|
||||
shown.replace(/[^\d]/g, '').includes(number.replace(/,/g, '')),
|
||||
shown,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test(`${locale}: a status message without a coverage note keeps its other forms`, () => {
|
||||
inLocale(locale, () => {
|
||||
assert.equal(
|
||||
translateStatusMessage('Upstream response too large'),
|
||||
t('Upstream response too large'),
|
||||
);
|
||||
assert.equal(
|
||||
translateStatusMessage('2 feeds live · 14 heard'),
|
||||
translateStatusLine('2 feeds live · 14 heard'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -87,6 +87,51 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
|
||||
radar.value = next && markRaw(next);
|
||||
}
|
||||
|
||||
/**
|
||||
* The orbital view's HUD: null outside a satellite subject. Shape:
|
||||
* `{ name, classLabel, altitudeM, velocityMps|null, latitude, longitude,
|
||||
* zoom, zoomSteps: number[], maxZoom, footprintKm|null,
|
||||
* sensor: { label|null, swathKm, stripFraction|null, zoom|null }|null,
|
||||
* transition: { active, blurPx, lockTick },
|
||||
* look: { offset, readout, swathScale, swathKm|null,
|
||||
* focus: { key, label }|null }, trackUp, northDeg,
|
||||
* place: { kind: 'country'|'sea'|'ocean', name, countryCode,
|
||||
* division?|null, near?|null }|null|undefined,
|
||||
* noradId|null, cosparId|null, tle: { line1, line2, epochMs }|null,
|
||||
* tleAgeMs|null (now minus the TLE epoch, read on each publish),
|
||||
* owner: { countryCode|null, label|null }|null, operator|null }` where
|
||||
* `place` is what the sub-satellite point is over (undefined until the
|
||||
* first offline lookup lands, null when nothing named holds it; see
|
||||
* src/data/placeBelow.js), the identity fields come from the satellites
|
||||
* layer and are null when unknown, `classLabel` is
|
||||
* already localized (the satellite layer's class label, e.g. "NAV · GPS"),
|
||||
* `velocityMps` is the orbital (inertial) speed, latitude/longitude are the
|
||||
* sub-satellite point in degrees, `zoom` is one of `zoomSteps` (1, 2, 4, 8,
|
||||
* and up to 128 for an imaging satellite with a known sensor: `maxZoom`) or
|
||||
* the SENSOR step's zoom between them, `sensor` is the imaging sensor's
|
||||
* narrowest swath with the fraction of the view it spans (kept off nadir)
|
||||
* and the zoom that frames it (null when outside 1x..maxZoom),
|
||||
* `footprintKm` is the nadir ground width across the frame at that zoom
|
||||
* (null while the view is tilted off nadir), `transition` is a zoom step in
|
||||
* flight: `active` while the field of view moves, `blurPx` the focus-pull
|
||||
* blur for the picture, `lockTick` true briefly once the step settles (see
|
||||
* src/cockpitOrbital.js), `look` says whether the view is tilted off
|
||||
* nadir and words the tilt (`readout`, '' at nadir), with the approximate
|
||||
* ground width at the tilted view's centre (`swathKm`, null at nadir) and
|
||||
* its ratio to the nadir footprint (`swathScale`, 1 at nadir) and the
|
||||
* mapped point a ground focus holds the view on (`focus`; the readout
|
||||
* then gives the single off-nadir angle to it), `trackUp`
|
||||
* whether the view is turned to the ground track (false for a satellite with none,
|
||||
* which stays north-up) and `northDeg` where north sits, in degrees
|
||||
* clockwise from the top (0 when north-up).
|
||||
*/
|
||||
const orbital = shallowRef(null);
|
||||
|
||||
/** @param {?object} next A fresh presentation of the orbital view HUD. */
|
||||
function publishOrbital(next) {
|
||||
orbital.value = next && markRaw(next);
|
||||
}
|
||||
|
||||
/**
|
||||
* The utility strip's measured layout: its top and height limits as CSS
|
||||
* lengths (null leaves the stylesheet's), whether only the expanded control
|
||||
@@ -124,6 +169,8 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
|
||||
publishSignals,
|
||||
radar,
|
||||
publishRadar,
|
||||
orbital,
|
||||
publishOrbital,
|
||||
utilityLayout,
|
||||
publishUtilityLayout,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,550 @@
|
||||
/* Orbital view HUD (src/ui/views/panels/CockpitOrbital.vue). The section
|
||||
covers the picture it is placed over: the reticle sits on its centre, the
|
||||
readout top-left and the optics bottom-centre. Square-cornered like the
|
||||
bridge view. The Cockpit controller publishes the zoom step's blur as
|
||||
--cockpit-orbital-blur and its lock tick as a reticle class. */
|
||||
.cockpit-orbital {
|
||||
--orbital-line: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 42%,
|
||||
transparent
|
||||
);
|
||||
--orbital-faint: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 18%,
|
||||
transparent
|
||||
);
|
||||
--orbital-reticle-size: min(38vmin, 320px);
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
color: rgba(244, 251, 255, 0.86);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
pointer-events: none;
|
||||
}
|
||||
.cockpit-orbital[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Focus pull: blurs the picture beneath only while a step is in flight. */
|
||||
.cockpit-orbital-lens {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
.cockpit-orbital-focusing .cockpit-orbital-lens {
|
||||
backdrop-filter: blur(var(--cockpit-orbital-blur, 0px));
|
||||
-webkit-backdrop-filter: blur(var(--cockpit-orbital-blur, 0px));
|
||||
}
|
||||
|
||||
.cockpit-orbital-reticle {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: var(--orbital-reticle-size);
|
||||
height: var(--orbital-reticle-size);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.cockpit-orbital-bracket {
|
||||
position: absolute;
|
||||
width: 18%;
|
||||
height: 18%;
|
||||
border: 0 solid var(--orbital-line);
|
||||
transition:
|
||||
border-color 160ms ease-out,
|
||||
transform 160ms ease-out;
|
||||
}
|
||||
.cockpit-orbital-bracket-tl {
|
||||
top: 0;
|
||||
left: 0;
|
||||
border-top-width: 1px;
|
||||
border-left-width: 1px;
|
||||
}
|
||||
.cockpit-orbital-bracket-tr {
|
||||
top: 0;
|
||||
right: 0;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
}
|
||||
.cockpit-orbital-bracket-bl {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
}
|
||||
.cockpit-orbital-bracket-br {
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
/* Nadir cross: a gapped plus, so the sub-satellite point stays visible. */
|
||||
.cockpit-orbital-cross {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
transform: translate(-50%, -50%);
|
||||
background:
|
||||
linear-gradient(var(--orbital-line), var(--orbital-line)) left center / 10px
|
||||
1px no-repeat,
|
||||
linear-gradient(var(--orbital-line), var(--orbital-line)) right center /
|
||||
10px 1px no-repeat,
|
||||
linear-gradient(var(--orbital-line), var(--orbital-line)) center top / 1px
|
||||
10px no-repeat,
|
||||
linear-gradient(var(--orbital-line), var(--orbital-line)) center bottom /
|
||||
1px 10px no-repeat;
|
||||
}
|
||||
/* North on the frame: the pointer spans the reticle and turns about its
|
||||
centre, carrying the tick (and, track-up, an N) round the rim. */
|
||||
.cockpit-orbital-north-pointer {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
.cockpit-orbital-north-letter {
|
||||
position: absolute;
|
||||
top: -26px;
|
||||
left: 50%;
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
/* North sits at the top of a north-up frame. */
|
||||
.cockpit-orbital-north-tick {
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
left: 50%;
|
||||
width: 1px;
|
||||
height: 7px;
|
||||
background: var(--cockpit-accent, #00dcff);
|
||||
}
|
||||
.cockpit-orbital-reticle-lock .cockpit-orbital-bracket {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
animation: cockpit-orbital-lock 220ms ease-out;
|
||||
}
|
||||
.cockpit-orbital-reticle-lock .cockpit-orbital-cross {
|
||||
--orbital-line: var(--cockpit-accent, #00dcff);
|
||||
}
|
||||
@keyframes cockpit-orbital-lock {
|
||||
0% {
|
||||
transform: scale(1.12);
|
||||
opacity: 0.4;
|
||||
}
|
||||
60% {
|
||||
transform: scale(0.97);
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Bottom-left, where the aircraft Contact card sits (hidden in orbit): clear
|
||||
of the Intel HUD's top-left classification block and above its MGRS and
|
||||
coordinate lines. */
|
||||
.cockpit-orbital-readout {
|
||||
position: absolute;
|
||||
bottom: clamp(150px, 19vh, 190px);
|
||||
left: clamp(16px, 4vw, 48px);
|
||||
max-width: min(320px, calc(100% - 32px));
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--orbital-faint);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 9, 14, 0.62);
|
||||
}
|
||||
.cockpit-orbital-readout p,
|
||||
.cockpit-orbital-data,
|
||||
.cockpit-orbital-data dd {
|
||||
margin: 0;
|
||||
}
|
||||
.cockpit-orbital-kicker {
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.14em;
|
||||
}
|
||||
.cockpit-orbital-name {
|
||||
margin-top: 4px;
|
||||
overflow: hidden;
|
||||
color: #f4fbff;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cockpit-orbital-class {
|
||||
margin-top: 2px;
|
||||
color: rgba(244, 251, 255, 0.66);
|
||||
}
|
||||
|
||||
/* The name with its owner's flag (or text badge) in front. */
|
||||
.cockpit-orbital-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
min-width: 0;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.cockpit-orbital-title .cockpit-orbital-name {
|
||||
min-width: 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
.cockpit-orbital-flag {
|
||||
flex: none;
|
||||
box-sizing: content-box;
|
||||
width: 20px;
|
||||
height: 15px;
|
||||
border: 1px solid var(--orbital-faint);
|
||||
border-radius: 1px;
|
||||
background-repeat: no-repeat;
|
||||
/* Only the flag's own cell: the sheet's neighbours stay out from under
|
||||
the border. */
|
||||
background-clip: content-box;
|
||||
}
|
||||
.cockpit-orbital-owner-badge {
|
||||
flex: none;
|
||||
max-width: 96px;
|
||||
overflow: hidden;
|
||||
padding: 1px 4px;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-size: 9px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cockpit-orbital-operator {
|
||||
margin-top: 2px;
|
||||
overflow: hidden;
|
||||
color: #f4fbff;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* NORAD · COSPAR · epoch, and the element set on request. */
|
||||
.cockpit-orbital-ident {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
color: rgba(244, 251, 255, 0.66);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
/* Wraps between its parts rather than truncating, so the epoch and the
|
||||
element set's age always show in full. */
|
||||
.cockpit-orbital-ident-text {
|
||||
min-width: 0;
|
||||
}
|
||||
.cockpit-orbital-ident-part {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cockpit-orbital-tle-toggle {
|
||||
flex: none;
|
||||
padding: 1px 6px;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.6);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.cockpit-orbital-tle-toggle[aria-expanded='true'],
|
||||
.cockpit-orbital-tle-toggle:hover,
|
||||
.cockpit-orbital-tle-toggle:focus-visible {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
color: #fff;
|
||||
outline: none;
|
||||
}
|
||||
/* 69 characters a line: small enough to fit the card, and selectable. */
|
||||
.cockpit-orbital-tle {
|
||||
margin: 6px 0 0;
|
||||
padding: 5px 6px;
|
||||
overflow-x: auto;
|
||||
border: 1px solid var(--orbital-faint);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 4, 8, 0.7);
|
||||
color: #f4fbff;
|
||||
font: 8px/1.5 var(--font-mono);
|
||||
letter-spacing: 0;
|
||||
white-space: pre;
|
||||
user-select: text;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* Under the vision selector (topline top + its ~38px height + a gap), on
|
||||
the centre line the reticle keeps clear below; the Intel HUD blocks and
|
||||
Display/Radio sit at the sides. */
|
||||
.cockpit-orbital-over {
|
||||
position: absolute;
|
||||
top: calc(clamp(18px, 3vh, 34px) + 50px);
|
||||
left: 50%;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
max-width: min(560px, calc(100% - 32px));
|
||||
margin: 0;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid var(--orbital-faint);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 9, 14, 0.62);
|
||||
transform: translateX(-50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cockpit-orbital-over span {
|
||||
flex: none;
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.14em;
|
||||
}
|
||||
.cockpit-orbital-over strong {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: #f4fbff;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.08em;
|
||||
text-overflow: ellipsis;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.cockpit-orbital-data {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.cockpit-orbital-datum {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.cockpit-orbital-datum dt {
|
||||
color: rgba(244, 251, 255, 0.56);
|
||||
}
|
||||
.cockpit-orbital-datum dd {
|
||||
color: #f4fbff;
|
||||
font-variant-numeric: tabular-nums;
|
||||
text-align: end;
|
||||
}
|
||||
.cockpit-orbital-north {
|
||||
display: inline-block;
|
||||
margin-top: 8px;
|
||||
padding: 1px 5px;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Above RESET / EXIT ORBIT: #view-switcher sits at clamp(128px, 15vh, 150px)
|
||||
less its -95px margin, and its buttons are about 30px tall. */
|
||||
.cockpit-orbital-optics {
|
||||
position: absolute;
|
||||
bottom: calc(clamp(128px, 15vh, 150px) - 95px + 44px);
|
||||
left: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--orbital-faint);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 9, 14, 0.62);
|
||||
transform: translateX(-50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* With a sensor's swath and step the strip is longer: it may wrap on a
|
||||
narrow screen rather than run off it. */
|
||||
@media (max-width: 720px) {
|
||||
.cockpit-orbital-optics {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
max-width: calc(100vw - 32px);
|
||||
}
|
||||
}
|
||||
.cockpit-orbital-zoom-button {
|
||||
width: 28px;
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.6);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.cockpit-orbital-zoom-button:hover:not(:disabled),
|
||||
.cockpit-orbital-zoom-button:focus-visible {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
color: #fff;
|
||||
outline: none;
|
||||
}
|
||||
.cockpit-orbital-zoom-button:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: default;
|
||||
}
|
||||
.cockpit-orbital-zoom {
|
||||
min-width: 64px;
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
text-align: center;
|
||||
}
|
||||
.cockpit-orbital-swath {
|
||||
padding-inline: 4px 2px;
|
||||
border-inline-start: 1px solid var(--orbital-faint);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.cockpit-orbital-readout {
|
||||
max-width: calc(100% - 32px);
|
||||
}
|
||||
.cockpit-orbital-name {
|
||||
font-size: 13px;
|
||||
}
|
||||
/* The phone shell lifts RESET / EXIT ORBIT (its row ends ~106px up) and
|
||||
sets the DISPLAY / RADIO row above it (to ~194px up). The optics wrap to
|
||||
two rows and sit above that row, where the zoom buttons can be tapped;
|
||||
the card sits above the optics. */
|
||||
.cockpit-orbital-optics {
|
||||
bottom: 200px;
|
||||
}
|
||||
.cockpit-orbital-readout {
|
||||
bottom: 284px;
|
||||
}
|
||||
}
|
||||
|
||||
/* A short window: the card stops below the left rail (DATA LAYERS,
|
||||
UTILITIES, which end ~340px down) and scrolls its own content, the TLE
|
||||
block included, instead of running into the rail. */
|
||||
@media (max-height: 760px) and (min-width: 561px) {
|
||||
.cockpit-orbital-readout {
|
||||
max-height: max(120px, calc(100vh - clamp(150px, 19vh, 190px) - 350px));
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* An instant cut: no focus pull and no lock motion. */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.cockpit-orbital-focusing .cockpit-orbital-lens {
|
||||
backdrop-filter: none;
|
||||
-webkit-backdrop-filter: none;
|
||||
}
|
||||
.cockpit-orbital-bracket {
|
||||
transition: none;
|
||||
}
|
||||
.cockpit-orbital-reticle-lock .cockpit-orbital-bracket {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Off-nadir look: the tilt readout and the way back, tucked under the
|
||||
readout card at the side of the picture. Shown only while tilted. */
|
||||
.cockpit-orbital-look {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--orbital-faint);
|
||||
}
|
||||
.cockpit-orbital-look-readout {
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.cockpit-orbital-nadir {
|
||||
padding: 3px 8px;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.6);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.cockpit-orbital-nadir:hover,
|
||||
.cockpit-orbital-nadir:focus-visible {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
color: #fff;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* The Cockpit HUD in orbit (#cockpit-hud[data-subject='satellite']): the
|
||||
orbital readout names the satellite, so the topline keeps only the
|
||||
vision selector, and panels and buttons stay square like the bridge. */
|
||||
#cockpit-hud[data-subject='satellite'] .cockpit-topline > div:first-child {
|
||||
visibility: hidden;
|
||||
}
|
||||
:root[data-ui-theme='cyber'] #cockpit-hud[data-subject='satellite']::before {
|
||||
clip-path: none;
|
||||
}
|
||||
:root:not([data-ui-theme='cyber']) body.cockpit-orbit {
|
||||
--panel-radius: 2px;
|
||||
--btn-radius: 2px;
|
||||
}
|
||||
#cockpit-hud[data-subject='satellite']
|
||||
:is(
|
||||
.cockpit-vision-controls,
|
||||
.cockpit-vision-controls button,
|
||||
.cockpit-card-actions button,
|
||||
.cockpit-utility-glyph,
|
||||
.cockpit-radio-transport button,
|
||||
#cockpit-brief-auto
|
||||
) {
|
||||
border-radius: 2px;
|
||||
}
|
||||
body.cockpit-orbit #view-switcher button {
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
/* The imaging sensor's narrowest swath, to scale across the view's width. The
|
||||
view is track-up, so the swath runs top to bottom along the ground track. */
|
||||
.cockpit-orbital-sensor-strip {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
min-width: 2px;
|
||||
border-inline: 1px dashed var(--orbital-line);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 6%,
|
||||
transparent
|
||||
);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.cockpit-orbital-sensor-swath {
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
}
|
||||
.cockpit-orbital-sensor-step {
|
||||
padding: 3px 8px;
|
||||
border: 1px solid var(--orbital-line);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.6);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.12em;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.cockpit-orbital-sensor-step:hover,
|
||||
.cockpit-orbital-sensor-step:focus-visible {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
color: #fff;
|
||||
outline: none;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* The site a ground focus holds, named under the off-nadir readout
|
||||
(src/ui/views/panels/CockpitOrbital.vue). Empty, it takes no room. */
|
||||
.cockpit-orbital-focus:not(:empty) {
|
||||
margin-top: 4px;
|
||||
overflow: hidden;
|
||||
color: #f4fbff;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -987,6 +987,26 @@ html:not([lang='en']) .pp-slider-row > .pp-slider-mini-label {
|
||||
.draw-mark-row.hidden-mark .draw-mark-swatch {
|
||||
opacity: 0.45;
|
||||
}
|
||||
/* What an application's row action said (a measurement, a confirmation), under
|
||||
the row; empty, it takes no room. */
|
||||
.draw-mark-note {
|
||||
order: 2;
|
||||
flex-basis: 100%;
|
||||
padding: 0 0 2px 16px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.4px;
|
||||
color: var(--text-dim);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.draw-mark-note:empty {
|
||||
display: none;
|
||||
}
|
||||
/* Busy, but focusable: disabling the pressed button would drop focus. */
|
||||
.draw-mark-action[aria-disabled='true'] {
|
||||
opacity: 0.5;
|
||||
cursor: progress;
|
||||
}
|
||||
.draw-mark-colors {
|
||||
/* Right after its swatch for keyboard and screen readers, shown last. */
|
||||
order: 1;
|
||||
|
||||
@@ -360,6 +360,31 @@ html:not([lang='en']) .radio-transport button {
|
||||
margin: 0 0 7px;
|
||||
color: #fff;
|
||||
}
|
||||
.military-awareness-photo {
|
||||
display: block;
|
||||
margin: 0 0 8px;
|
||||
color: #a9b7c7;
|
||||
text-decoration: none;
|
||||
}
|
||||
.military-awareness-photo img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border: 1px solid rgba(98, 181, 255, 0.34);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.military-awareness-photo small {
|
||||
display: block;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.military-awareness-photo:hover small,
|
||||
.military-awareness-photo:focus-visible small {
|
||||
color: #fff;
|
||||
}
|
||||
.military-awareness-photo:focus-visible {
|
||||
outline: 1px solid rgba(127, 200, 255, 0.85);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.military-awareness-controls {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useCockpitStore } from '../stores/cockpit.js';
|
||||
import { useGlobeActionsStore } from '../stores/globeActions.js';
|
||||
import CockpitBriefing from './panels/CockpitBriefing.vue';
|
||||
import CockpitContext from './panels/CockpitContext.vue';
|
||||
import CockpitOrbital from './panels/CockpitOrbital.vue';
|
||||
import CockpitRadar from './panels/CockpitRadar.vue';
|
||||
import CockpitRollingValue from './panels/CockpitRollingValue.vue';
|
||||
import CockpitUtilityControls from './panels/CockpitUtilityControls.vue';
|
||||
@@ -26,15 +27,31 @@ const { presence, instruments, route, vision, utilityLayout } =
|
||||
const active = computed(() => Boolean(presence.value?.active));
|
||||
// A vessel subject swaps the aviation readouts for bridge ones.
|
||||
const bridge = computed(() => presence.value?.subjectKind === 'vessel');
|
||||
const subject = computed(() => (bridge.value ? 'vessel' : 'aircraft'));
|
||||
// A satellite subject keeps only its orbital HUD over the nadir picture.
|
||||
const orbital = computed(() => presence.value?.subjectKind === 'satellite');
|
||||
const subject = computed(() =>
|
||||
bridge.value ? 'vessel' : orbital.value ? 'satellite' : 'aircraft',
|
||||
);
|
||||
const hudLabel = computed(() =>
|
||||
bridge.value ? t('Ship bridge view') : t('Aircraft cockpit view'),
|
||||
bridge.value
|
||||
? t('Ship bridge view')
|
||||
: orbital.value
|
||||
? t('Satellite orbital view')
|
||||
: t('Aircraft cockpit view'),
|
||||
);
|
||||
const exitLabel = computed(() =>
|
||||
bridge.value ? t('Exit bridge view') : t('Exit cockpit view'),
|
||||
bridge.value
|
||||
? t('Exit bridge view')
|
||||
: orbital.value
|
||||
? t('Exit orbital view')
|
||||
: t('Exit cockpit view'),
|
||||
);
|
||||
const exitText = computed(() =>
|
||||
bridge.value ? t('EXIT BRIDGE') : t('EXIT COCKPIT'),
|
||||
bridge.value
|
||||
? t('EXIT BRIDGE')
|
||||
: orbital.value
|
||||
? t('EXIT ORBIT')
|
||||
: t('EXIT COCKPIT'),
|
||||
);
|
||||
const globe = useGlobeActionsStore();
|
||||
const { resetBusy } = storeToRefs(globe);
|
||||
@@ -74,8 +91,10 @@ const tickStyle = (tick) =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Aircraft first-person view or a vessel's bridge. It can be entered from the visible view switcher. -->
|
||||
<section id="cockpit-hud" :aria-label="hudLabel" :hidden="!active" :data-subject="subject" :style="utilityStyle" v-class-toggle="{ 'signals-active': active, 'context-active': Boolean(presence?.context) }" :data-layer="hud.layer ?? undefined">
|
||||
<!-- Aircraft first-person view, a vessel's bridge or a satellite's nadir view. It can be entered from the visible view switcher. -->
|
||||
<section id="cockpit-hud" :aria-label="hudLabel" :hidden="!active" :data-subject="subject" :style="utilityStyle" v-class-toggle="{ 'signals-active': active, 'context-active': Boolean(presence?.context) }" :data-layer="orbital ? 'satellites' : hud.layer ?? undefined">
|
||||
<!-- In orbit the picture keeps only the nadir reticle, readout and zoom. -->
|
||||
<CockpitOrbital v-if="orbital" />
|
||||
<!-- One optical coordinate system: every targeting mark shares this center.
|
||||
Decorative only; telemetry and interactive panels remain separate.
|
||||
A bridge looks out through straight window mullions instead: a header
|
||||
@@ -87,7 +106,7 @@ const tickStyle = (tick) =>
|
||||
<path d="M0 600H324 M876 600H1200"/>
|
||||
</g>
|
||||
</svg>
|
||||
<svg v-else class="cockpit-frame-lines" viewBox="0 0 1200 720" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
||||
<svg v-else-if="!orbital" class="cockpit-frame-lines" viewBox="0 0 1200 720" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
||||
<g fill="none" stroke="currentColor">
|
||||
<path d="M42 106H234L266 126H334 M866 126H934L966 106H1158 M42 114H226L258 136H318 M882 136H942L974 114H1158"/>
|
||||
<path d="M42 616H226L254 598H320 M880 598H946L974 616H1158 M42 624H238L266 606H330 M870 606H934L962 624H1158"/>
|
||||
@@ -97,7 +116,7 @@ const tickStyle = (tick) =>
|
||||
<path class="cockpit-frame-warning" d="M338 645H476L490 654H710L724 645H862" fill="none"/>
|
||||
<path class="cockpit-frame-meter" d="M372 642H418 M782 642H828"/>
|
||||
</svg>
|
||||
<div v-if="!bridge" class="cockpit-scan-array" aria-hidden="true">
|
||||
<div v-if="!bridge && !orbital" class="cockpit-scan-array" aria-hidden="true">
|
||||
<svg class="cockpit-target-geometry" viewBox="0 0 600 600" fill="none" focusable="false">
|
||||
<g class="cockpit-target-hairline">
|
||||
<circle cx="300" cy="300" r="276"/>
|
||||
@@ -129,7 +148,7 @@ const tickStyle = (tick) =>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="cockpit-visor-shell" aria-hidden="true">
|
||||
<div v-if="!orbital" class="cockpit-visor-shell" aria-hidden="true">
|
||||
<!-- A ship's bridge keeps no roll arc or pitch ladder. -->
|
||||
<div v-if="!bridge" class="cockpit-roll-arc">
|
||||
<span style="--slot:-3;--depth:3">−30</span>
|
||||
@@ -158,7 +177,7 @@ const tickStyle = (tick) =>
|
||||
<div class="cockpit-visor-status cockpit-visor-status-left">{{ bridge ? t('BRIDGE WINDOW · FWD') : t('OPTICAL PLANE · 01') }}</div>
|
||||
<div class="cockpit-visor-status cockpit-visor-status-right">{{ bridge ? (hud.trackSource === 'course' ? t('COURSE HOLD · AIS') : hud.trackSource === 'heading' ? t('HEADING HOLD · AIS') : t('NO HEADING · AIS')) : t('VISOR LOCK · ACTIVE') }}</div>
|
||||
</div>
|
||||
<div id="cockpit-speed-rim" class="cockpit-altitude-rim cockpit-speed-rim" v-class-toggle="{ unavailable: hud.speedRim.unavailable }">
|
||||
<div v-if="!orbital" id="cockpit-speed-rim" class="cockpit-altitude-rim cockpit-speed-rim" v-class-toggle="{ unavailable: hud.speedRim.unavailable }">
|
||||
<span class="cockpit-altitude-rim-label">{{ bridge ? t('SPEED OVER GROUND · KTS') : t('GROUND SPEED · KTS') }}</span>
|
||||
<div class="cockpit-altitude-rim-rail"></div>
|
||||
<div class="cockpit-altitude-rim-scale">
|
||||
@@ -169,7 +188,7 @@ const tickStyle = (tick) =>
|
||||
<strong id="cockpit-speed-rim-value">{{ hud.speedRim.value }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div id="cockpit-altitude-rim" class="cockpit-altitude-rim" :hidden="bridge" v-class-toggle="{ unavailable: hud.altitudeRim.unavailable }">
|
||||
<div v-if="!orbital" id="cockpit-altitude-rim" class="cockpit-altitude-rim" :hidden="bridge" v-class-toggle="{ unavailable: hud.altitudeRim.unavailable }">
|
||||
<span class="cockpit-altitude-rim-label">{{ t('ALTITUDE · FT') }}</span>
|
||||
<div class="cockpit-altitude-rim-rail"></div>
|
||||
<div class="cockpit-altitude-rim-scale">
|
||||
@@ -201,7 +220,7 @@ const tickStyle = (tick) =>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cockpit-reticle material-symbols-outlined" aria-hidden="true">my_location</div>
|
||||
<div v-if="!orbital" class="cockpit-reticle material-symbols-outlined" aria-hidden="true">my_location</div>
|
||||
<!-- A bridge view turned off the bow says where it looks and offers the way back. -->
|
||||
<div v-if="bridge" class="cockpit-look" :hidden="!look.offset">
|
||||
<span id="cockpit-look-readout" class="cockpit-look-readout" aria-live="polite">{{ look.readout }}</span>
|
||||
@@ -209,7 +228,7 @@ const tickStyle = (tick) =>
|
||||
<span>{{ t('LOOK AHEAD') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="cockpit-compass" :aria-label="bridge ? t('Current vessel heading') : t('Current aircraft heading')">
|
||||
<div v-if="!orbital" class="cockpit-compass" :aria-label="bridge ? t('Current vessel heading') : t('Current aircraft heading')">
|
||||
<div class="cockpit-instrument-row">
|
||||
<div class="cockpit-readout cockpit-speed">
|
||||
<span class="cockpit-readout-label">{{ bridge ? t('SPEED OVER GROUND') : t('GROUND SPEED') }}</span>
|
||||
@@ -231,7 +250,7 @@ const tickStyle = (tick) =>
|
||||
<span class="cockpit-heading-caret material-symbols-outlined" aria-hidden="true">arrow_drop_down</span>
|
||||
<div class="cockpit-compass-tape" id="cockpit-compass-tape" aria-hidden="true" :style="bridge ? { '--tape-shift': tapeShift } : undefined"><span v-for="division in hud.compass" :key="division.heading ?? division.slot" :class="(division.active ?? division.slot === 0) ? 'active' : ''" :style="{ '--slot': division.slot, '--depth': Math.abs(division.slot) }">{{ division.label }}</span><template v-if="bridge"><i v-if="hud.compassMarkers?.prograde != null" class="cockpit-compass-marker cockpit-compass-prograde" aria-hidden="true" :style="{ '--slot': hud.compassMarkers.prograde }"></i><i v-if="hud.compassMarkers?.retrograde != null" class="cockpit-compass-marker cockpit-compass-retrograde" aria-hidden="true" :style="{ '--slot': hud.compassMarkers.retrograde }"></i></template></div>
|
||||
</div>
|
||||
<div class="cockpit-position-readout">
|
||||
<div v-if="!orbital" class="cockpit-position-readout">
|
||||
<span id="cockpit-clock">{{ hud.clock }}</span>
|
||||
<span id="cockpit-position">{{ hud.position }}</span>
|
||||
</div>
|
||||
@@ -242,7 +261,7 @@ const tickStyle = (tick) =>
|
||||
<CockpitRadar />
|
||||
</div>
|
||||
<CockpitUtilityControls />
|
||||
<div class="cockpit-help"><bdi>{{ t('ESC EXIT') }}</bdi> <span>·</span> <bdi>{{ t('C TOGGLE') }}</bdi><template v-if="bridge"> <span>·</span> <bdi>{{ t('ARROWS LOOK') }}</bdi> <span>·</span> <bdi>{{ t('HOME RESET') }}</bdi></template></div>
|
||||
<div class="cockpit-help"><bdi>{{ t('ESC EXIT') }}</bdi><template v-if="bridge"> <span>·</span> <bdi>{{ t('ARROWS LOOK') }}</bdi> <span>·</span> <bdi>{{ t('HOME RESET') }}</bdi></template><template v-if="orbital"> <span>·</span> <bdi>{{ t('+/− ZOOM') }}</bdi> <span>·</span> <bdi>{{ t('ARROWS TILT') }}</bdi> <span>·</span> <bdi>{{ t('HOME NADIR') }}</bdi></template></div>
|
||||
</section>
|
||||
|
||||
<nav id="view-switcher" :aria-label="t('View switcher')">
|
||||
@@ -250,7 +269,7 @@ const tickStyle = (tick) =>
|
||||
<span class="material-symbols-outlined" aria-hidden="true">public</span>
|
||||
<span>{{ t('RESET') }}</span>
|
||||
</button>
|
||||
<button id="map-view-switch" type="button" :aria-label="exitLabel" aria-keyshortcuts="Escape C" :title="exitLabel" :hidden="!active">
|
||||
<button id="map-view-switch" type="button" :aria-label="exitLabel" aria-keyshortcuts="Escape" :title="exitLabel" :hidden="!active">
|
||||
<span class="material-symbols-outlined" aria-hidden="true">close_fullscreen</span>
|
||||
<span>{{ exitText }}</span>
|
||||
</button>
|
||||
|
||||
@@ -11,6 +11,13 @@ import AwarenessNames from './AwarenessNames.vue';
|
||||
const { awareness: view, awarenessLayer: layer } = storeToRefs(useContextStore());
|
||||
const user = { origin: 'user' };
|
||||
const root = ref(null);
|
||||
// A photo whose image failed to load stays hidden until another one arrives.
|
||||
// The failing image's own src is recorded, so a late error from a previous
|
||||
// photo never hides the current one.
|
||||
const failedPhoto = ref('');
|
||||
const fail = (event) => {
|
||||
failedPhoto.value = event.target.getAttribute('src');
|
||||
};
|
||||
|
||||
// A live repaint keeps focus on the same control by identity: browsers drop
|
||||
// focus from a node Vue moves, removes or disables, so the control is found
|
||||
@@ -52,6 +59,10 @@ onUpdated(() => {
|
||||
</div>
|
||||
<template v-else-if="view.kind === 'results'">
|
||||
<div class="military-awareness-subject">{{ view.subject }}</div>
|
||||
<a v-if="view.photo && view.photo.src !== failedPhoto" class="military-awareness-photo" :href="view.photo.link" target="_blank" rel="noopener">
|
||||
<img :src="view.photo.src" :width="view.photo.width ?? undefined" :height="view.photo.height ?? undefined" alt="" @error="fail" />
|
||||
<small>{{ view.photo.credit }}</small>
|
||||
</a>
|
||||
<AwarenessNames v-if="view.subjectNames" :names="view.subjectNames" />
|
||||
<div class="military-awareness-controls" role="group" :aria-label="view.navigation.label">
|
||||
<button type="button" data-awareness-action="previous" :title="view.navigation.previous.title" :disabled="view.navigation.previous.disabled" @click="layer?.navigatePrevious(user)">{{ view.navigation.previous.text }}</button>
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import { formatNumber, getLocale, t } from '../../../i18n/index.js';
|
||||
import {
|
||||
formatCockpitCoordinate,
|
||||
formatTleEpochUtc,
|
||||
tleAgeParts,
|
||||
} from '../../cockpitPresentation.js';
|
||||
import {
|
||||
ownerMark,
|
||||
preloadOwnerFlags,
|
||||
regionName,
|
||||
shownOwnerMark,
|
||||
} from '../../ownerFlag.js';
|
||||
import { useCockpitStore } from '../../stores/cockpit.js';
|
||||
|
||||
// The orbital view's HUD: a nadir reticle over the picture, the satellite's
|
||||
// identity and orbit, and the optical zoom. The Cockpit controller presents
|
||||
// it, drives the zoom step's blur and lock tick, and keeps the zoom buttons'
|
||||
// listeners; this view only reflects the store.
|
||||
|
||||
const { orbital } = storeToRefs(useCockpitStore());
|
||||
|
||||
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
||||
|
||||
const altitudeText = computed(() => {
|
||||
const altitudeM = orbital.value?.altitudeM;
|
||||
return finite(altitudeM)
|
||||
? t('{value} KM', {
|
||||
value: formatNumber(Math.round(altitudeM / 1000)),
|
||||
})
|
||||
: '—';
|
||||
});
|
||||
|
||||
const velocityText = computed(() => {
|
||||
const velocityMps = orbital.value?.velocityMps;
|
||||
return finite(velocityMps)
|
||||
? t('{value} KM/S', {
|
||||
value: formatNumber(velocityMps / 1000, {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}),
|
||||
})
|
||||
: null;
|
||||
});
|
||||
|
||||
const subPointText = computed(() => {
|
||||
const { latitude, longitude } = orbital.value || {};
|
||||
if (!finite(latitude) || !finite(longitude)) return '—';
|
||||
return `${formatCockpitCoordinate(latitude, 'N', 'S')} ${formatCockpitCoordinate(longitude, 'E', 'W')}`;
|
||||
});
|
||||
|
||||
const zoomSteps = computed(() => orbital.value?.zoomSteps || [1]);
|
||||
const zoom = computed(() => orbital.value?.zoom ?? zoomSteps.value[0]);
|
||||
// The SENSOR step lands between ladder steps, e.g. 5.7×.
|
||||
const zoomText = computed(() =>
|
||||
t('ZOOM {zoom}×', {
|
||||
zoom: formatNumber(zoom.value, { maximumFractionDigits: 1 }),
|
||||
}),
|
||||
);
|
||||
const maxZoom = computed(
|
||||
() => orbital.value?.maxZoom ?? Math.max(...zoomSteps.value),
|
||||
);
|
||||
const atWidest = computed(() => zoom.value <= Math.min(...zoomSteps.value));
|
||||
const atTightest = computed(() => zoom.value >= maxZoom.value);
|
||||
|
||||
// The imaging sensor's swath: a strip drawn to scale across the view, its
|
||||
// width as a readout, and the SENSOR step that zooms the view to it. Off
|
||||
// nadir the strip stays, the readout scales as the view's swath does (≈),
|
||||
// and the SENSOR step, a nadir framing, is hidden.
|
||||
const sensor = computed(() => orbital.value?.sensor || null);
|
||||
// Track-up turns the frame to the ground track; north's pointer turns back.
|
||||
const trackUp = computed(() => orbital.value?.trackUp === true);
|
||||
const northPointerStyle = computed(() => {
|
||||
const northDeg = orbital.value?.northDeg;
|
||||
return finite(northDeg) && northDeg !== 0
|
||||
? { transform: `rotate(${northDeg.toFixed(1)}deg)` }
|
||||
: null;
|
||||
});
|
||||
// The N itself stays upright as its pointer turns.
|
||||
const northLetterStyle = computed(() => {
|
||||
const northDeg = orbital.value?.northDeg;
|
||||
return finite(northDeg) && northDeg !== 0
|
||||
? { transform: `translateX(-50%) rotate(${(-northDeg).toFixed(1)}deg)` }
|
||||
: null;
|
||||
});
|
||||
|
||||
const sensorStripStyle = computed(() => {
|
||||
const fraction = sensor.value?.stripFraction;
|
||||
return finite(fraction) && fraction > 0
|
||||
? { width: `${(fraction * 100).toFixed(3)}%` }
|
||||
: null;
|
||||
});
|
||||
const sensorText = computed(() => {
|
||||
const km = sensor.value?.swathKm;
|
||||
if (!finite(km)) return '';
|
||||
const look = orbital.value?.look;
|
||||
if (look?.offset === true) {
|
||||
const scale = look.swathScale;
|
||||
if (!finite(scale)) return '';
|
||||
return t('SENSOR SWATH ≈ {value} KM', {
|
||||
value: formatNumber(km * scale, { maximumFractionDigits: 1 }),
|
||||
});
|
||||
}
|
||||
// As published: 13.1 km, 185 km.
|
||||
return t('SENSOR SWATH {value} KM', {
|
||||
value: formatNumber(km, { maximumFractionDigits: 1 }),
|
||||
});
|
||||
});
|
||||
const sensorStepShown = computed(
|
||||
() =>
|
||||
finite(sensor.value?.zoom) &&
|
||||
finite(orbital.value?.footprintKm) &&
|
||||
orbital.value?.look?.offset !== true,
|
||||
);
|
||||
|
||||
// A focused control that turns off (a zoom button at the end of its range,
|
||||
// SENSOR as the view tilts away) hands focus on instead of dropping it to the
|
||||
// page. The watchers run before the re-render, while it still has focus.
|
||||
const zoomInButton = ref(null);
|
||||
const zoomOutButton = ref(null);
|
||||
const sensorButton = ref(null);
|
||||
const nadirButton = ref(null);
|
||||
const handFocus = (from, to) => {
|
||||
if (!from || document.activeElement !== from) return;
|
||||
nextTick(() =>
|
||||
(to() ?? document.getElementById('map-view-switch'))?.focus({
|
||||
preventScroll: true,
|
||||
}),
|
||||
);
|
||||
};
|
||||
watch(
|
||||
atTightest,
|
||||
(now) => now && handFocus(zoomInButton.value, () => zoomOutButton.value),
|
||||
{ flush: 'pre' },
|
||||
);
|
||||
watch(
|
||||
atWidest,
|
||||
(now) => now && handFocus(zoomOutButton.value, () => zoomInButton.value),
|
||||
{ flush: 'pre' },
|
||||
);
|
||||
watch(
|
||||
sensorStepShown,
|
||||
(shown) => !shown && handFocus(sensorButton.value, () => nadirButton.value),
|
||||
{ flush: 'pre' },
|
||||
);
|
||||
|
||||
// At nadir the footprint; tilted, the approximate width at the view's
|
||||
// centre, marked ≈.
|
||||
const swathText = computed(() => {
|
||||
const tilted = orbital.value?.look?.offset === true;
|
||||
const km = tilted ? orbital.value?.look?.swathKm : orbital.value?.footprintKm;
|
||||
if (!finite(km)) return '';
|
||||
const digits = km < 10 ? 1 : 0;
|
||||
const value = formatNumber(km, {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
});
|
||||
return tilted
|
||||
? t('SWATH ≈ {value} KM', { value })
|
||||
: t('SWATH {value} KM', { value });
|
||||
});
|
||||
|
||||
// What the sub-satellite point is over: nothing until the first lookup
|
||||
// lands; on land the division as Natural Earth names it and the country in
|
||||
// the reader's language, with the populated place in view from 8x; at sea
|
||||
// the Natural Earth name.
|
||||
const placeText = computed(() => {
|
||||
const place = orbital.value?.place;
|
||||
if (place === undefined) return '';
|
||||
// No feature holds the point (a gap at a simplified coastline): say
|
||||
// nothing rather than call land open ocean.
|
||||
if (!place) return '';
|
||||
if (place.kind !== 'country') return place.name || '';
|
||||
const country =
|
||||
(place.countryCode && regionName(place.countryCode, getLocale())) ||
|
||||
place.name ||
|
||||
'';
|
||||
const region = place.division
|
||||
? t('{division}, {country}', { division: place.division, country })
|
||||
: country;
|
||||
return place.near
|
||||
? t('{region} · near {place}', { region, place: place.near })
|
||||
: region;
|
||||
});
|
||||
|
||||
// The owner's flag, or a text badge for an owner without one.
|
||||
const mark = computed(() =>
|
||||
ownerMark(orbital.value?.owner, { locale: getLocale() }),
|
||||
);
|
||||
// The flag sheet loads at startup; a sheet that would not load (offline, a
|
||||
// stale asset after a deploy) is asked again for the next flag, and until it
|
||||
// comes the code shows as a badge, never no owner at all.
|
||||
const flagsReady = ref(false);
|
||||
const flagsFailed = ref(false);
|
||||
watch(
|
||||
// Keyed on the satellite too: after a failed load, the next ride asks
|
||||
// again even when its owner is the same country.
|
||||
() =>
|
||||
mark.value?.kind === 'flag'
|
||||
? `${mark.value.code}:${orbital.value?.noradId ?? ''}`
|
||||
: null,
|
||||
async (key) => {
|
||||
if (!key || flagsReady.value) return;
|
||||
const ready = await preloadOwnerFlags();
|
||||
flagsReady.value = ready;
|
||||
flagsFailed.value = !ready;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
const shownMark = computed(() =>
|
||||
shownOwnerMark(mark.value, {
|
||||
ready: flagsReady.value,
|
||||
failed: flagsFailed.value,
|
||||
}),
|
||||
);
|
||||
|
||||
// NORAD · COSPAR · TLE epoch, and the two element lines on request.
|
||||
const identParts = computed(() => {
|
||||
const o = orbital.value;
|
||||
if (!o) return [];
|
||||
const parts = [];
|
||||
if (o.noradId !== null && o.noradId !== undefined && o.noradId !== '')
|
||||
parts.push(t('NORAD {id}', { id: String(o.noradId) }));
|
||||
if (o.cosparId) parts.push(o.cosparId);
|
||||
const epoch = formatTleEpochUtc(o.tle?.epochMs);
|
||||
if (epoch) parts.push(t('EPOCH {time}', { time: epoch }));
|
||||
const age = tleAgeParts(o.tleAgeMs);
|
||||
if (age?.unit === 'under-hour') parts.push(t('<1 H OLD'));
|
||||
else if (age?.unit === 'hours')
|
||||
parts.push(t('{value} H OLD', { value: formatNumber(age.value) }));
|
||||
else if (age?.unit === 'days')
|
||||
parts.push(t('{value} D OLD', { value: formatNumber(age.value) }));
|
||||
return parts;
|
||||
});
|
||||
const identText = computed(() => identParts.value.join(' · '));
|
||||
const tleText = computed(() => {
|
||||
const tle = orbital.value?.tle;
|
||||
return tle?.line1 && tle?.line2 ? `${tle.line1}\n${tle.line2}` : '';
|
||||
});
|
||||
const tleOpen = ref(false);
|
||||
// Another satellite starts with its element set folded.
|
||||
watch(
|
||||
() => orbital.value?.noradId ?? null,
|
||||
() => {
|
||||
tleOpen.value = false;
|
||||
},
|
||||
);
|
||||
|
||||
// The off-nadir tilt; an untilted view shows no readout or reset.
|
||||
const look = computed(() => orbital.value?.look || { offset: false });
|
||||
// A ground focus names its target in a polite live region; the angle,
|
||||
// which changes every update, is left out of it.
|
||||
const focusText = computed(() => {
|
||||
const label = look.value.focus?.label;
|
||||
return label ? t('FOCUS · {name}', { name: label }) : '';
|
||||
});
|
||||
|
||||
const transition = computed(() => orbital.value?.transition || {});
|
||||
const lensStyle = computed(() => {
|
||||
const blurPx = transition.value.blurPx;
|
||||
return {
|
||||
'--cockpit-orbital-blur': `${finite(blurPx) && blurPx > 0 ? blurPx.toFixed(2) : 0}px`,
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section id="cockpit-orbital" class="cockpit-orbital" :class="{ 'cockpit-orbital-focusing': transition.active }" :style="lensStyle" :aria-label="t('Orbital view')" :hidden="!orbital">
|
||||
<template v-if="orbital">
|
||||
<div class="cockpit-orbital-lens" aria-hidden="true"></div>
|
||||
<div class="cockpit-orbital-reticle" :class="{ 'cockpit-orbital-reticle-lock': transition.lockTick }" aria-hidden="true">
|
||||
<span class="cockpit-orbital-bracket cockpit-orbital-bracket-tl"></span>
|
||||
<span class="cockpit-orbital-bracket cockpit-orbital-bracket-tr"></span>
|
||||
<span class="cockpit-orbital-bracket cockpit-orbital-bracket-bl"></span>
|
||||
<span class="cockpit-orbital-bracket cockpit-orbital-bracket-br"></span>
|
||||
<span class="cockpit-orbital-cross"></span>
|
||||
<!-- North on the frame: at the top while north-up, turned with the ground track while track-up. -->
|
||||
<span class="cockpit-orbital-north-pointer" :style="northPointerStyle">
|
||||
<span class="cockpit-orbital-north-tick"></span>
|
||||
<span v-if="trackUp" class="cockpit-orbital-north-letter" :style="northLetterStyle">{{ t('N') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<!-- The imaging sensor's swath, to scale across the view. -->
|
||||
<div v-if="sensorStripStyle" class="cockpit-orbital-sensor-strip" :style="sensorStripStyle" aria-hidden="true"></div>
|
||||
<!-- Under the vision selector: where the ground track is. -->
|
||||
<p v-if="placeText" id="cockpit-orbital-over" class="cockpit-orbital-over"><span>{{ t('CURRENTLY OVER') }}</span> <strong>{{ placeText }}</strong></p>
|
||||
<div class="cockpit-orbital-readout">
|
||||
<p class="cockpit-orbital-kicker">{{ look.offset ? t('ORBITAL VIEW · OFF-NADIR') : t('ORBITAL VIEW · NADIR') }}</p>
|
||||
<div class="cockpit-orbital-title">
|
||||
<span v-if="shownMark?.kind === 'flag'" class="cockpit-orbital-flag" role="img" :aria-label="shownMark.label" :title="shownMark.label" :style="shownMark.style"></span>
|
||||
<span v-else-if="shownMark?.kind === 'badge'" class="cockpit-orbital-owner-badge" :title="shownMark.title">{{ shownMark.label }}</span>
|
||||
<p class="cockpit-orbital-name">{{ orbital.name }}</p>
|
||||
</div>
|
||||
<p v-if="orbital.operator" class="cockpit-orbital-operator">{{ orbital.operator }}</p>
|
||||
<p v-if="orbital.classLabel" class="cockpit-orbital-class">{{ orbital.classLabel }}</p>
|
||||
<div v-if="identText" class="cockpit-orbital-ident">
|
||||
<!-- Wraps between parts, never inside a date. -->
|
||||
<span class="cockpit-orbital-ident-text"><template v-for="(part, index) in identParts" :key="index"><template v-if="index"> · </template><span class="cockpit-orbital-ident-part">{{ part }}</span></template></span>
|
||||
<button v-if="tleText" id="cockpit-orbital-tle-toggle" type="button" class="cockpit-orbital-tle-toggle" :aria-expanded="String(tleOpen)" aria-controls="cockpit-orbital-tle" :aria-label="tleOpen ? t('Hide the two-line element set') : t('Show the two-line element set')" :title="tleOpen ? t('Hide the two-line element set') : t('Show the two-line element set')" @click="tleOpen = !tleOpen">{{ t('TLE') }}</button>
|
||||
</div>
|
||||
<pre v-if="tleText" v-show="tleOpen" id="cockpit-orbital-tle" class="cockpit-orbital-tle" :aria-label="t('Two-line element set')">{{ tleText }}</pre>
|
||||
<dl class="cockpit-orbital-data">
|
||||
<div class="cockpit-orbital-datum">
|
||||
<dt>{{ t('ALTITUDE') }}</dt>
|
||||
<dd class="cockpit-orbital-altitude">{{ altitudeText }}</dd>
|
||||
</div>
|
||||
<div v-if="velocityText" class="cockpit-orbital-datum">
|
||||
<dt>{{ t('ORBITAL VELOCITY') }}</dt>
|
||||
<dd class="cockpit-orbital-velocity">{{ velocityText }}</dd>
|
||||
</div>
|
||||
<div class="cockpit-orbital-datum">
|
||||
<dt>{{ t('SUB-SATELLITE POINT') }}</dt>
|
||||
<dd class="cockpit-orbital-subpoint">{{ subPointText }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p class="cockpit-orbital-north">{{ trackUp ? t('TRACK UP') : t('NORTH UP') }}</p>
|
||||
<!-- Shown only while the view is tilted off nadir: where it looks and the way back. -->
|
||||
<div v-if="look.offset" class="cockpit-orbital-look">
|
||||
<span id="cockpit-orbital-look-readout" class="cockpit-orbital-look-readout" :aria-live="look.focus ? 'off' : 'polite'">{{ look.readout }}</span>
|
||||
<button id="cockpit-orbital-nadir" ref="nadirButton" type="button" class="cockpit-orbital-nadir" :aria-label="t('Return the view to nadir')" :title="t('Return to nadir (Home or 0)')" aria-keyshortcuts="Home 0">{{ t('NADIR') }}</button>
|
||||
</div>
|
||||
<p id="cockpit-orbital-focus" class="cockpit-orbital-focus" aria-live="polite">{{ focusText }}</p>
|
||||
</div>
|
||||
<div class="cockpit-orbital-optics">
|
||||
<button id="cockpit-orbital-zoom-out" ref="zoomOutButton" type="button" class="cockpit-orbital-zoom-button" :disabled="atWidest" :aria-label="t('Zoom out')" :title="t('Zoom out (−)')" aria-keyshortcuts="- _">−</button>
|
||||
<span class="cockpit-orbital-zoom" aria-live="polite">{{ zoomText }}</span>
|
||||
<button id="cockpit-orbital-zoom-in" ref="zoomInButton" type="button" class="cockpit-orbital-zoom-button" :disabled="atTightest" :aria-label="t('Zoom in')" :title="t('Zoom in (+)')" aria-keyshortcuts="+ =">+</button>
|
||||
<span v-if="swathText" class="cockpit-orbital-swath">{{ swathText }}</span>
|
||||
<span v-if="sensorText" class="cockpit-orbital-swath cockpit-orbital-sensor-swath">{{ sensorText }}</span>
|
||||
<button v-if="sensorStepShown" id="cockpit-orbital-sensor" ref="sensorButton" type="button" class="cockpit-orbital-sensor-step" :aria-label="t('Zoom to the imaging sensor swath')" :title="t('Zoom to the imaging sensor swath')">{{ t('SENSOR') }}</button>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
@@ -7,7 +7,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createApp, nextTick } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import { presentDrawMarks } from '../../../annotations/drawMarks.js';
|
||||
import { drawMarkActions, presentDrawMarks } from '../../../annotations/drawMarks.js';
|
||||
import { useDisplayStore } from '../../stores/display.js';
|
||||
import DrawMarkList from './DrawMarkList.vue';
|
||||
|
||||
@@ -34,8 +34,8 @@ function mount(t) {
|
||||
return { store, calls };
|
||||
}
|
||||
|
||||
async function show(store, marks) {
|
||||
store.publishDraw({ active: true, shape: 'area', color: 'primary', hint: '', marks: presentDrawMarks(marks) });
|
||||
async function show(store, marks, actions = []) {
|
||||
store.publishDraw({ active: true, shape: 'area', color: 'primary', hint: '', marks: presentDrawMarks(marks, drawMarkActions(actions)) });
|
||||
await nextTick();
|
||||
}
|
||||
const row = (id) => document.querySelector(`#draw-mark-list [data-mark-id="${id}"]`);
|
||||
@@ -63,6 +63,32 @@ test('lists only hand-drawn marks, named or by kind, with Import-style actions',
|
||||
assert.equal(control('a2', 'remove').getAttribute('aria-label'), 'Remove Camp');
|
||||
});
|
||||
|
||||
test('an application\'s row actions sit before fly to, labelled, and act on their mark', async (t) => {
|
||||
const { store, calls } = mount(t);
|
||||
const tag = { id: 'tag', icon: 'sell', label: (name) => `Tag ${name}`, shapes: ['line'], run: () => {} };
|
||||
await show(store, [{ ...LINE, path: [[0, 0], [1, 0]] }, PIN], [tag]);
|
||||
const button = control('a1', 'action-tag');
|
||||
assert.equal(button.getAttribute('aria-label'), 'Tag Line · 950 m');
|
||||
assert.equal(button.textContent, 'sell');
|
||||
assert.equal(button.nextElementSibling, control('a1', 'fly'));
|
||||
assert.equal(control('a2', 'action-tag'), null, 'a pin is not offered a line action');
|
||||
button.click();
|
||||
assert.deepEqual(calls, [['runDrawMarkAction', 'a1', 'tag']]);
|
||||
const note = row('a1').querySelector('.draw-mark-note');
|
||||
assert.equal(note.getAttribute('role'), 'status');
|
||||
assert.equal(note.textContent, '');
|
||||
assert.equal(row('a2').querySelector('.draw-mark-note'), null, 'a row without actions has no note');
|
||||
const line = { ...LINE, path: [[0, 0], [1, 0]] };
|
||||
store.publishDraw({ active: true, shape: 'area', color: 'primary', hint: '', marks: presentDrawMarks([line], drawMarkActions([tag]), new Map([['a1', { busy: true, text: '' }]])) });
|
||||
await nextTick();
|
||||
assert.equal(control('a1', 'action-tag').getAttribute('aria-disabled'), 'true');
|
||||
assert.equal(row('a1').querySelector('.draw-mark-note').textContent, '…');
|
||||
store.publishDraw({ active: true, shape: 'area', color: 'primary', hint: '', marks: presentDrawMarks([line], drawMarkActions([tag]), new Map([['a1', { busy: false, text: 'Tagged' }]])) });
|
||||
await nextTick();
|
||||
assert.equal(control('a1', 'action-tag').getAttribute('aria-disabled'), 'false');
|
||||
assert.equal(row('a1').querySelector('.draw-mark-note').textContent, 'Tagged');
|
||||
});
|
||||
|
||||
test('show/hide, fly to and remove act on that one mark', async (t) => {
|
||||
const { store, calls } = mount(t);
|
||||
await show(store, [LINE, PIN]);
|
||||
|
||||
@@ -10,10 +10,11 @@ import { useDisplayStore } from '../../stores/display.js';
|
||||
|
||||
// UTILITIES ▸ Draw's shapes, one row each like Import's files: the colour
|
||||
// swatch (it opens the five colours in the row), the name typed in place,
|
||||
// and show/hide, fly to and remove. The draw tool publishes the rows and
|
||||
// answers the controls. Rows are keyed, so a board change elsewhere updates a
|
||||
// row in place and never takes the button under a click or the field being
|
||||
// typed in. The list's template is one line: templates keep whitespace.
|
||||
// and show/hide, the application's own row actions, fly to and remove. The
|
||||
// draw tool publishes the rows and answers the controls. Rows are keyed, so a
|
||||
// board change elsewhere updates a row in place and never takes the button
|
||||
// under a click or the field being typed in. The list's template is one
|
||||
// line: templates keep whitespace.
|
||||
const display = useDisplayStore();
|
||||
const { draw } = storeToRefs(display);
|
||||
const rows = computed(() => draw.value?.marks ?? []);
|
||||
@@ -98,5 +99,5 @@ function leave() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul class="geo-import-list draw-mark-list" :class="{ visible: listed }" id="draw-mark-list" v-focus-safe-children="leave" :aria-label="t('Drawn shapes')"><li v-for="row in rows" :key="row.id" class="geo-import-row draw-mark-row" :class="{ 'hidden-mark': row.hidden }" :data-mark-id="row.id" @keydown="onRowKey(row, $event)"><button type="button" class="geo-import-swatch draw-mark-swatch" data-control="swatch" :style="{ background: DRAW_COLOR_CSS[row.color] }" :title="row.labels.swatch" :aria-label="row.labels.swatch" :aria-expanded="String(picking === row.id)" :aria-controls="`draw-mark-colors-${row.id}`" @click="picking = picking === row.id ? null : row.id"></button><DrawSwatches v-if="picking === row.id" :id="`draw-mark-colors-${row.id}`" class="draw-mark-colors" data-control="picker" autofocus :label="row.labels.colors" :model-value="row.color" @update:model-value="recolor(row, $event)" @choose="closePicker(row.id)" /><input type="text" class="geo-import-name draw-mark-name" data-control="name" maxlength="120" autocomplete="off" spellcheck="false" v-field-value="row.name" :placeholder="row.placeholder" :aria-label="row.labels.name" @keydown="onNameKey(row, $event)" @focusout="commit(row, $event.currentTarget)"><button type="button" class="geo-import-action" data-control="toggle" :title="row.labels.toggle" :aria-label="row.labels.toggle" @click="display.act('toggleDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ row.hidden ? 'visibility_off' : 'visibility' }}</span></button><button type="button" class="geo-import-action" data-control="fly" :title="row.labels.fly" :aria-label="row.labels.fly" @click="display.act('flyToDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">my_location</span></button><button type="button" class="geo-import-action" data-control="remove" :title="row.labels.remove" :aria-label="row.labels.remove" @click="display.act('removeDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">close</span></button></li></ul>
|
||||
<ul class="geo-import-list draw-mark-list" :class="{ visible: listed }" id="draw-mark-list" v-focus-safe-children="leave" :aria-label="t('Drawn shapes')"><li v-for="row in rows" :key="row.id" class="geo-import-row draw-mark-row" :class="{ 'hidden-mark': row.hidden }" :data-mark-id="row.id" @keydown="onRowKey(row, $event)"><button type="button" class="geo-import-swatch draw-mark-swatch" data-control="swatch" :style="{ background: DRAW_COLOR_CSS[row.color] }" :title="row.labels.swatch" :aria-label="row.labels.swatch" :aria-expanded="String(picking === row.id)" :aria-controls="`draw-mark-colors-${row.id}`" @click="picking = picking === row.id ? null : row.id"></button><DrawSwatches v-if="picking === row.id" :id="`draw-mark-colors-${row.id}`" class="draw-mark-colors" data-control="picker" autofocus :label="row.labels.colors" :model-value="row.color" @update:model-value="recolor(row, $event)" @choose="closePicker(row.id)" /><input type="text" class="geo-import-name draw-mark-name" data-control="name" maxlength="120" autocomplete="off" spellcheck="false" v-field-value="row.name" :placeholder="row.placeholder" :aria-label="row.labels.name" @keydown="onNameKey(row, $event)" @focusout="commit(row, $event.currentTarget)"><button type="button" class="geo-import-action" data-control="toggle" :title="row.labels.toggle" :aria-label="row.labels.toggle" @click="display.act('toggleDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ row.hidden ? 'visibility_off' : 'visibility' }}</span></button><button v-for="action in row.actions" :key="action.id" type="button" class="geo-import-action draw-mark-action" :data-control="`action-${action.id}`" :data-action="action.id" :title="action.label" :aria-label="action.label" :aria-disabled="String(row.busy)" @click="display.act('runDrawMarkAction', row.id, action.id)"><span class="material-symbols-outlined" aria-hidden="true">{{ action.icon }}</span></button><button type="button" class="geo-import-action" data-control="fly" :title="row.labels.fly" :aria-label="row.labels.fly" @click="display.act('flyToDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">my_location</span></button><button type="button" class="geo-import-action" data-control="remove" :title="row.labels.remove" :aria-label="row.labels.remove" @click="display.act('removeDrawMark', row.id)"><span class="material-symbols-outlined" aria-hidden="true">close</span></button><span v-if="row.actions.length" class="draw-mark-note" role="status" :aria-busy="String(row.busy)">{{ row.busy ? '…' : row.note }}</span></li></ul>
|
||||
</template>
|
||||
Reference in new issue
Block a user