mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge remote-tracking branch 'origin/main' into sv-locale
This commit is contained in:
commit
6a6cee4c21
231 files changed
+26032
-776
No files matched your search
@@ -64,6 +64,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.
|
||||
@@ -158,8 +161,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;
|
||||
@@ -361,6 +371,10 @@ export class StyleManager extends ShellFacade {
|
||||
services: {
|
||||
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,
|
||||
@@ -375,6 +389,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,
|
||||
@@ -400,6 +421,10 @@ export class StyleManager extends ShellFacade {
|
||||
useCockpitStore(applicationPinia()).publishVision(view),
|
||||
signals: (rows) =>
|
||||
useCockpitStore(applicationPinia()).publishSignals(rows),
|
||||
radar: (view) =>
|
||||
useCockpitStore(applicationPinia()).publishRadar(view),
|
||||
orbital: (view) =>
|
||||
useCockpitStore(applicationPinia()).publishOrbital(view),
|
||||
utilityLayout: (layout) =>
|
||||
useCockpitStore(applicationPinia()).publishUtilityLayout(layout),
|
||||
},
|
||||
@@ -1810,6 +1835,7 @@ export class StyleManager extends ShellFacade {
|
||||
this._wildlifeSightingCard?.destroy();
|
||||
this._ui.destroy();
|
||||
this._panelChrome.destroy();
|
||||
this._offPlacePacks();
|
||||
this._feedback.destroy();
|
||||
|
||||
this._displayBindings.destroy();
|
||||
|
||||
@@ -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']) {
|
||||
for (const name of ['cockpit-mode', 'cockpit-bridge', 'cockpit-orbit']) {
|
||||
assert.ok(classes.includes(name), `${name} is not added to <body>`);
|
||||
}
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -85,12 +85,9 @@ export function relocalizeBrief() {
|
||||
Object.assign(this.brief, cycleWords(this.briefAutoRotateEnabled));
|
||||
this.showBriefPage(this.briefPageIndex);
|
||||
if (this.regionalBrief)
|
||||
this.renderRegionalBrief(this.regionalBrief, this.lastAircraftInfo);
|
||||
this.renderRegionalBrief(this.regionalBrief, this.lastSubjectInfo);
|
||||
else if (this.brief.news.state)
|
||||
this.renderRegionalBriefStatus(
|
||||
this.brief.news.state,
|
||||
this.lastAircraftInfo,
|
||||
);
|
||||
this.renderRegionalBriefStatus(this.brief.news.state, this.lastSubjectInfo);
|
||||
}
|
||||
|
||||
export function setBriefAutoRotate(enabled) {
|
||||
@@ -156,7 +153,7 @@ export function maybeRefreshRegionalBrief(info) {
|
||||
!Number.isFinite(info.longitude)
|
||||
)
|
||||
return;
|
||||
const subjectId = `${info.layerId || 'aircraft'}:${info.icao24 || 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;
|
||||
|
||||
+244
-11
@@ -7,6 +7,15 @@ import {
|
||||
cockpitUiUpdateDue,
|
||||
slewHeading,
|
||||
} from '../cockpitMath.js';
|
||||
import {
|
||||
VESSEL_DEAD_RECKON_MAX_S,
|
||||
VESSEL_WATERLINE_REFRESH_MS,
|
||||
deadReckonVesselFix,
|
||||
vesselCameraProfile,
|
||||
vesselWaterlineM,
|
||||
waterlineProbePoints,
|
||||
} from '../cockpitSubjects.js';
|
||||
import { easeLook } from '../cockpitLook.js';
|
||||
import {
|
||||
COCKPIT_HEADING_SLEW_DPS,
|
||||
COCKPIT_FORWARD_OFFSET_M,
|
||||
@@ -44,6 +53,14 @@ export function update() {
|
||||
}
|
||||
|
||||
const nowMs = performance.now();
|
||||
if (this.subjectKind === 'vessel') {
|
||||
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
|
||||
@@ -86,17 +103,216 @@ export function update() {
|
||||
placeCamera.call(this, target, info, nowMs, dtSec, AIRCRAFT_CAMERA_PROFILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* The surface the ridden ship floats on: the layer's geoid sea surface, or
|
||||
* the water read off the rendered scene when that sits higher (a river or
|
||||
* lake above sea level). The read runs in the background every
|
||||
* VESSEL_WATERLINE_REFRESH_MS. The full-detail read can take many seconds
|
||||
* from cold tiles, so a new ship's first read starts from the tiles already
|
||||
* on screen; until any read lands the sea surface stands. Only one
|
||||
* full-detail read runs at a time (each is nine picks Cesium traverses
|
||||
* every frame until it settles): while one is still running, a refresh
|
||||
* reads the loaded tiles instead, and the slow read applies whenever it
|
||||
* lands. Once a full-detail read has answered, only full-detail reads
|
||||
* change the height; before then a loaded-tile read may find raised water
|
||||
* but never takes a raised height back to the sea. One coarse probe cannot
|
||||
* drop a river bridge to the sea, and a read that sampled nothing keeps
|
||||
* the height it had.
|
||||
* @param {{latitude: number, longitude: number}} [at] Where to read the
|
||||
* water: the dead-reckoned position the camera rides.
|
||||
* @returns {number} Ellipsoidal metres.
|
||||
*/
|
||||
function vesselSurfaceM(info, nowMs, at = info) {
|
||||
const seaM = Number.isFinite(info.seaSurfaceHeightM)
|
||||
? info.seaSurfaceHeightM
|
||||
: 0;
|
||||
const scene = this.viewer.scene;
|
||||
let read =
|
||||
this.vesselWaterline?.mmsi === info.mmsi ? this.vesselWaterline : null;
|
||||
if (
|
||||
typeof scene?.sampleHeightMostDetailed === 'function' &&
|
||||
(!read || nowMs - read.sampledMs >= VESSEL_WATERLINE_REFRESH_MS)
|
||||
) {
|
||||
const probes = waterlineProbePoints(at.latitude, at.longitude).map(
|
||||
({ lat, lon }) => Cesium.Cartographic.fromDegrees(lon, lat),
|
||||
);
|
||||
if (!read) {
|
||||
read = {
|
||||
mmsi: info.mmsi,
|
||||
heightM: loadedWaterlineM(scene, probes, seaM),
|
||||
sampledMs: nowMs,
|
||||
// Whether a full-detail read has answered for this ship.
|
||||
landed: false,
|
||||
inFlight: false,
|
||||
};
|
||||
this.vesselWaterline = read;
|
||||
} else {
|
||||
read.sampledMs = nowMs;
|
||||
if (read.inFlight && !read.landed) {
|
||||
const loadedM = loadedWaterlineM(scene, probes, seaM);
|
||||
// Taking a river back to the sea is the full-detail read's to say.
|
||||
const lowers =
|
||||
Number.isFinite(read.heightM) &&
|
||||
read.heightM > seaM &&
|
||||
!(loadedM > seaM);
|
||||
if (Number.isFinite(loadedM) && !lowers) read.heightM = loadedM;
|
||||
}
|
||||
}
|
||||
if (!read.inFlight) readWaterline.call(this, read, scene, probes, seaM);
|
||||
}
|
||||
return read && Number.isFinite(read.heightM)
|
||||
? Math.max(seaM, read.heightM)
|
||||
: seaM;
|
||||
}
|
||||
|
||||
/** Start one full-detail water read for `read`; its answer lands on it. */
|
||||
function readWaterline(read, scene, probes, seaM) {
|
||||
read.inFlight = true;
|
||||
Promise.resolve()
|
||||
.then(() => scene.sampleHeightMostDetailed(probes))
|
||||
.then(
|
||||
(samples) => {
|
||||
if (this.vesselWaterline !== read) return;
|
||||
read.inFlight = false;
|
||||
// However late it lands, it applies; one that sampled nothing (tiles
|
||||
// not loaded yet) is no answer and keeps the height already read.
|
||||
const heights = (samples || []).map((sample) => sample?.height);
|
||||
if (!heights.some(Number.isFinite)) return;
|
||||
read.landed = true;
|
||||
read.heightM = vesselWaterlineM(seaM, heights);
|
||||
},
|
||||
() => {
|
||||
if (this.vesselWaterline === read) read.inFlight = false;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The waterline from the tiles already loaded, read at once: a first answer
|
||||
* while the full-detail read loads. Null when the scene cannot sample or no
|
||||
* probe met loaded geometry: nothing sampled is no answer, not the sea, so it
|
||||
* never undoes a river height a full read set.
|
||||
*/
|
||||
function loadedWaterlineM(scene, probes, seaM) {
|
||||
if (typeof scene.sampleHeight !== 'function') return null;
|
||||
if (scene.sampleHeightSupported === false) return null;
|
||||
try {
|
||||
const heights = probes.map((probe) => scene.sampleHeight(probe));
|
||||
if (!heights.some(Number.isFinite)) return null;
|
||||
return vesselWaterlineM(seaM, heights);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drive the bridge camera from the selected vessel. The vessel layer redraws
|
||||
* a ship only when its feed refreshes, so the target is the last fix advanced
|
||||
* along course over ground; the shared anchor smoothing then absorbs the
|
||||
* correction each new fix brings.
|
||||
*/
|
||||
function updateVessel(nowMs) {
|
||||
// Tracking an aircraft from the bridge clears the vessel selection; end the
|
||||
// bridge and leave Cesium tracking with that aircraft.
|
||||
if (this.viewer.trackedEntity?.position) {
|
||||
this.exit({ restoreTracking: false });
|
||||
return;
|
||||
}
|
||||
const info = this.readVesselInfo();
|
||||
if (!info || info.mmsi !== this.subjectId) {
|
||||
this.exit({ restoreTracking: false });
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!cockpitUiUpdateDue(
|
||||
nowMs,
|
||||
this.lastCameraUpdateMs,
|
||||
COCKPIT_CAMERA_UPDATE_MS,
|
||||
)
|
||||
)
|
||||
return;
|
||||
this.lastCameraUpdateMs = nowMs;
|
||||
|
||||
const fix = deadReckonVesselFix(
|
||||
{
|
||||
latitude: info.latitude,
|
||||
longitude: info.longitude,
|
||||
courseDeg: info.motionCourse,
|
||||
speedMps: info.velocityMps,
|
||||
fixEpochMs: info.fixEpochMs,
|
||||
receivedAtMs: info.receivedAtMs,
|
||||
feedEpochMs: info.feedEpochMs,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
// The radar centres here too, so it agrees with the view out the window.
|
||||
this.vesselFix = fix;
|
||||
const target = Cesium.Cartesian3.fromDegrees(
|
||||
fix.longitude,
|
||||
fix.latitude,
|
||||
// Read the water where the ship is now, not at its last report.
|
||||
vesselSurfaceM.call(this, info, nowMs, fix),
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
this.scratchTarget,
|
||||
);
|
||||
// The target advances in wall-clock time, so the anchor must too: the
|
||||
// aircraft path's 0.1 s step cap would leave a slow-frame or hitching bridge
|
||||
// falling ever further behind its own ship.
|
||||
const dtSec = Math.min(
|
||||
VESSEL_DEAD_RECKON_MAX_S,
|
||||
Math.max(0, (nowMs - this.lastFrameMs) / 1000),
|
||||
);
|
||||
this.lastFrameMs = nowMs;
|
||||
if (Number.isFinite(info.track)) {
|
||||
this.heading = slewHeading(
|
||||
this.heading ?? info.track,
|
||||
info.track,
|
||||
COCKPIT_HEADING_SLEW_DPS * dtSec,
|
||||
);
|
||||
}
|
||||
// Past the projection limit the target stops advancing; hold on it rather
|
||||
// than let the inertial anchor sail on alone.
|
||||
const projectionExpired =
|
||||
Number.isFinite(fix.ageSec) && fix.ageSec > VESSEL_DEAD_RECKON_MAX_S;
|
||||
// The look eases on its own clock: the anchor's step is capped differently.
|
||||
this.lookView = easeLook(
|
||||
this.lookView,
|
||||
this.lookTarget,
|
||||
nowMs - (this.lookLastMs || nowMs),
|
||||
);
|
||||
this.lookLastMs = nowMs;
|
||||
// A ship reporting neither course nor heading has no direction to move
|
||||
// in: its anchor stays on the fix, as the dead reckoning does.
|
||||
const ridden = Number.isFinite(info.motionCourse)
|
||||
? info
|
||||
: { ...info, velocityMps: 0 };
|
||||
placeCamera.call(
|
||||
this,
|
||||
target,
|
||||
projectionExpired ? { ...ridden, stale: true } : ridden,
|
||||
nowMs,
|
||||
dtSec,
|
||||
vesselCameraProfile(info),
|
||||
this.lookView,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the camera for one update: advance the inertial anchor, clamp it and
|
||||
* the eye against the rendered surface, and look along the slewed heading.
|
||||
* @param {Cesium.Cartesian3} target Authoritative subject position.
|
||||
* @param {object} info Subject info.
|
||||
* @param {object} info Subject info; `motionCourse` (when present) is the
|
||||
* direction the subject moves, otherwise it moves where it faces.
|
||||
* @param {number} nowMs Frame time.
|
||||
* @param {number} dtSec Seconds since the previous camera update.
|
||||
* @param {{forwardM: number, upM: number, pitchDeg: number,
|
||||
* minClearanceM: number}} profile Eye offsets for the subject kind.
|
||||
* @param {?{yawDeg: number, pitchDeg: number}} [look] A bridge view turned
|
||||
* off the bow: yaw relative to the heading and absolute pitch. It turns
|
||||
* only the view; the eye and its motion keep the heading and course.
|
||||
* Aircraft pass none and look along the heading at the profile pitch.
|
||||
*/
|
||||
function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
|
||||
if (!this.cockpitAnchorValid) {
|
||||
Cesium.Cartesian3.clone(target, this.cockpitAnchor);
|
||||
this.cockpitAnchorValid = true;
|
||||
@@ -110,7 +326,15 @@ function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
// 15/30-second interpolation and per-frame cache without exposing its
|
||||
// sample-boundary corrections to the camera.
|
||||
const headingRad = Cesium.Math.toRadians(this.heading ?? 0);
|
||||
const pitchRad = Cesium.Math.toRadians(profile.pitchDeg);
|
||||
const courseRad = Number.isFinite(info.motionCourse)
|
||||
? Cesium.Math.toRadians(info.motionCourse)
|
||||
: headingRad;
|
||||
const pitchRad = Cesium.Math.toRadians(
|
||||
look ? look.pitchDeg : profile.pitchDeg,
|
||||
);
|
||||
const viewHeadingRad = look
|
||||
? Cesium.Math.toRadians((this.heading ?? 0) + look.yawDeg)
|
||||
: headingRad;
|
||||
const speedMps = Number.isFinite(info.velocityMps)
|
||||
? Math.max(0, info.velocityMps)
|
||||
: 0;
|
||||
@@ -126,8 +350,8 @@ function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
this.scratchEnu,
|
||||
);
|
||||
this.scratchLocal.x = Math.sin(headingRad);
|
||||
this.scratchLocal.y = Math.cos(headingRad);
|
||||
this.scratchLocal.x = Math.sin(courseRad);
|
||||
this.scratchLocal.y = Math.cos(courseRad);
|
||||
this.scratchLocal.z = 0;
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
this.scratchEnu,
|
||||
@@ -187,9 +411,18 @@ function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
this.scratchTargetCartographic,
|
||||
);
|
||||
// A bridge's target is its fix dead-reckoned up to minutes ahead: read
|
||||
// the floor where the ship is now, as its water is.
|
||||
const floorAt =
|
||||
info.kind === 'vessel'
|
||||
? {
|
||||
latitude: Cesium.Math.toDegrees(targetCartographic.latitude),
|
||||
longitude: Cesium.Math.toDegrees(targetCartographic.longitude),
|
||||
}
|
||||
: info;
|
||||
let cockpitFloorM = this.services.cachedGroundFloor(
|
||||
info.latitude,
|
||||
info.longitude,
|
||||
floorAt.latitude,
|
||||
floorAt.longitude,
|
||||
);
|
||||
if (info.onGround === true) {
|
||||
const groundPoint = [{ lat: info.latitude, lon: info.longitude }];
|
||||
@@ -296,8 +529,8 @@ function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
);
|
||||
Cesium.Cartesian3.normalize(this.scratchHorizontal, this.scratchHorizontal);
|
||||
|
||||
this.scratchLocal.x = Math.sin(headingRad) * Math.cos(pitchRad);
|
||||
this.scratchLocal.y = Math.cos(headingRad) * Math.cos(pitchRad);
|
||||
this.scratchLocal.x = Math.sin(viewHeadingRad) * Math.cos(pitchRad);
|
||||
this.scratchLocal.y = Math.cos(viewHeadingRad) * Math.cos(pitchRad);
|
||||
this.scratchLocal.z = Math.sin(pitchRad);
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
this.scratchEnu,
|
||||
@@ -306,8 +539,8 @@ function placeCamera(target, info, nowMs, dtSec, profile) {
|
||||
);
|
||||
Cesium.Cartesian3.normalize(this.scratchForward, this.scratchForward);
|
||||
|
||||
this.scratchLocal.x = -Math.sin(headingRad) * Math.sin(pitchRad);
|
||||
this.scratchLocal.y = -Math.cos(headingRad) * Math.sin(pitchRad);
|
||||
this.scratchLocal.x = -Math.sin(viewHeadingRad) * Math.sin(pitchRad);
|
||||
this.scratchLocal.y = -Math.cos(viewHeadingRad) * Math.sin(pitchRad);
|
||||
this.scratchLocal.z = Math.cos(pitchRad);
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
this.scratchEnu,
|
||||
|
||||
+282
-8
@@ -1,6 +1,8 @@
|
||||
/** Coordinate Cockpit lifecycle through supplied aircraft, terrain, rendering and briefing operations. */
|
||||
import {
|
||||
readAircraftInfo,
|
||||
readSatelliteInfo,
|
||||
readVesselInfo,
|
||||
readSubjectLayerId,
|
||||
resolveEntryKind,
|
||||
dispatchCockpitModeChanged,
|
||||
@@ -14,11 +16,36 @@ 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,
|
||||
updateHud,
|
||||
updateRoute,
|
||||
updateRadar,
|
||||
presentLook,
|
||||
syncWeatherToggle,
|
||||
setVisionMode,
|
||||
cycleVisionMode,
|
||||
@@ -67,10 +94,21 @@ import {
|
||||
import {
|
||||
onKeyDown,
|
||||
onSceneDoubleClick,
|
||||
onScenePointerDown,
|
||||
routeSceneDoubleClick,
|
||||
} from './cockpitInput.js';
|
||||
import { DEFAULT_RADAR_RANGE_NM, nextRadarRange } from '../cockpitRadar.js';
|
||||
import { VESSEL_BRIDGE_PITCH_DEG } from '../cockpitSubjects.js';
|
||||
import { stepLook } from '../cockpitLook.js';
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/** Whether the user asked for reduced motion: look turns then jump. */
|
||||
function prefersReducedMotion() {
|
||||
return Boolean(
|
||||
globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches,
|
||||
);
|
||||
}
|
||||
|
||||
export class CockpitViewController {
|
||||
constructor(
|
||||
viewer,
|
||||
@@ -80,6 +118,8 @@ export class CockpitViewController {
|
||||
getInitialVisionMode = null,
|
||||
onCameraTakeover = null,
|
||||
isEntryAllowed = null,
|
||||
isBridgeEntryAllowed = null,
|
||||
isOrbitEntryAllowed = null,
|
||||
isUtilityDisclosureOpen = null,
|
||||
onEntered = null,
|
||||
onExited = null,
|
||||
@@ -93,6 +133,21 @@ export class CockpitViewController {
|
||||
this.destroyed = false;
|
||||
this.disposed = false;
|
||||
this.active = false;
|
||||
/**
|
||||
* 'aircraft', 'vessel' or 'satellite' while active; which subject the
|
||||
* camera rides.
|
||||
*/
|
||||
this.subjectKind = null;
|
||||
/**
|
||||
* 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;
|
||||
@@ -105,6 +160,14 @@ export class CockpitViewController {
|
||||
this.surfaceWaitStartedMs = 0;
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
/**
|
||||
* Where the bridge view is turned to (`lookTarget`) and where the camera
|
||||
* looks on its way there (`lookView`): yaw off the bow, starboard
|
||||
* positive, and absolute pitch. Aircraft never turn it.
|
||||
*/
|
||||
this.lookTarget = { yawDeg: 0, pitchDeg: VESSEL_BRIDGE_PITCH_DEG };
|
||||
this.lookView = { ...this.lookTarget };
|
||||
this.lookLastMs = 0;
|
||||
this.entry = document.getElementById('cockpit-entry');
|
||||
this.tr3bToggle = document.getElementById('tr3b-toggle');
|
||||
this._tr3bSignature = null;
|
||||
@@ -130,6 +193,16 @@ export class CockpitViewController {
|
||||
: () => false;
|
||||
this.isEntryAllowed =
|
||||
typeof isEntryAllowed === 'function' ? isEntryAllowed : () => true;
|
||||
// Without a supplied gate there is no vessel layer to ride either.
|
||||
this.isBridgeEntryAllowed =
|
||||
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
|
||||
@@ -164,9 +237,16 @@ export class CockpitViewController {
|
||||
this.publishVision = publish.vision ?? (() => {});
|
||||
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 = {
|
||||
active: false,
|
||||
entryAvailable: false,
|
||||
// Which subject the entry button would enter, and the active subject.
|
||||
entryKind: null,
|
||||
subjectKind: null,
|
||||
tr3b: null,
|
||||
context: false,
|
||||
// The Contact and briefing cards' collapse, which their toggles show.
|
||||
@@ -179,7 +259,8 @@ export class CockpitViewController {
|
||||
this.contextView = createContextState();
|
||||
this.brief = createBriefState();
|
||||
this.briefTimer = null;
|
||||
this.lastAircraftInfo = null;
|
||||
// The last aircraft or vessel the HUD drew.
|
||||
this.lastSubjectInfo = null;
|
||||
this.regionalBrief = null;
|
||||
this.regionalBriefAnchor = null;
|
||||
this.regionalBriefFetchedAt = 0;
|
||||
@@ -216,9 +297,25 @@ export class CockpitViewController {
|
||||
);
|
||||
this._listen(this.entry, 'click', () => this.enter());
|
||||
// Double-clicking the followed track is a third way in.
|
||||
this._listen(
|
||||
viewer.scene?.canvas,
|
||||
'pointerdown',
|
||||
() => this.onScenePointerDown(),
|
||||
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, so its clicks are delegated.
|
||||
// this controller; delegated like the radar's range button.
|
||||
this._listen(document, 'click', (event) => {
|
||||
if (event.target?.closest?.('#cockpit-entry-readout')) this.enter();
|
||||
});
|
||||
@@ -248,6 +345,26 @@ export class CockpitViewController {
|
||||
this._listen(window, 'gev:cockpit-weather-state', (event) => {
|
||||
this.syncWeatherToggle(event?.detail?.enabled !== false);
|
||||
});
|
||||
// The radar mounts only on a bridge, so its range button is delegated.
|
||||
this._listen(document, 'click', (event) => {
|
||||
if (event.target?.closest?.('#cockpit-radar-range'))
|
||||
this.cycleRadarRange();
|
||||
});
|
||||
// The look-ahead button shows only on a turned bridge view; delegated.
|
||||
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 }),
|
||||
);
|
||||
@@ -289,6 +406,108 @@ export class CockpitViewController {
|
||||
readAircraftInfo() {
|
||||
return readAircraftInfo.call(this);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -316,8 +535,8 @@ export class CockpitViewController {
|
||||
_adoptTrackedEntity(nowMs, suppliedInfo) {
|
||||
return _adoptTrackedEntity.call(this, nowMs, suppliedInfo);
|
||||
}
|
||||
enter() {
|
||||
return enter.call(this);
|
||||
enter(options) {
|
||||
return enter.call(this, options);
|
||||
}
|
||||
exit(options) {
|
||||
return exit.call(this, options);
|
||||
@@ -337,6 +556,58 @@ export class CockpitViewController {
|
||||
updateRoute(info) {
|
||||
return updateRoute.call(this, info);
|
||||
}
|
||||
updateRadar(info) {
|
||||
return updateRadar.call(this, info);
|
||||
}
|
||||
/** Step the bridge radar to its next range and redraw it at once. */
|
||||
cycleRadarRange() {
|
||||
this.radarRangeNm = nextRadarRange(this.radarRangeNm);
|
||||
if (this.active && this.subjectKind === 'vessel' && this.lastSubjectInfo)
|
||||
this.updateRadar(this.lastSubjectInfo);
|
||||
}
|
||||
presentLook() {
|
||||
return presentLook.call(this);
|
||||
}
|
||||
/**
|
||||
* Turn the bridge view one arrow step (see `lookKeyStep`). The camera
|
||||
* eases there unless the user prefers reduced motion.
|
||||
* @param {{axis: 'yaw'|'pitch', sign: number, stepDeg: number}} step
|
||||
* @returns {boolean} True when a bridge view was turned.
|
||||
*/
|
||||
turnLook(step) {
|
||||
if (!this.active || this.subjectKind !== 'vessel' || !step) return false;
|
||||
this.lookTarget = stepLook(this.lookTarget, step);
|
||||
if (prefersReducedMotion()) this.lookView = { ...this.lookTarget };
|
||||
this.presentLook();
|
||||
this.publishInstrumentsView();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Point the bridge view back over the bow at the rest pitch.
|
||||
* @param {{immediate?: boolean}} [options] Jump there instead of easing,
|
||||
* as entry and exit do.
|
||||
*/
|
||||
resetLook({ immediate = false } = {}) {
|
||||
this.lookTarget = { yawDeg: 0, pitchDeg: VESSEL_BRIDGE_PITCH_DEG };
|
||||
if (immediate || prefersReducedMotion())
|
||||
this.lookView = { ...this.lookTarget };
|
||||
this.lookLastMs = performance.now();
|
||||
this.presentLook();
|
||||
this.publishInstrumentsView();
|
||||
}
|
||||
/**
|
||||
* The LOOK AHEAD control and the Home and 0 keys: ease the bridge view
|
||||
* back over the bow. Focus leaves the button before it hides.
|
||||
* @returns {boolean} True on a bridge.
|
||||
*/
|
||||
lookAhead() {
|
||||
if (!this.active || this.subjectKind !== 'vessel') return false;
|
||||
const button = document.getElementById('cockpit-look-ahead');
|
||||
const hadFocus = !!button && button.contains(document.activeElement);
|
||||
this.resetLook();
|
||||
if (hadFocus) this.mapViewButton?.focus({ preventScroll: true });
|
||||
return true;
|
||||
}
|
||||
syncWeatherToggle(enabled) {
|
||||
return syncWeatherToggle.call(this, enabled);
|
||||
}
|
||||
@@ -426,8 +697,11 @@ export class CockpitViewController {
|
||||
onKeyDown(event) {
|
||||
return onKeyDown.call(this, event);
|
||||
}
|
||||
onSceneDoubleClick(position) {
|
||||
return onSceneDoubleClick.call(this, position);
|
||||
onSceneDoubleClick(position, nowMs) {
|
||||
return onSceneDoubleClick.call(this, position, nowMs);
|
||||
}
|
||||
onScenePointerDown(nowMs) {
|
||||
return onScenePointerDown.call(this, nowMs);
|
||||
}
|
||||
|
||||
handleSignalClick(event) {
|
||||
@@ -444,10 +718,10 @@ export class CockpitViewController {
|
||||
this.relocalizeBrief();
|
||||
this.publishVision(createVisionState(this.visionMode));
|
||||
this.routeSignature = null;
|
||||
if (this.active && this.lastAircraftInfo) {
|
||||
if (this.active && this.lastSubjectInfo) {
|
||||
this.rewordingSignals = true;
|
||||
try {
|
||||
this.updateHud(this.lastAircraftInfo, performance.now(), true);
|
||||
this.updateHud(this.lastSubjectInfo, performance.now(), true);
|
||||
} finally {
|
||||
this.rewordingSignals = false;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ import { nextTick } from 'vue';
|
||||
import { CockpitViewController, CockpitDisplayPortal } from './cockpit.js';
|
||||
import {
|
||||
COCKPIT_AIRCRAFT_LAYER_IDS,
|
||||
bridgeEntryAllowed,
|
||||
cockpitEntryAllowed,
|
||||
orbitEntryAllowed,
|
||||
} from '../contextModePolicy.js';
|
||||
import { formatAwarenessLabel } from '../data/militaryAwarenessEngine.js';
|
||||
import { enterCockpitWithTracking } from '../cockpitTracking.js';
|
||||
@@ -40,6 +42,9 @@ export class CockpitCoordinator {
|
||||
const {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
aisLiveVesselsLayer,
|
||||
satellitesLayer,
|
||||
militaryInstallationsLayer,
|
||||
isTr3b,
|
||||
toggleTr3b,
|
||||
militaryAwarenessLayer,
|
||||
@@ -54,12 +59,16 @@ export class CockpitCoordinator {
|
||||
fetchRegionalBrief,
|
||||
regionalDistanceM,
|
||||
weatherCodeLabel,
|
||||
acquireOrbitImagery,
|
||||
} = services;
|
||||
this._cockpitDisplayPortal = null;
|
||||
this.cockpitView = new CockpitViewController(viewer, {
|
||||
services: {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
aisLiveVesselsLayer,
|
||||
satellitesLayer,
|
||||
militaryInstallationsLayer,
|
||||
isTr3b,
|
||||
toggleTr3b,
|
||||
militaryAwarenessLayer,
|
||||
@@ -75,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),
|
||||
},
|
||||
@@ -93,6 +103,19 @@ export class CockpitCoordinator {
|
||||
contextModeChanging: this._contextModeChanging,
|
||||
});
|
||||
},
|
||||
isBridgeEntryAllowed: () =>
|
||||
bridgeEntryAllowed({
|
||||
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(),
|
||||
@@ -129,15 +152,21 @@ export class CockpitCoordinator {
|
||||
return Boolean(layerId) && !!this._dataManager?.isEnabled(layerId);
|
||||
}
|
||||
/**
|
||||
* Make the ridden aircraft's layer the user's own while Contacts is on.
|
||||
* Contacts may have turned that layer on, and it releases the layers it
|
||||
* owns when it goes off; the Cockpit must outlive Contacts, so riding an
|
||||
* aircraft adopts its layer as a direct selection does. Contacts then stops
|
||||
* owning it and the Context restore keeps it (session `userAdded`).
|
||||
* @param {string|null} layerId The ridden aircraft's layer.
|
||||
* Make the ridden layer the user's own while Contacts is on. Contacts may
|
||||
* have turned that layer on (an aircraft layer, or Live AIS Vessels), and
|
||||
* it releases the layers it owns when it goes off; the Cockpit must outlive
|
||||
* Contacts, so riding an aircraft or a vessel adopts its layer as a direct
|
||||
* selection does. Contacts then stops owning it and the Context restore
|
||||
* keeps it (session `userAdded`).
|
||||
* @param {string|null} layerId The ridden aircraft's layer, or
|
||||
* 'ais-live-vessels' on a bridge.
|
||||
*/
|
||||
_adoptRiddenLayer(layerId) {
|
||||
if (!COCKPIT_AIRCRAFT_LAYER_IDS.includes(layerId)) return;
|
||||
if (
|
||||
!COCKPIT_AIRCRAFT_LAYER_IDS.includes(layerId) &&
|
||||
layerId !== 'ais-live-vessels'
|
||||
)
|
||||
return;
|
||||
if (!this._isLayerEnabled('military-awareness')) return;
|
||||
this._dataManager?.adoptLayerVisibility?.(layerId, true, {
|
||||
origin: 'user',
|
||||
@@ -158,6 +187,16 @@ export class CockpitCoordinator {
|
||||
_cockpitEntryRefusal() {
|
||||
if (this._contextModeChanging)
|
||||
return 'Context is still changing — try Cockpit again in a moment';
|
||||
// Tracking an aircraft from the bridge ends the bridge and clears the
|
||||
// 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;
|
||||
@@ -167,6 +206,16 @@ export class CockpitCoordinator {
|
||||
const snapshot = militaryAwarenessLayer.getContextSnapshot?.();
|
||||
const info = this.cockpitView?.readAircraftInfo?.();
|
||||
const active = Boolean(this.cockpitView?.active);
|
||||
// Voice enters aircraft only; a bridge in use is still reported as it is.
|
||||
const vessel =
|
||||
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
|
||||
@@ -195,13 +244,30 @@ export class CockpitCoordinator {
|
||||
? 'subject-layer-off'
|
||||
: 'no-tracked-aircraft',
|
||||
visionMode: this.cockpitView?.visionMode || null,
|
||||
subject: info
|
||||
subject: satellite
|
||||
? {
|
||||
id: info.icao24 || info.id || null,
|
||||
layerId: info.layerId || null,
|
||||
callsign: info.callsign || null,
|
||||
kind: 'satellite',
|
||||
id: satellite.id,
|
||||
layerId: satellite.layerId,
|
||||
callsign: null,
|
||||
name: satellite.name,
|
||||
}
|
||||
: null,
|
||||
: vessel
|
||||
? {
|
||||
kind: 'vessel',
|
||||
id: vessel.mmsi,
|
||||
layerId: vessel.layerId,
|
||||
callsign: null,
|
||||
name: vessel.name,
|
||||
}
|
||||
: 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,
|
||||
@@ -86,6 +101,14 @@ function fixture(
|
||||
services: {
|
||||
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() {},
|
||||
@@ -120,7 +143,11 @@ function fixture(
|
||||
t.after(() => {
|
||||
coordinator.stop();
|
||||
app.unmount();
|
||||
document.body.classList.remove('cockpit-mode');
|
||||
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) => {
|
||||
@@ -157,6 +184,7 @@ test('a civilian aircraft enters with Live Flights alone: no Contacts, no Milita
|
||||
assert.equal(state.entryAllowed, true);
|
||||
assert.equal(state.entryBlockedReason, null);
|
||||
assert.equal(cockpit.enter(), true);
|
||||
assert.equal(cockpit.subjectKind, 'aircraft');
|
||||
});
|
||||
|
||||
test('a military aircraft enters with Military Flights alone', (t) => {
|
||||
@@ -197,6 +225,47 @@ test('with no aircraft layer on, entry is refused for that reason, never for Con
|
||||
assert.equal(cockpit.active, false);
|
||||
});
|
||||
|
||||
test('voice entry on a vessel bridge refuses before it touches tracking', (t) => {
|
||||
const { coordinator, cockpit } = fixture(t, { enabled: ['flights'] });
|
||||
let navigated = false;
|
||||
coordinator.services.militaryAwarenessLayer.navigateNext = () => {
|
||||
navigated = true;
|
||||
return true;
|
||||
};
|
||||
// Stand in for a bridge ride: the refusal reads only these two.
|
||||
cockpit.active = true;
|
||||
cockpit.subjectKind = 'vessel';
|
||||
t.after(() => {
|
||||
cockpit.active = false;
|
||||
cockpit.subjectKind = null;
|
||||
});
|
||||
const voice = coordinator.controlCockpit('enter', { targetLayer: 'flights' });
|
||||
assert.equal(voice.ok, false);
|
||||
assert.match(voice.error, /vessel bridge/);
|
||||
assert.equal(navigated, false, 'no aircraft was tracked');
|
||||
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(
|
||||
@@ -439,6 +508,22 @@ test('a ride handed to an aircraft on a layer Contacts turned on keeps that laye
|
||||
assert.deepEqual(on(manager), ['flights', 'military']);
|
||||
});
|
||||
|
||||
test('Live AIS Vessels, once adopted as the ridden layer, outlives Contacts', async (t) => {
|
||||
const live = await liveFixture(t, {
|
||||
tracked: { layerId: 'flights', info: CIVIL },
|
||||
});
|
||||
const { manager, controls, coordinator, settle } = live;
|
||||
assert.equal(await controls._selectContextMode('flights'), true);
|
||||
await settle();
|
||||
assert.equal(manager.isEnabled('ais-live-vessels'), true);
|
||||
// The bridge reports its layer on entry (cockpitBridge.test.mjs).
|
||||
coordinator._adoptRiddenLayer('ais-live-vessels');
|
||||
await controls._selectContextMode(null);
|
||||
await settle();
|
||||
assert.equal(controls.getContextModeState().mode, null);
|
||||
assert.deepEqual(on(manager), ['ais-live-vessels']);
|
||||
});
|
||||
|
||||
test('the ridden layer still ends the Cockpit while Contacts is on', async (t) => {
|
||||
const live = await liveFixture(t, {
|
||||
tracked: { layerId: 'flights', info: CIVIL },
|
||||
@@ -465,3 +550,101 @@ test('without a Cockpit, ending Contacts restores the layers it found', async (t
|
||||
assert.equal(controls.getContextModeState().mode, null);
|
||||
assert.deepEqual(on(manager), [], 'Live Flights goes back off');
|
||||
});
|
||||
|
||||
test('the readout entry reads BRIDGE for a selected vessel', async (t) => {
|
||||
const { $, store } = fixture(t);
|
||||
store.publishPresence({
|
||||
active: false,
|
||||
entryAvailable: true,
|
||||
entryKind: 'vessel',
|
||||
subjectKind: null,
|
||||
tr3b: null,
|
||||
});
|
||||
await nextTick();
|
||||
const readoutEntry = $('#cockpit-entry-readout');
|
||||
assert.equal(readoutEntry.hidden, false);
|
||||
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);
|
||||
});
|
||||
+154
-28
@@ -1,5 +1,6 @@
|
||||
/** Route Cockpit keys while preserving the active disclosure and form-control owner. */
|
||||
import * as Cesium from 'cesium';
|
||||
import { lookKeyStep } from '../cockpitLook.js';
|
||||
import { isPointerFree } from '../data/inputOwnership.js';
|
||||
|
||||
/** How far from the followed track a double-click may land, CSS pixels. */
|
||||
@@ -22,14 +23,35 @@ export function doubleClickHitsSubject(
|
||||
return Number.isFinite(distance) && distance <= radiusPx;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long the first press of a double-click keeps its picture of the track,
|
||||
* ms: a click on a selected ship re-centres the camera, so the ship can move
|
||||
* on screen before the second click lands.
|
||||
*/
|
||||
export const DOUBLE_CLICK_MEMORY_MS = 700;
|
||||
|
||||
/** Where the track `kind` would ride is drawn now, as a world position. */
|
||||
function subjectWorldPosition(kind) {
|
||||
if (kind !== 'aircraft') return null;
|
||||
return (
|
||||
this.viewer.trackedEntity?.position?.getValue?.(
|
||||
this.viewer.clock?.currentTime,
|
||||
) ?? null
|
||||
);
|
||||
if (kind === 'aircraft') {
|
||||
return (
|
||||
this.viewer.trackedEntity?.position?.getValue?.(
|
||||
this.viewer.clock?.currentTime,
|
||||
) ?? 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;
|
||||
// The sprite floats on the geoid, not on the ellipsoid (tens of metres
|
||||
// apart): project the height it is drawn at.
|
||||
const heightM = Number.isFinite(info.markHeightM)
|
||||
? info.markHeightM
|
||||
: Number.isFinite(info.seaSurfaceHeightM)
|
||||
? info.seaSurfaceHeightM
|
||||
: 0;
|
||||
return Cesium.Cartesian3.fromDegrees(info.longitude, info.latitude, heightM);
|
||||
}
|
||||
|
||||
/** The followed track's canvas position now, or null off screen. */
|
||||
@@ -44,21 +66,54 @@ function subjectCanvasPosition() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note where the selected ship is drawn as a press begins, for a
|
||||
* double-click whose first click moves it. The second press of the gesture
|
||||
* keeps the first one's picture: by then the first click may have moved it.
|
||||
* @param {number} [nowMs]
|
||||
*/
|
||||
export function onScenePointerDown(nowMs = performance.now()) {
|
||||
if (this.active || this.destroyed) return;
|
||||
const start = this.doubleClickStart;
|
||||
if (start && nowMs - start.atMs <= DOUBLE_CLICK_MEMORY_MS) return;
|
||||
// Only a ship moves under its own click (selecting it re-centres the
|
||||
// camera); a followed aircraft stays put, so its hit area stays its own.
|
||||
if (this.resolveEntryKind() !== 'vessel') {
|
||||
this.doubleClickStart = null;
|
||||
return;
|
||||
}
|
||||
const at = subjectCanvasPosition.call(this);
|
||||
const mmsi = this.readVesselInfo()?.mmsi ?? null;
|
||||
this.doubleClickStart = at ? { x: at.x, y: at.y, atMs: nowMs, mmsi } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter first person when the followed track itself is double-clicked: the
|
||||
* same entry, and the same gates, as C and the entry buttons. A
|
||||
* 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.
|
||||
* @param {{x: number, y: number}|null|undefined} position Canvas position.
|
||||
* @param {number} [nowMs]
|
||||
* @returns {boolean} True when it landed on the followed track, entered or
|
||||
* refused by the gate: the caller does nothing else with it.
|
||||
*/
|
||||
export function onSceneDoubleClick(position) {
|
||||
export function onSceneDoubleClick(position, nowMs = performance.now()) {
|
||||
const start = this.doubleClickStart;
|
||||
this.doubleClickStart = null;
|
||||
if (this.active || this.destroyed || !isPointerFree()) return false;
|
||||
if (!Number.isFinite(position?.x) || !Number.isFinite(position?.y))
|
||||
return false;
|
||||
if (!doubleClickHitsSubject(position, subjectCanvasPosition.call(this)))
|
||||
return false;
|
||||
const hit =
|
||||
doubleClickHitsSubject(position, subjectCanvasPosition.call(this)) ||
|
||||
(Boolean(start) &&
|
||||
nowMs - start.atMs <= DOUBLE_CLICK_MEMORY_MS &&
|
||||
// The memory is the ship's it was taken for: one followed since (an
|
||||
// aircraft, another ship) is hit only where it is drawn.
|
||||
this.resolveEntryKind() === 'vessel' &&
|
||||
start.mmsi === (this.readVesselInfo()?.mmsi ?? null) &&
|
||||
doubleClickHitsSubject(position, start));
|
||||
if (!hit) return false;
|
||||
this.enter();
|
||||
return true;
|
||||
}
|
||||
@@ -68,7 +123,8 @@ export function onSceneDoubleClick(position) {
|
||||
* 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.
|
||||
*/
|
||||
@@ -79,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);
|
||||
@@ -91,12 +150,92 @@ export function routeSceneDoubleClick() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cockpit's capture-phase keydown: Escape and C.
|
||||
* Focus inside one of these keeps its arrows (and Home): text entry, sliders,
|
||||
* tabs, radio groups, lists and menus all move with them.
|
||||
*/
|
||||
const LOOK_KEY_OWNERS = [
|
||||
'input',
|
||||
'textarea',
|
||||
'select',
|
||||
'[contenteditable]',
|
||||
'[role=combobox]',
|
||||
'[role=grid]',
|
||||
'[role=menubar]',
|
||||
'[role=menuitemcheckbox]',
|
||||
'[role=menuitemradio]',
|
||||
'[role=scrollbar]',
|
||||
'[role=searchbox]',
|
||||
'[role=slider]',
|
||||
'[role=spinbutton]',
|
||||
'[role=textbox]',
|
||||
'[role=tree]',
|
||||
'[role=treeitem]',
|
||||
'[role=tab]',
|
||||
'[role=tablist]',
|
||||
'[role=radio]',
|
||||
'[role=radiogroup]',
|
||||
'[role=listbox]',
|
||||
'[role=menu]',
|
||||
'[role=menuitem]',
|
||||
'[role=option]',
|
||||
].join(', ');
|
||||
|
||||
/**
|
||||
* Turn the bridge view with the arrow keys (Shift for 45° steps) and bring
|
||||
* it back over the bow with Home or 0. Only a bridge looks around, and only
|
||||
* while focus is on the scene or a plain HUD button.
|
||||
* @returns {boolean} True when the key was taken.
|
||||
*/
|
||||
function handleLookKey(event) {
|
||||
if (!this.active || this.subjectKind !== 'vessel') return false;
|
||||
if (event.metaKey || event.ctrlKey || event.altKey) return false;
|
||||
const step = lookKeyStep(event.key, event.shiftKey);
|
||||
const reset = !event.repeat && (event.key === 'Home' || event.key === '0');
|
||||
if (!step && !reset) return false;
|
||||
if (event.target?.closest?.(LOOK_KEY_OWNERS)) return false;
|
||||
if (this.isUtilityDisclosureOpen?.()) return false;
|
||||
event.preventDefault();
|
||||
if (step) this.turnLook(step);
|
||||
else this.lookAhead();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Zoom keys in orbit: `+` (or `=`, unshifted) in and `-` (or `_`) out. */
|
||||
const ORBITAL_ZOOM_KEYS = Object.freeze({ '+': 1, '=': 1, '-': -1, _: -1 });
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (this.destroyed) return false;
|
||||
if (event.repeat || event.isComposing) return;
|
||||
if (event.isComposing) return;
|
||||
// Held arrows turn a bridge view smoothly; every other key acts once.
|
||||
if (event.repeat && !lookKeyStep(event.key)) return;
|
||||
if (event.key === 'Escape' && this.active) {
|
||||
// The credit lightbox owns Escape while its Close control or links hold
|
||||
// focus. Its target handler closes the overlay and restores attribution
|
||||
@@ -139,19 +278,6 @@ export function onKeyDown(event) {
|
||||
}
|
||||
if (event.target?.closest?.('input, textarea, select, [contenteditable]'))
|
||||
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
|
||||
);
|
||||
if (!cockpitAttempt) return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
if (!this.active && !this.isEntryAllowed()) return;
|
||||
if (this.active) this.exit();
|
||||
else this.enter();
|
||||
return;
|
||||
}
|
||||
if (handleLookKey.call(this, event)) return;
|
||||
handleOrbitalKey.call(this, event);
|
||||
}
|
||||
@@ -52,15 +52,28 @@ function createRimState(value) {
|
||||
*/
|
||||
export function createInstrumentState() {
|
||||
return {
|
||||
// 'aircraft' or 'vessel': which readouts the HUD labels and shows.
|
||||
kind: 'aircraft',
|
||||
layer: null,
|
||||
callsign: t('AIRCRAFT'),
|
||||
meta: { text: t('LIVE TRACK · COURSE ALIGNED'), emergency: false },
|
||||
speed: null,
|
||||
altitude: null,
|
||||
// A vessel's course over ground, shown where an aircraft shows altitude.
|
||||
course: null,
|
||||
heading: null,
|
||||
// A vessel's `heading` readout is its true heading, or its course over
|
||||
// ground when it reports none: 'heading' | 'course' | null.
|
||||
trackSource: null,
|
||||
speedRim: createRimState('---'),
|
||||
altitudeRim: createRimState('-----'),
|
||||
compass: [],
|
||||
// A bridge tape's bow (prograde) and stern (retrograde) marks, in
|
||||
// division slots off its centre; null when off the tape or not a bridge.
|
||||
compassMarkers: { prograde: null, retrograde: null },
|
||||
// A bridge view turned off the bow: whether it is, the target yaw off
|
||||
// the bow (degrees, -180..180, starboard positive) and its worded readout.
|
||||
look: { offset: false, yawDeg: 0, readout: '' },
|
||||
clock: '--:--:--Z',
|
||||
position: '--° · --°',
|
||||
};
|
||||
@@ -73,6 +86,8 @@ export function createInstrumentState() {
|
||||
*/
|
||||
export function createRouteState() {
|
||||
return {
|
||||
// A vessel's card shows only the free-text AIS destination.
|
||||
kind: 'aircraft',
|
||||
visible: false,
|
||||
from: t('UNKNOWN'),
|
||||
to: t('UNKNOWN'),
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
cockpitAltitudeDisplayFt,
|
||||
cockpitUiUpdateDue,
|
||||
compassDivisions,
|
||||
compassMarkerSlot,
|
||||
scrollingCompassDivisions,
|
||||
formatAltitudeRulerTick,
|
||||
formatCompassDivision,
|
||||
formatCockpitEmergency,
|
||||
@@ -22,10 +24,23 @@ import {
|
||||
} from '../cockpitMath.js';
|
||||
import {
|
||||
COCKPIT_CONTEXT_UPDATE_MS,
|
||||
cockpitUnitCase,
|
||||
compassPointLabel,
|
||||
formatCockpitCoordinate,
|
||||
} from './cockpitPresentation.js';
|
||||
import { createVisionState } from './cockpitInstrumentState.js';
|
||||
import { unitLabel } from './unitLabels.js';
|
||||
import {
|
||||
VESSEL_BRIDGE_PITCH_DEG,
|
||||
vesselCameraProfile,
|
||||
} from '../cockpitSubjects.js';
|
||||
import { lookIsOffset, lookReadoutParts, wrapLookYaw } from '../cockpitLook.js';
|
||||
import {
|
||||
RADAR_MAX_CONTACTS,
|
||||
radarPicture,
|
||||
radarRangeM,
|
||||
radarRangeNm,
|
||||
} from '../cockpitRadar.js';
|
||||
|
||||
/** A transponder status name (src/data/aircraftEmergency.js) for the HUD. */
|
||||
const emergencyLabel = ({ name }) => t(name).toUpperCase();
|
||||
@@ -68,20 +83,73 @@ export function publishInstrumentsView() {
|
||||
meta: { ...view.meta },
|
||||
speed: view.speed && { ...view.speed },
|
||||
altitude: view.altitude && { ...view.altitude },
|
||||
course: view.course && { ...view.course },
|
||||
heading: view.heading && { ...view.heading },
|
||||
speedRim: rim(view.speedRim),
|
||||
altitudeRim: rim(view.altitudeRim),
|
||||
compass: view.compass.map((division) => ({ ...division })),
|
||||
compassMarkers: { ...view.compassMarkers },
|
||||
look: { ...view.look },
|
||||
});
|
||||
}
|
||||
|
||||
/** Word a bridge look's readout parts (see `lookReadoutParts`). */
|
||||
function wordLook({ side, bearingDeg, elevation, angleDeg }) {
|
||||
const bearing = formatHeadingReadout(bearingDeg);
|
||||
const angle = formatNumber(angleDeg);
|
||||
let direction = '';
|
||||
if (side === 'starboard') direction = t('LOOK STBD {bearing}°', { bearing });
|
||||
else if (side === 'port') direction = t('LOOK PORT {bearing}°', { bearing });
|
||||
else if (side === 'astern') direction = t('LOOK ASTERN');
|
||||
let tilt = '';
|
||||
if (elevation === 'up') tilt = t('UP {angle}°', { angle });
|
||||
else if (elevation === 'down') tilt = t('DOWN {angle}°', { angle });
|
||||
else if (elevation === 'level') tilt = t('LEVEL');
|
||||
if (direction && tilt)
|
||||
return t('{direction} · {elevation}', { direction, elevation: tilt });
|
||||
if (tilt) return t('LOOK {elevation}', { elevation: tilt });
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the bridge look target: whether the view is turned off the bow,
|
||||
* its yaw for the radar and its worded readout. Outside a bridge the look
|
||||
* always rests. The caller publishes.
|
||||
*/
|
||||
export function presentLook() {
|
||||
const target = this.lookTarget;
|
||||
const offset =
|
||||
this.active &&
|
||||
this.subjectKind === 'vessel' &&
|
||||
lookIsOffset(target, VESSEL_BRIDGE_PITCH_DEG);
|
||||
this.instruments.look = offset
|
||||
? {
|
||||
offset: true,
|
||||
yawDeg: wrapLookYaw(target.yawDeg),
|
||||
readout: wordLook(lookReadoutParts(target, VESSEL_BRIDGE_PITCH_DEG)),
|
||||
}
|
||||
: { offset: false, yawDeg: 0, readout: '' };
|
||||
}
|
||||
|
||||
export function updateHud(
|
||||
info,
|
||||
nowMs = performance.now(),
|
||||
forceContext = false,
|
||||
) {
|
||||
this.lastAircraftInfo = info;
|
||||
if (info?.kind === 'vessel') {
|
||||
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';
|
||||
view.trackSource = null;
|
||||
view.course = null;
|
||||
const heading = normalizeHeading(this.heading ?? info.track ?? 0);
|
||||
view.callsign =
|
||||
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
|
||||
@@ -128,6 +196,7 @@ export function updateHud(
|
||||
slot: index - 3,
|
||||
label: compassPointLabel(formatCompassDivision(division)),
|
||||
}));
|
||||
view.compassMarkers = { prograde: null, retrograde: null };
|
||||
view.clock = new Date().toISOString().slice(11, 19) + 'Z';
|
||||
const lat = Number.isFinite(info.latitude)
|
||||
? formatCockpitCoordinate(info.latitude, 'N', 'S')
|
||||
@@ -175,6 +244,157 @@ export function updateHud(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the bridge readouts: speed and course over ground, true heading,
|
||||
* the vessel type and its assumed eye height. Contact navigation and Live
|
||||
* Signals stay aircraft-only, so the Contact card is withdrawn.
|
||||
*/
|
||||
function updateVesselHud(info, nowMs, forceContext) {
|
||||
this.lastSubjectInfo = info;
|
||||
const view = this.instruments;
|
||||
view.kind = 'vessel';
|
||||
view.trackSource = info.trackSource ?? null;
|
||||
// A ship reporting neither heading nor course has no heading to read out
|
||||
// and no bow to mark; the tape still follows the camera.
|
||||
const headingKnown = Number.isFinite(info.track);
|
||||
const cameraHeading = normalizeHeading(this.heading ?? info.track ?? 0);
|
||||
const heading = headingKnown ? cameraHeading : null;
|
||||
view.callsign = info.name;
|
||||
const speedKt = Number.isFinite(info.speedKt)
|
||||
? Math.max(0, info.speedKt)
|
||||
: null;
|
||||
view.speed = {
|
||||
text: formatSpeedRulerTick(speedKt),
|
||||
value: speedKt,
|
||||
immediate: forceContext,
|
||||
};
|
||||
view.speedRim.unavailable = speedKt === null;
|
||||
view.speedRim.value = formatSpeedRulerTick(speedKt);
|
||||
placeRimTicks(
|
||||
view.speedRim.ticks,
|
||||
speedRulerTicks(speedKt, view.speedRim.ticks.length),
|
||||
(tick) => formatSpeedRulerTick(tick.valueKt),
|
||||
);
|
||||
view.altitude = null;
|
||||
view.altitudeRim.unavailable = true;
|
||||
const course = Number.isFinite(info.course)
|
||||
? normalizeHeading(info.course)
|
||||
: null;
|
||||
view.course = {
|
||||
text: formatHeadingReadout(course),
|
||||
value: course,
|
||||
immediate: forceContext,
|
||||
};
|
||||
view.heading = {
|
||||
text: formatHeadingReadout(heading),
|
||||
value: heading,
|
||||
immediate: forceContext,
|
||||
};
|
||||
// Looking around turns the tape with the camera; the readout above it
|
||||
// keeps the ship's heading, and the bow and stern marks stay on the ship.
|
||||
const viewHeading = normalizeHeading(
|
||||
cameraHeading + (this.lookView?.yawDeg ?? 0),
|
||||
);
|
||||
// The tape scrolls continuously, so the caret reads the view's exact
|
||||
// heading and the marks sit at their true bearings from it.
|
||||
view.compass = scrollingCompassDivisions(viewHeading).map((division) => ({
|
||||
slot: division.slot,
|
||||
heading: division.heading,
|
||||
active: division.nearest,
|
||||
label: compassPointLabel(formatCompassDivision(division.heading)),
|
||||
}));
|
||||
view.compassMarkers = headingKnown
|
||||
? {
|
||||
prograde: compassMarkerSlot(heading, viewHeading),
|
||||
retrograde: compassMarkerSlot(heading + 180, viewHeading),
|
||||
}
|
||||
: { prograde: null, retrograde: null };
|
||||
view.clock = new Date().toISOString().slice(11, 19) + 'Z';
|
||||
view.position = `${formatCockpitCoordinate(info.latitude, 'N', 'S')} · ${formatCockpitCoordinate(info.longitude, 'E', 'W')}`;
|
||||
const eyeHeightM = vesselCameraProfile(info).upM;
|
||||
view.meta.text = t('{vesselType} · {feedState} · EYE {height}', {
|
||||
vesselType: info.typeLabel || t('VESSEL'),
|
||||
feedState: info.stale ? t('STALE FEED') : t('LIVE AIS'),
|
||||
height: `${formatNumber(Math.round(eyeHeightM))} ${cockpitUnitCase(unitLabel('m'))}`,
|
||||
});
|
||||
view.meta.emergency = false;
|
||||
view.layer = info.layerId;
|
||||
// Reworded here too, so a language switch reaches the look readout.
|
||||
this.presentLook();
|
||||
this.publishInstrumentsView();
|
||||
updateVesselRoute.call(this, info);
|
||||
if (
|
||||
forceContext ||
|
||||
cockpitUiUpdateDue(
|
||||
nowMs,
|
||||
this.lastContextUpdateMs,
|
||||
COCKPIT_CONTEXT_UPDATE_MS,
|
||||
)
|
||||
) {
|
||||
this.lastContextUpdateMs = nowMs;
|
||||
this.updateLocalPosition(info);
|
||||
this.maybeRefreshRegionalBrief(info);
|
||||
this.updateRadar(info);
|
||||
this.showContextCard(false);
|
||||
this.pushCockpitSignal(
|
||||
'context-status',
|
||||
'info',
|
||||
t('CONTACT NAVIGATION OFF'),
|
||||
t('THE BRIDGE STAYS WITH THE SELECTED VESSEL'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the bridge radar: nearby AIS vessels drawn heading-up from the
|
||||
* camera's current heading, within the chosen range. Own ship sits where
|
||||
* the camera rides (its fix dead-reckoned); contacts sit at their last
|
||||
* fixes, where the vessel layer draws them, so the scope matches the
|
||||
* window.
|
||||
* @param {object} info The vessel subject (`readVesselInfo`).
|
||||
*/
|
||||
export function updateRadar(info) {
|
||||
const layer = this.services.aisLiveVesselsLayer;
|
||||
if (!info || typeof layer?.getRadarContacts !== 'function') {
|
||||
this.publishRadar(null);
|
||||
return;
|
||||
}
|
||||
const rangeNm = radarRangeNm(this.radarRangeNm);
|
||||
const own = this.vesselFix ?? info;
|
||||
const contacts = layer.getRadarContacts(
|
||||
own.latitude,
|
||||
own.longitude,
|
||||
radarRangeM(rangeNm),
|
||||
RADAR_MAX_CONTACTS,
|
||||
);
|
||||
const picture = radarPicture(
|
||||
{
|
||||
latitude: own.latitude,
|
||||
longitude: own.longitude,
|
||||
headingDeg: normalizeHeading(this.heading ?? info.track ?? 0),
|
||||
courseDeg: info.course,
|
||||
},
|
||||
contacts,
|
||||
rangeNm,
|
||||
);
|
||||
this.publishRadar({
|
||||
...picture,
|
||||
rangeLabel: t('{range} NM', { range: formatNumber(rangeNm) }),
|
||||
});
|
||||
}
|
||||
|
||||
/** Show the AIS voyage destination; it is crew-entered text, not a place. */
|
||||
function updateVesselRoute(info) {
|
||||
const route = this.routeView;
|
||||
route.kind = 'vessel';
|
||||
route.from = '';
|
||||
route.to = info.destination || t('UNKNOWN');
|
||||
route.status = t('AIS DESTINATION · CREW REPORTED');
|
||||
route.visible = Boolean(info.destination);
|
||||
// No coordinates, so no arrow; clearing also publishes the card.
|
||||
this.clearPredictiveRoute();
|
||||
}
|
||||
|
||||
/** Publish the route card and destination arrow when either changed. */
|
||||
export function publishRouteView() {
|
||||
const signature = JSON.stringify(this.routeView);
|
||||
@@ -188,6 +408,7 @@ export function publishRouteView() {
|
||||
|
||||
export function updateRoute(info) {
|
||||
const route = this.routeView;
|
||||
route.kind = 'aircraft';
|
||||
const origin = info?.route?.origin;
|
||||
const destination = info?.route?.destination;
|
||||
const validDestination =
|
||||
|
||||
@@ -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,16 +146,46 @@ export function formatCockpitWindDirection(value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Cockpit entry for each subject it can ride: an aircraft's cockpit.
|
||||
* Both entry buttons (Contacts and the Intel HUD readout) show it.
|
||||
* 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'|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,
|
||||
|
||||
@@ -6,6 +6,12 @@ import {
|
||||
resolveTrackedAircraftInfo,
|
||||
} from '../cockpitMath.js';
|
||||
|
||||
/** The camera's own heading in degrees, or 0 when it has none. */
|
||||
function cameraHeadingDeg(camera) {
|
||||
const heading = camera?.heading;
|
||||
return Number.isFinite(heading) ? (heading * 180) / Math.PI : 0;
|
||||
}
|
||||
|
||||
export function readAircraftInfo() {
|
||||
// In cockpit mode the controller takes the entity off `viewer.trackedEntity`
|
||||
// (see update()), so the cockpit's own handle is the tracked identity there.
|
||||
@@ -17,14 +23,27 @@ export function readAircraftInfo() {
|
||||
});
|
||||
}
|
||||
|
||||
/** The selected vessel the bridge view would ride, or rides; null without one. */
|
||||
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: 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'|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(':');
|
||||
@@ -32,23 +51,29 @@ export function readSubjectLayerId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The subject entry would take: a Cesium-tracked aircraft.
|
||||
* @returns {'aircraft'|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() {
|
||||
return this.readAircraftInfo() && this.viewer.trackedEntity?.position
|
||||
? 'aircraft'
|
||||
: null;
|
||||
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 || '')
|
||||
? String(info?.icao24 || info?.mmsi || info?.noradId || '')
|
||||
.trim()
|
||||
.toLowerCase() || null
|
||||
: null;
|
||||
const layerId =
|
||||
active && ['flights', 'military'].includes(info?.layerId)
|
||||
active &&
|
||||
['flights', 'military', 'ais-live-vessels', 'satellites'].includes(
|
||||
info?.layerId,
|
||||
)
|
||||
? info.layerId
|
||||
: null;
|
||||
window.dispatchEvent(
|
||||
@@ -103,17 +128,35 @@ export function syncEntry() {
|
||||
const info = this.readAircraftInfo();
|
||||
const trackedContact = !!(info && this.viewer.trackedEntity?.position);
|
||||
this.syncTr3bToggle(trackedContact ? info : null);
|
||||
const available = !!(this.isEntryAllowed() && trackedContact);
|
||||
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;
|
||||
// Change-only publishes: this runs on a preUpdate cadence, and a fresh
|
||||
// presence every frame would re-render the views even when nothing
|
||||
// changed. (perf item 9)
|
||||
if (this.presence.entryAvailable === available) return;
|
||||
if (
|
||||
this.presence.entryAvailable === available &&
|
||||
this.presence.entryKind === entryKind
|
||||
)
|
||||
return;
|
||||
this.presence.entryAvailable = available;
|
||||
this.presence.entryKind = entryKind;
|
||||
this.publishPresenceView();
|
||||
}
|
||||
|
||||
export function navigateContext(direction, options = {}) {
|
||||
if (this.destroyed) 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;
|
||||
@@ -132,6 +175,10 @@ export function navigateContext(direction, options = {}) {
|
||||
}
|
||||
|
||||
export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
// 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 ||
|
||||
@@ -160,13 +207,33 @@ export function _adoptTrackedEntity(nowMs, suppliedInfo = null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function enter() {
|
||||
/**
|
||||
* Enter first person on a tracked aircraft or, with none tracked, the
|
||||
* 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.
|
||||
*/
|
||||
export function enter({ kind = null } = {}) {
|
||||
if (this.destroyed) return false;
|
||||
if (this.active) return false;
|
||||
if (!this.isEntryAllowed()) return false;
|
||||
const info = this.readAircraftInfo();
|
||||
const entity = this.viewer.trackedEntity;
|
||||
if (!info || !entity?.position) return false;
|
||||
const subjectKind = kind ?? this.resolveEntryKind() ?? 'aircraft';
|
||||
const vessel = subjectKind === 'vessel';
|
||||
const satellite = subjectKind === 'satellite';
|
||||
const allowed = vessel
|
||||
? this.isBridgeEntryAllowed()
|
||||
: satellite
|
||||
? this.isOrbitEntryAllowed()
|
||||
: this.isEntryAllowed();
|
||||
if (!allowed) return false;
|
||||
const info = vessel
|
||||
? this.readVesselInfo()
|
||||
: satellite
|
||||
? this.readSatelliteInfo()
|
||||
: this.readAircraftInfo();
|
||||
// Only an aircraft is ridden through its Cesium entity.
|
||||
const entity = vessel || satellite ? null : this.viewer.trackedEntity;
|
||||
if (!info || (!vessel && !satellite && !entity?.position)) return false;
|
||||
this.entryFocusOrigin =
|
||||
document.activeElement instanceof HTMLElement
|
||||
? document.activeElement
|
||||
@@ -174,10 +241,31 @@ export function enter() {
|
||||
// Retire deferred navigation before cancelFlight can run its callbacks.
|
||||
this.onCameraTakeover?.();
|
||||
this.viewer.camera.cancelFlight();
|
||||
this.subjectKind = subjectKind;
|
||||
// Each session reads its own water: never a height left from the last.
|
||||
this.vesselWaterline = null;
|
||||
this.vesselFix = null;
|
||||
this.subjectId = vessel ? info.mmsi : satellite ? info.noradId : null;
|
||||
this.trackedEntity = entity;
|
||||
this.trackedEntityWasShown = entity.show;
|
||||
entity.show = false;
|
||||
this.heading = normalizeHeading(info.track ?? 0);
|
||||
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);
|
||||
}
|
||||
// A ship reporting neither heading nor course keeps the camera's own
|
||||
// heading: no direction is made up for it.
|
||||
this.heading = normalizeHeading(
|
||||
Number.isFinite(info.track)
|
||||
? info.track
|
||||
: vessel
|
||||
? cameraHeadingDeg(this.viewer.camera)
|
||||
: 0,
|
||||
);
|
||||
this.lastFrameMs = performance.now();
|
||||
this.lastCameraUpdateMs = 0;
|
||||
this.lastHudUpdateMs = 0;
|
||||
@@ -189,6 +277,8 @@ export function enter() {
|
||||
this.surfaceFallback = false;
|
||||
this.cockpitAnchorValid = false;
|
||||
this.lastCameraUpdateMs = 0;
|
||||
// Every bridge opens looking over the bow.
|
||||
this.resetLook({ immediate: true });
|
||||
this.active = true;
|
||||
// Cockpit animates the camera from preUpdate every frame — preUpdate only
|
||||
// runs on rendered frames, so idle mode would freeze the cockpit solid.
|
||||
@@ -197,33 +287,70 @@ export function enter() {
|
||||
this.viewer.trackedEntity = undefined;
|
||||
this.viewer.scene.screenSpaceCameraController.enableInputs = false;
|
||||
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;
|
||||
Object.assign(this.presence, {
|
||||
active: true,
|
||||
entryAvailable: false,
|
||||
entryKind: null,
|
||||
subjectKind,
|
||||
tr3b: null,
|
||||
});
|
||||
this.publishPresenceView();
|
||||
// Only a bridge has a radar.
|
||||
if (!vessel) this.publishRadar(null);
|
||||
this.signalItems = [];
|
||||
this.signalSignatures.clear();
|
||||
this.showBriefPage(0);
|
||||
this.startBriefRotation();
|
||||
const trackLabel =
|
||||
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
|
||||
const trackHeading = formatHeadingReadout(info.track ?? 0);
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · COURSE {heading}°', {
|
||||
label: trackLabel,
|
||||
heading: trackHeading,
|
||||
}),
|
||||
);
|
||||
if (satellite) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · NADIR VIEW', { label: info.name }),
|
||||
);
|
||||
} else if (vessel) {
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
// A ship with no true heading is held on its course over ground; one
|
||||
// with neither is named without a direction.
|
||||
info.trackSource === 'course'
|
||||
? t('{label} · COURSE {heading}°', {
|
||||
label: info.name,
|
||||
heading: trackHeading,
|
||||
})
|
||||
: info.trackSource === 'heading'
|
||||
? t('{label} · HEADING {heading}°', {
|
||||
label: info.name,
|
||||
heading: trackHeading,
|
||||
})
|
||||
: t('{label} · NO HEADING', { label: info.name }),
|
||||
);
|
||||
} else {
|
||||
const trackLabel =
|
||||
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
|
||||
this.pushCockpitSignal(
|
||||
'track',
|
||||
'track',
|
||||
t('TRACK ACQUIRED'),
|
||||
t('{label} · COURSE {heading}°', {
|
||||
label: trackLabel,
|
||||
heading: trackHeading,
|
||||
}),
|
||||
);
|
||||
}
|
||||
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(() => {
|
||||
@@ -239,10 +366,18 @@ export function enter() {
|
||||
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;
|
||||
this.vesselFix = null;
|
||||
this.subjectId = null;
|
||||
this.services.releaseContinuousRender('cockpit');
|
||||
this.trackedEntity = null;
|
||||
this.heading = null;
|
||||
this.resetLook({ immediate: true });
|
||||
this.cockpitAnchorValid = false;
|
||||
this.surfaceWaitStartedMs = 0;
|
||||
this.surfaceAcquiring = false;
|
||||
@@ -255,22 +390,40 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
this.regionalBriefAbort = null;
|
||||
this.regionalBriefRequestToken += 1;
|
||||
this.regionalBriefSubjectId = null;
|
||||
document.body.classList.remove('cockpit-mode');
|
||||
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;
|
||||
this.presence.subjectKind = null;
|
||||
this.publishPresenceView();
|
||||
this.routeView.visible = false;
|
||||
this.clearPredictiveRoute();
|
||||
this.publishRadar(null);
|
||||
this.setVisionMode('optical');
|
||||
this.viewer.scene.screenSpaceCameraController.enableInputs = true;
|
||||
if (entity && this.viewer.entities.contains(entity))
|
||||
entity.show = this.trackedEntityWasShown;
|
||||
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;
|
||||
this.restoreTrackingFrame(entity);
|
||||
} 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.
|
||||
|
||||
@@ -434,12 +434,12 @@ test('Cyber lower-left telemetry tracks the credit anchor with clearance for its
|
||||
cyberStyles,
|
||||
/#intel-hud\[data-variant='cyber'\] \.hud-bottom-left/,
|
||||
);
|
||||
const offset = telemetry.match(/bottom:\s*calc\(2vh \+ ([\d.]+)rem\);/);
|
||||
const offset = telemetry.match(/bottom:\s*calc\(2vh \+ ([\d.]+)rem \+ var\(--world-timeline-lift, 0px\)\);/);
|
||||
assert.ok(offset, 'telemetry must retain the attribution viewport anchor');
|
||||
const credits = read('./styles/command-dock-trays.css');
|
||||
const creditOffsets = [
|
||||
...credits.matchAll(
|
||||
/#cesium-credits\s*\{[^}]*bottom:\s*calc\(2vh \+ ([\d.]+)rem\);/g,
|
||||
/#cesium-credits\s*\{[^}]*bottom:\s*calc\(2vh \+ ([\d.]+)rem \+ var\(--world-timeline-lift, 0px\)\);/g,
|
||||
),
|
||||
];
|
||||
assert.ok(creditOffsets.length > 0);
|
||||
@@ -738,7 +738,7 @@ test('the Display selector, voice schema and final stylesheet expose Cyber', ()
|
||||
);
|
||||
assert.match(
|
||||
cyberStyles,
|
||||
/#left-panel-stack \{[\s\S]*?top: var\(--cyber-left-rail-top\) !important;[\s\S]*?bottom: calc\(2vh \+ 13rem\);/,
|
||||
/#left-panel-stack \{[\s\S]*?top: var\(--cyber-left-rail-top\) !important;[\s\S]*?bottom: calc\(2vh \+ 13rem \+ var\(--world-timeline-lift, 0px\)\);/,
|
||||
);
|
||||
assert.match(
|
||||
cyberStyles,
|
||||
@@ -793,7 +793,7 @@ test('the Display selector, voice schema and final stylesheet expose Cyber', ()
|
||||
cyberStyles,
|
||||
/#right-context-rail:has\(> \[data-panel-id\]:not\(\.collapsed, \[hidden\]\)\) \{\s*border-inline-end-color:/,
|
||||
);
|
||||
assert.match(cyberStyles, /bottom: calc\(2vh \+ 13rem\);/);
|
||||
assert.match(cyberStyles, /bottom: calc\(2vh \+ 13rem \+ var\(--world-timeline-lift, 0px\)\);/);
|
||||
assert.doesNotMatch(cyberStyles, /NAV 01 \/\/ COMMAND BUS \/\/ VIS 03/);
|
||||
assert.match(cyberStyles, /data-layer-id='satellites'/);
|
||||
assert.match(cyberStyles, /#search-toggle::before/);
|
||||
|
||||
+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]),
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -586,7 +586,7 @@ test('the phone shell keeps the required attribution visible', () => {
|
||||
};
|
||||
const lift = (block) =>
|
||||
Number(
|
||||
/bottom: calc\(var\(--mobile-tab-space\) \+ (\d+)px\)/.exec(block)?.[1],
|
||||
/bottom: calc\(var\(--mobile-tab-space\) \+ (\d+)px \+ var\(--world-timeline-lift, 0px\)\)/.exec(block)?.[1],
|
||||
);
|
||||
const z = (block) => Number(/z-index: (\d+);/.exec(block)?.[1]);
|
||||
const idleCredit = rule(
|
||||
|
||||
@@ -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',
|
||||
]),
|
||||
});
|
||||
@@ -32,6 +32,7 @@ const LEFT_STACK_OBSTACLE_SELECTOR = [
|
||||
'#gev-voice-control',
|
||||
'#pp-toggles',
|
||||
'#param-slider-panel',
|
||||
'#world-timeline',
|
||||
].join(', ');
|
||||
/**
|
||||
* Fixed UI regions that can occupy the right control lane. Runtime rectangle
|
||||
@@ -59,6 +60,7 @@ const RIGHT_STACK_OBSTACLE_SELECTOR = [
|
||||
'#cesium-credits .cesium-credit-textContainer',
|
||||
'#command-dock',
|
||||
'#gev-voice-control',
|
||||
'#world-timeline',
|
||||
].join(', ');
|
||||
export class PanelLayoutController {
|
||||
constructor({
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
});
|
||||
@@ -4,6 +4,16 @@ import { canPresentDeferredStatusNotice } from '../loadingFeedback.js';
|
||||
import { t, msg, formatDate } from '../i18n/index.js';
|
||||
import { SHARE_VIEW_ENTITY_KINDS } from '../share/follow.js';
|
||||
import { UiLifetime } from './uiLifetime.js';
|
||||
import { isWorldTime, worldClock } from '../time/worldClock.js';
|
||||
|
||||
// A link made away from live opens at its world time, paused. One without a
|
||||
// world time leaves the clock as it is: a page opens live, and Back or Forward
|
||||
// through long-form hashes (which never carry one) does not stop a replay.
|
||||
function applySharedWorldTime(state) {
|
||||
if (!isWorldTime(state?.worldTime)) return;
|
||||
worldClock.pause();
|
||||
worldClock.seek(state.worldTime);
|
||||
}
|
||||
|
||||
/** How long a shared vessel may take to appear in the vessel feed. */
|
||||
export const SHARED_VESSEL_WAIT_MS = 120_000;
|
||||
@@ -146,6 +156,7 @@ export class ShareRestoration {
|
||||
: Promise.resolve({ status: 'not-requested', share: null, layers: [] });
|
||||
if (savedState) {
|
||||
this._hasShareState = true;
|
||||
applySharedWorldTime(savedState);
|
||||
// Reserve camera authority now; the delayed mesh-friendly flight may
|
||||
// run only if no newer user, voice, or tracking navigation has won.
|
||||
this._initialShareNavigationGeneration =
|
||||
@@ -301,6 +312,7 @@ export class ShareRestoration {
|
||||
layers: [],
|
||||
});
|
||||
this._initialShareState = state;
|
||||
applySharedWorldTime(state);
|
||||
this._initialShareSelectionSuperseded = false;
|
||||
this._hasShareState = true;
|
||||
this._navigatedShareRestoreActive = true;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
@@ -34,7 +34,13 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
|
||||
context.value = next && markRaw(next);
|
||||
}
|
||||
|
||||
/** The presented instruments; null until the first HUD update. */
|
||||
/**
|
||||
* The presented instruments; null until the first HUD update. Besides the
|
||||
* readouts, `look: { offset, yawDeg, readout }` says whether a bridge view
|
||||
* is turned off the bow, the yaw it is turned to (degrees in -180..180,
|
||||
* starboard positive; the radar draws its look line there) and the worded
|
||||
* readout. An aircraft's look always rests (`offset: false`).
|
||||
*/
|
||||
const instruments = shallowRef(null);
|
||||
|
||||
/** @param {?object} next A fresh presentation of the instruments. */
|
||||
@@ -66,6 +72,66 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
|
||||
signals.value = next && markRaw(next);
|
||||
}
|
||||
|
||||
/**
|
||||
* The bridge radar: null outside a vessel bridge. Shape:
|
||||
* `{ rangeNm, rangeLabel, ringsNm: number[], headingDeg,
|
||||
* ownRelativeCourseDeg|null,
|
||||
* contacts: [{ id, name, x, y, distanceNm, relativeBearingDeg,
|
||||
* relativeCourseDeg|null, color, stale }] }` where x/y are heading-up
|
||||
* screen fractions in [-1, 1] (x right, y up) of the range circle.
|
||||
*/
|
||||
const radar = shallowRef(null);
|
||||
|
||||
/** @param {?object} next A fresh presentation of the bridge radar. */
|
||||
function publishRadar(next) {
|
||||
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
|
||||
@@ -101,6 +167,10 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
|
||||
publishVision,
|
||||
signals,
|
||||
publishSignals,
|
||||
radar,
|
||||
publishRadar,
|
||||
orbital,
|
||||
publishOrbital,
|
||||
utilityLayout,
|
||||
publishUtilityLayout,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { onScopeDispose, shallowRef } from 'vue';
|
||||
import { worldClock } from '../../time/worldClock.js';
|
||||
|
||||
/** How often a shown timeline moves its readout and its end on with now. */
|
||||
const LIVE_TICK_MS = 1000;
|
||||
/** A scrub this close to now, as a share of the track, is a scrub to live. */
|
||||
const LIVE_EDGE = 0.005;
|
||||
/** The least that counts as at now, past the readout's own second. */
|
||||
const LIVE_EDGE_MS = 5000;
|
||||
/** The speeds play offers, in world ms per real ms. */
|
||||
export const WORLD_TIME_SPEEDS = Object.freeze({
|
||||
real: 1,
|
||||
minute: 60,
|
||||
hour: 3_600,
|
||||
day: 86_400,
|
||||
week: 604_800,
|
||||
});
|
||||
|
||||
/**
|
||||
* The world clock as the timeline shows it: `{live, playing, stepping,
|
||||
* buffering, timeMs, supported, span}`, where `supported` says a layer that moves with the clock
|
||||
* has time to show and `span` is the stretch the timeline runs over: the
|
||||
* time those layers cover, reaching to now and to the world time, with their
|
||||
* marks. It follows the page's world clock, which tells it of every move, and
|
||||
* of the time a few times a second while it plays on its own. While a
|
||||
* timeline shows, it reads the clock each second itself, so live and the
|
||||
* track's end keep up with now.
|
||||
*/
|
||||
export const useWorldTimeStore = defineStore('gev-world-time', () => {
|
||||
// The time the layers cover, reaching to now.
|
||||
const reach = () => {
|
||||
const coverage = worldClock.coverage();
|
||||
if (!coverage) return null;
|
||||
const now = worldClock.wallNow();
|
||||
return {
|
||||
start: Math.min(coverage.start, now),
|
||||
end: Math.max(coverage.end, now),
|
||||
marks: coverage.marks,
|
||||
};
|
||||
};
|
||||
const spanOf = (state) => {
|
||||
if (!state.supported) return null;
|
||||
const covered = reach();
|
||||
if (!covered) return null;
|
||||
return Object.freeze({
|
||||
start: Math.min(covered.start, state.timeMs),
|
||||
end: Math.max(covered.end, state.timeMs),
|
||||
marks: covered.marks,
|
||||
});
|
||||
};
|
||||
const nearNow = (ms, length) =>
|
||||
Math.abs(ms - worldClock.wallNow()) <=
|
||||
Math.max(LIVE_EDGE_MS, length * LIVE_EDGE);
|
||||
// Whether the track ends at now (and moves on with it), not past it.
|
||||
const endsAtNow = (covered) =>
|
||||
covered.end - worldClock.wallNow() <= LIVE_EDGE_MS;
|
||||
// Play stops at the end of the track: at now it goes live, past now (a
|
||||
// satellite's future) it holds there.
|
||||
let stopping = false;
|
||||
const stopAtEnd = (state) => {
|
||||
if (stopping || !state.playing || state.live || !state.supported)
|
||||
return false;
|
||||
const covered = reach();
|
||||
if (!covered || state.timeMs < covered.end) return false;
|
||||
stopping = true;
|
||||
try {
|
||||
if (endsAtNow(covered)) worldClock.goLive();
|
||||
else {
|
||||
// Back to the end first, so nothing hears the overshoot as paused.
|
||||
worldClock.seek(covered.end);
|
||||
worldClock.pause();
|
||||
worldClock.seek(covered.end);
|
||||
}
|
||||
} finally {
|
||||
stopping = false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const read = (state = worldClock.getState()) =>
|
||||
Object.freeze({
|
||||
live: state.live,
|
||||
playing: state.playing,
|
||||
stepping: state.stepping,
|
||||
buffering: state.buffering,
|
||||
timeMs: state.timeMs,
|
||||
supported: state.supported,
|
||||
span: spanOf(state),
|
||||
});
|
||||
const time = shallowRef(read());
|
||||
const speed = shallowRef('real');
|
||||
const rate = () => WORLD_TIME_SPEEDS[speed.value];
|
||||
let ticker = null;
|
||||
const syncTicker = () => {
|
||||
// Playing, the clock tells of the time itself.
|
||||
const ticking = Boolean(time.value.span) && !time.value.playing;
|
||||
if (ticking && ticker === null)
|
||||
ticker = setInterval(() => {
|
||||
time.value = read();
|
||||
}, LIVE_TICK_MS);
|
||||
else if (!ticking && ticker !== null) {
|
||||
clearInterval(ticker);
|
||||
ticker = null;
|
||||
}
|
||||
};
|
||||
const unsubscribe = worldClock.subscribe((state) => {
|
||||
if (stopAtEnd(state)) return;
|
||||
time.value = read(state);
|
||||
syncTicker();
|
||||
});
|
||||
syncTicker();
|
||||
onScopeDispose(() => {
|
||||
unsubscribe();
|
||||
if (ticker !== null) clearInterval(ticker);
|
||||
ticker = null;
|
||||
});
|
||||
|
||||
return {
|
||||
time,
|
||||
/**
|
||||
* Play runs the track at the speed chosen, from the start when it is at
|
||||
* its end (at live, say), as a video plays again from the top. It runs
|
||||
* the clock itself, past weather's own replay: weather follows the time
|
||||
* frame by frame like every other layer the track covers.
|
||||
*/
|
||||
togglePlay() {
|
||||
const { playing, live, timeMs, span } = time.value;
|
||||
if (playing) return worldClock.pause();
|
||||
const covered = reach();
|
||||
if (span && covered && (live || timeMs >= covered.end))
|
||||
worldClock.seek(span.start);
|
||||
worldClock.play({ rate: rate(), continuous: true });
|
||||
},
|
||||
speed,
|
||||
/**
|
||||
* Choose how fast play runs; playing, it changes at once. Weather's own
|
||||
* replay steps at its own pace, so a speed chosen while it plays takes
|
||||
* playback over from where it is.
|
||||
*/
|
||||
setSpeed(next) {
|
||||
if (!Object.hasOwn(WORLD_TIME_SPEEDS, next)) return;
|
||||
speed.value = next;
|
||||
const { playing, stepping } = worldClock.getState();
|
||||
if (!playing) return;
|
||||
if (!stepping) return worldClock.setRate(rate());
|
||||
worldClock.pause();
|
||||
worldClock.play({ rate: rate(), continuous: true });
|
||||
},
|
||||
goLive: () => worldClock.goLive(),
|
||||
/**
|
||||
* Scrub to `ms`: playback stops where the hand puts it; at now, live.
|
||||
* How near now counts as now goes by `length`, the stretch the track
|
||||
* shows, all of the span unless it is zoomed.
|
||||
*/
|
||||
scrub(ms, length) {
|
||||
const span = time.value.span;
|
||||
length ??= span ? span.end - span.start : 0;
|
||||
if (nearNow(ms, length)) {
|
||||
worldClock.goLive();
|
||||
return;
|
||||
}
|
||||
worldClock.pause();
|
||||
worldClock.seek(ms);
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -283,6 +283,10 @@ body.cockpit-mode:has(#left-panel-stack > .panel-collapsible:not(.collapsed))
|
||||
color: var(--cockpit-accent);
|
||||
opacity: 0.9;
|
||||
}
|
||||
/* A bridge has no altitude tape; course over ground replaces the readout. */
|
||||
#cockpit-altitude-rim[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.cockpit-altitude-rim-label {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
@@ -900,7 +904,7 @@ html:not([lang='en']) .cockpit-roll-token.is-separator {
|
||||
position: fixed;
|
||||
z-index: 146;
|
||||
right: 36px;
|
||||
bottom: calc(2vh + 4.5rem);
|
||||
bottom: calc(2vh + 4.5rem + var(--world-timeline-lift, 0px));
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
@@ -2079,7 +2083,7 @@ body.cockpit-mode #intel-hud .hud-right-edge {
|
||||
@media (max-width: 760px) {
|
||||
#view-switcher {
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
bottom: calc(16px + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
body.cockpit-mode #view-switcher {
|
||||
right: auto;
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
/* Ship bridge
|
||||
A vessel's bridge reads as a wheelhouse window rather than an aircraft
|
||||
visor: straight mullions, a straight speed tape and heading tape, square
|
||||
panels, and a radar console in the bottom-right corner. Every rule is
|
||||
scoped to the bridge, so the aircraft cockpit keeps its keyhole. */
|
||||
#cockpit-hud[data-subject='vessel'] {
|
||||
--cockpit-radar-size: 240px;
|
||||
--cockpit-radar-label-height: 28px;
|
||||
--cockpit-radar-right: clamp(24px, 4vw, 58px);
|
||||
/* Above the position readout, which sits above the language picker. */
|
||||
--cockpit-radar-bottom: calc(max(clamp(22px, 4vh, 42px), 3.5rem) + 40px);
|
||||
/* From the viewport bottom to clear above the console (border + gap). */
|
||||
--cockpit-radar-clearance: calc(
|
||||
var(--cockpit-radar-bottom) + var(--cockpit-radar-size) +
|
||||
var(--cockpit-radar-label-height) + 14px
|
||||
);
|
||||
}
|
||||
:root[data-ui-theme='cyber'] #cockpit-hud[data-subject='vessel'] {
|
||||
--cockpit-radar-right: 30px;
|
||||
}
|
||||
:root[data-ui-theme='cyber'] #cockpit-hud[data-subject='vessel']::before {
|
||||
clip-path: none;
|
||||
}
|
||||
:root:not([data-ui-theme='cyber']) body.cockpit-bridge {
|
||||
--panel-radius: 2px;
|
||||
--btn-radius: 2px;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-bridge-frame {
|
||||
display: block;
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
color: color-mix(in srgb, var(--cockpit-accent) 32%, transparent);
|
||||
stroke-width: 1;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-bridge-frame path {
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-reticle {
|
||||
width: 36px;
|
||||
height: 14px;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
color: transparent;
|
||||
background:
|
||||
linear-gradient(var(--cockpit-accent), var(--cockpit-accent)) 50% 0 / 1px
|
||||
100% no-repeat,
|
||||
linear-gradient(90deg, var(--cockpit-accent), var(--cockpit-accent)) 0 50% /
|
||||
100% 1px no-repeat;
|
||||
font-size: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-reticle::before,
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-reticle::after {
|
||||
display: none;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-horizon-guide {
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-horizon-guide span,
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-visor-status {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* Speed over ground: a straight vertical tape beside the left pane post. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-speed-rim {
|
||||
top: 22vh;
|
||||
right: auto;
|
||||
left: calc(27vw + 14px);
|
||||
width: 150px;
|
||||
height: 46vh;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-label {
|
||||
top: 0;
|
||||
right: auto;
|
||||
left: 0;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
:is(.cockpit-altitude-rim-rail, .cockpit-altitude-rim-scale) {
|
||||
inset: 18px 0 0;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-rail {
|
||||
background: linear-gradient(90deg, rgba(0, 7, 12, 0.3), transparent 70%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-rail::before {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 0;
|
||||
height: auto;
|
||||
border: 0;
|
||||
border-left: 2px solid
|
||||
color-mix(in srgb, var(--cockpit-accent) 72%, transparent);
|
||||
border-radius: 0;
|
||||
box-shadow: -3px 0 12px
|
||||
color-mix(in srgb, var(--cockpit-accent) 18%, transparent);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-scale
|
||||
> span {
|
||||
left: 2px;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-pointer {
|
||||
z-index: 1;
|
||||
top: calc(50% + 9px);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-speed-rim
|
||||
.cockpit-altitude-rim-pointer
|
||||
strong {
|
||||
min-width: 0;
|
||||
padding: 2px 5px;
|
||||
border: 1px solid var(--cockpit-accent);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.78);
|
||||
}
|
||||
|
||||
/* Heading: a straight horizontal tape under flat readouts. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass {
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] :is(.cockpit-speed, .cockpit-altitude) {
|
||||
transform: none;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-tape {
|
||||
height: 44px;
|
||||
margin-top: 0;
|
||||
overflow: hidden;
|
||||
/* The minor ticks below scroll by a fraction of the tape's width. */
|
||||
container-type: inline-size;
|
||||
transform-style: flat;
|
||||
-webkit-mask-image: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
#000 12% 88%,
|
||||
transparent
|
||||
);
|
||||
mask-image: linear-gradient(90deg, transparent, #000 12% 88%, transparent);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-tape::before {
|
||||
inset: 0 0 auto;
|
||||
height: 26px;
|
||||
border-top: 1px solid
|
||||
color-mix(in srgb, var(--cockpit-accent) 78%, transparent);
|
||||
border-bottom: 1px solid
|
||||
color-mix(in srgb, var(--cockpit-accent) 22%, transparent);
|
||||
border-radius: 0;
|
||||
/* Minor ticks every 10 degrees, centred on the 30-degree divisions. */
|
||||
background:
|
||||
linear-gradient(
|
||||
90deg,
|
||||
transparent calc(50% - 0.5px),
|
||||
color-mix(in srgb, var(--cockpit-accent) 46%, transparent)
|
||||
calc(50% - 0.5px) calc(50% + 0.5px),
|
||||
transparent calc(50% + 0.5px)
|
||||
)
|
||||
50% 0 / calc(14% / 3) 6px repeat-x,
|
||||
rgba(0, 7, 12, 0.34);
|
||||
/* Scrolled with the divisions (--tape-shift slots of 14% each). */
|
||||
background-position:
|
||||
calc(50% + var(--tape-shift, 0) * 14cqw) 0,
|
||||
0 0;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-tape span {
|
||||
top: 0;
|
||||
left: calc(50% + (var(--slot) * 14%));
|
||||
font-size: 11px;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-tape span::before {
|
||||
height: 10px;
|
||||
margin: 0 auto 5px;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-tape span.active {
|
||||
font-size: 15px;
|
||||
}
|
||||
/* The tape follows the look; the bow (prograde: a ring and centre dot) and
|
||||
stern (retrograde: a ring and cross) marks sit under it at the ship's
|
||||
heading and its reciprocal. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-marker {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: calc(50% + (var(--slot) * 14%));
|
||||
box-sizing: border-box;
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
border: 1.5px solid var(--cockpit-accent);
|
||||
border-radius: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-marker::before,
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-retrograde::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
background: var(--cockpit-accent);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-prograde::before {
|
||||
width: 3px;
|
||||
height: 3px;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-retrograde::before,
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-retrograde::after {
|
||||
width: 1.5px;
|
||||
height: 9px;
|
||||
transform: translate(-50%, -50%) rotate(45deg);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass-retrograde::after {
|
||||
transform: translate(-50%, -50%) rotate(-45deg);
|
||||
}
|
||||
|
||||
/* Square panels and buttons. */
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
:is(
|
||||
.cockpit-vision-controls,
|
||||
.cockpit-vision-controls button,
|
||||
.cockpit-card-actions button,
|
||||
.cockpit-utility-glyph,
|
||||
.cockpit-radio-transport button,
|
||||
.cockpit-route-direction small,
|
||||
#cockpit-brief-auto
|
||||
) {
|
||||
border-radius: 2px;
|
||||
}
|
||||
body.cockpit-bridge #view-switcher button {
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
/* The briefing card sits flat and shorter, above the radar console. Its top
|
||||
leaves the utility strip room below the REC readout. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-signal-window {
|
||||
bottom: var(--cockpit-radar-clearance);
|
||||
max-height: max(
|
||||
44px,
|
||||
min(30vh, 280px, calc(100vh - var(--cockpit-radar-clearance) - 290px))
|
||||
);
|
||||
border-radius: 2px;
|
||||
transform: none;
|
||||
}
|
||||
/* Cyber anchors the card's top from the layout pass; bound its height. */
|
||||
:root[data-ui-theme='cyber']
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-signal-window {
|
||||
bottom: auto;
|
||||
max-height: max(
|
||||
44px,
|
||||
min(
|
||||
30vh,
|
||||
280px,
|
||||
calc(
|
||||
100vh - var(--cockpit-signal-top, clamp(255px, 28vh, 300px)) -
|
||||
var(--cockpit-radar-clearance)
|
||||
)
|
||||
)
|
||||
);
|
||||
clip-path: none;
|
||||
}
|
||||
|
||||
/* The radar console: CockpitRadar fills it, label row included. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-radar-console {
|
||||
position: absolute;
|
||||
z-index: 4;
|
||||
right: var(--cockpit-radar-right);
|
||||
bottom: var(--cockpit-radar-bottom);
|
||||
display: grid;
|
||||
width: var(--cockpit-radar-size);
|
||||
height: calc(var(--cockpit-radar-size) + var(--cockpit-radar-label-height));
|
||||
overflow: hidden;
|
||||
border: 1px solid color-mix(in srgb, var(--cockpit-accent) 30%, transparent);
|
||||
border-top-color: color-mix(in srgb, var(--cockpit-accent) 64%, transparent);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.68);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.04),
|
||||
0 0 28px rgba(0, 0, 0, 0.26);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
pointer-events: auto;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-radar-console:has(> .cockpit-radar[hidden]) {
|
||||
display: none;
|
||||
}
|
||||
:root[data-ui-theme='cyber']
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-radar-console {
|
||||
border-color: rgba(105, 203, 209, 0.34);
|
||||
border-top-color: rgba(196, 84, 84, 0.82);
|
||||
background:
|
||||
linear-gradient(135deg, rgba(105, 203, 209, 0.07), transparent 38%),
|
||||
rgba(8, 23, 27, 0.78);
|
||||
}
|
||||
|
||||
@media (min-width: 761px) {
|
||||
/* The heading tape narrows to stay clear of the console. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-compass {
|
||||
width: min(
|
||||
760px,
|
||||
72vw,
|
||||
calc(
|
||||
100vw - 2 *
|
||||
(var(--cockpit-radar-right) + var(--cockpit-radar-size) + 24px)
|
||||
)
|
||||
);
|
||||
}
|
||||
:root[data-ui-theme='cyber']
|
||||
#cockpit-hud[data-subject='vessel']
|
||||
.cockpit-compass {
|
||||
width: min(
|
||||
650px,
|
||||
56vw,
|
||||
calc(
|
||||
100vw - 2 *
|
||||
(var(--cockpit-radar-right) + var(--cockpit-radar-size) + 24px)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@media (min-width: 761px) and (min-height: 601px) {
|
||||
/* The console takes the intel HUD's bottom-right corner. */
|
||||
body.cockpit-bridge #intel-hud .hud-bottom-right {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@media (max-width: 1280px), (max-height: 820px) {
|
||||
#cockpit-hud[data-subject='vessel'] {
|
||||
--cockpit-radar-size: 192px;
|
||||
--cockpit-radar-label-height: 24px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
#cockpit-hud[data-subject='vessel'] {
|
||||
--cockpit-radar-size: 152px;
|
||||
--cockpit-radar-label-height: 22px;
|
||||
}
|
||||
}
|
||||
/* Too small for a console: the briefing card returns to its usual place. */
|
||||
@media (max-width: 760px), (max-height: 600px) {
|
||||
#cockpit-hud[data-subject='vessel'] {
|
||||
--cockpit-radar-clearance: var(--cockpit-bottom-rail-safe);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-radar-console {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Look around: the readout and LOOK AHEAD control sit beside the radar
|
||||
console, out of the forward view, while the view is turned off the bow;
|
||||
the radar scope draws the matching look line. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look {
|
||||
position: absolute;
|
||||
right: calc(var(--cockpit-radar-right) + var(--cockpit-radar-size) + 14px);
|
||||
bottom: var(--cockpit-radar-bottom);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 6px;
|
||||
opacity: 0.78;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look:focus-within,
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
/* Without the console, the controls take its corner. */
|
||||
@media (max-width: 760px), (max-height: 600px) {
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look {
|
||||
right: var(--cockpit-radar-right);
|
||||
}
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look[hidden] {
|
||||
display: none;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look-readout {
|
||||
padding: 2px 6px;
|
||||
border: 1px solid color-mix(in srgb, var(--cockpit-accent) 46%, transparent);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.62);
|
||||
color: var(--cockpit-accent);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.12em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look-ahead {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 8px;
|
||||
border: 1px solid color-mix(in srgb, var(--cockpit-accent) 64%, transparent);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.78);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.14em;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look-ahead:hover {
|
||||
border-color: var(--cockpit-accent);
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-look-ahead:focus-visible {
|
||||
outline: 2px solid var(--cockpit-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
/* A narrow wedge from own ship with a line along its centre, eased with the
|
||||
camera's turn. Both point up (ahead) before rotation. */
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-radar-look {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 50%;
|
||||
background: conic-gradient(
|
||||
from -6deg,
|
||||
color-mix(in srgb, var(--cockpit-accent) 18%, transparent) 0deg 12deg,
|
||||
transparent 12deg
|
||||
);
|
||||
pointer-events: none;
|
||||
transition: transform 180ms ease-out;
|
||||
}
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-radar-look::before {
|
||||
position: absolute;
|
||||
bottom: 50%;
|
||||
left: 50%;
|
||||
width: 0;
|
||||
height: 50%;
|
||||
border-left: 1px dashed
|
||||
color-mix(in srgb, var(--cockpit-accent) 80%, transparent);
|
||||
content: '';
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
#cockpit-hud[data-subject='vessel'] .cockpit-radar-look {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/* Bridge radar internals (src/ui/views/panels/CockpitRadar.vue). The
|
||||
Cockpit view places and sizes the console; the radar fills it, with a
|
||||
square scope as large as the smaller side allows. */
|
||||
.cockpit-radar {
|
||||
--radar-line: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 34%,
|
||||
transparent
|
||||
);
|
||||
--radar-faint: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 16%,
|
||||
transparent
|
||||
);
|
||||
--radar-readout-height: 22px;
|
||||
container-type: size;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
color: rgba(244, 251, 255, 0.82);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
.cockpit-radar[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.cockpit-radar-scope {
|
||||
position: relative;
|
||||
flex: none;
|
||||
width: min(100cqw, calc(100cqh - var(--radar-readout-height) - 4px));
|
||||
aspect-ratio: 1;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--radar-line);
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(
|
||||
circle,
|
||||
rgba(0, 24, 32, 0.72) 0%,
|
||||
rgba(0, 9, 14, 0.82) 100%
|
||||
);
|
||||
box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.cockpit-radar-ring,
|
||||
.cockpit-radar-sweep,
|
||||
.cockpit-radar-own,
|
||||
.cockpit-radar-contact {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
}
|
||||
.cockpit-radar-ring {
|
||||
border: 1px solid var(--radar-faint);
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.cockpit-radar-tick {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
.cockpit-radar-tick::before {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
width: 1px;
|
||||
height: 5px;
|
||||
background: var(--radar-line);
|
||||
content: '';
|
||||
}
|
||||
.cockpit-radar-tick-major::before {
|
||||
height: 8px;
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 62%,
|
||||
transparent
|
||||
);
|
||||
}
|
||||
.cockpit-radar-sweep {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: -50% 0 0 -50%;
|
||||
border-radius: 50%;
|
||||
/* The bright edge leads clockwise; the trail fades behind it. */
|
||||
background: conic-gradient(
|
||||
transparent 0deg 270deg,
|
||||
color-mix(in srgb, var(--cockpit-accent, #00dcff) 4%, transparent) 300deg,
|
||||
color-mix(in srgb, var(--cockpit-accent, #00dcff) 26%, transparent) 357deg,
|
||||
color-mix(in srgb, var(--cockpit-accent, #00dcff) 70%, transparent) 360deg
|
||||
);
|
||||
will-change: transform;
|
||||
}
|
||||
.cockpit-radar-heading-line {
|
||||
position: absolute;
|
||||
bottom: 50%;
|
||||
left: 50%;
|
||||
width: 1px;
|
||||
height: 50%;
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--cockpit-accent, #00dcff) 72%,
|
||||
transparent
|
||||
);
|
||||
}
|
||||
.cockpit-radar-own {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
margin: -3.5px 0 0 -3.5px;
|
||||
border: 1px solid var(--cockpit-accent, #00dcff);
|
||||
border-radius: 1px;
|
||||
background: rgba(0, 9, 14, 0.9);
|
||||
}
|
||||
.cockpit-radar-contact {
|
||||
--radar-contact-color: #9fb3c8;
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
margin: -2.5px 0 0 -2.5px;
|
||||
border-radius: 50%;
|
||||
background: var(--radar-contact-color);
|
||||
box-shadow: 0 0 4px var(--radar-contact-color);
|
||||
will-change: opacity;
|
||||
}
|
||||
.cockpit-radar-contact-stale {
|
||||
border: 1px solid var(--radar-contact-color);
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
/* A course vector starts at the mark's centre and points along the course. */
|
||||
.cockpit-radar-vector {
|
||||
position: absolute;
|
||||
bottom: 50%;
|
||||
left: 50%;
|
||||
width: 1px;
|
||||
height: 9px;
|
||||
margin-left: -0.5px;
|
||||
background: var(--radar-contact-color);
|
||||
transform-origin: 50% 100%;
|
||||
}
|
||||
.cockpit-radar-own-vector {
|
||||
height: 14px;
|
||||
background: #f4fbff;
|
||||
}
|
||||
.cockpit-radar-readout {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: var(--radar-readout-height);
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.cockpit-radar-range {
|
||||
flex: none;
|
||||
min-width: 44px;
|
||||
height: 20px;
|
||||
padding: 0 6px;
|
||||
border: 1px solid var(--radar-line);
|
||||
border-radius: 2px;
|
||||
background: rgba(0, 7, 12, 0.6);
|
||||
color: #f4fbff;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
}
|
||||
.cockpit-radar-range:hover,
|
||||
.cockpit-radar-range:focus-visible {
|
||||
border-color: var(--cockpit-accent, #00dcff);
|
||||
color: #fff;
|
||||
outline: none;
|
||||
}
|
||||
.cockpit-radar-rings,
|
||||
.cockpit-radar-count {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.cockpit-radar-count {
|
||||
color: var(--cockpit-accent, #00dcff);
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.cockpit-radar-sweep {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@@ -377,15 +377,15 @@
|
||||
|
||||
/* Compact dock clearance keeps the reference-like low profile. */
|
||||
body:not(.ui-clean-view):not(.recording-mode) #cesium-credits {
|
||||
bottom: calc(2vh + 4.7rem);
|
||||
bottom: calc(2vh + 4.7rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-left {
|
||||
bottom: calc(2vh + 5.4rem);
|
||||
bottom: calc(2vh + 5.4rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-bar {
|
||||
bottom: calc(2vh + 8.9rem);
|
||||
bottom: calc(2vh + 8.9rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
|
||||
@@ -455,7 +455,7 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
)
|
||||
#cesium-credits {
|
||||
right: auto;
|
||||
bottom: calc(2vh + 5rem);
|
||||
bottom: calc(2vh + 5rem + var(--world-timeline-lift, 0px));
|
||||
left: 1.5rem;
|
||||
width: auto !important;
|
||||
max-width: calc(100vw - 3rem);
|
||||
@@ -464,21 +464,21 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
|
||||
#intel-hud[data-variant='tactical'] .hud-bottom-left,
|
||||
#intel-hud[data-variant='tactical'] .hud-bottom-right {
|
||||
bottom: calc(2vh + 6.5rem);
|
||||
bottom: calc(2vh + 6.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-left {
|
||||
bottom: calc(2vh + 5.4rem);
|
||||
bottom: calc(2vh + 5.4rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
:root[data-scope-mask='off']
|
||||
#intel-hud[data-variant='minimal']
|
||||
.hud-bottom-left {
|
||||
bottom: calc(2vh + 6.5rem);
|
||||
bottom: calc(2vh + 6.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-bar {
|
||||
bottom: calc(2vh + 9rem);
|
||||
bottom: calc(2vh + 9rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
@@ -487,7 +487,7 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
#intel-hud[data-variant='minimal'].active
|
||||
)
|
||||
#cesium-credits {
|
||||
bottom: calc(2vh + 5rem);
|
||||
bottom: calc(2vh + 5rem + var(--world-timeline-lift, 0px));
|
||||
left: 0.75rem;
|
||||
max-width: calc(100vw - 1.5rem);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#command-dock {
|
||||
position: fixed;
|
||||
right: auto;
|
||||
bottom: 2vh;
|
||||
/* Above the world timeline while it shows (world-timeline.css). */
|
||||
bottom: calc(2vh + var(--world-timeline-lift, 0px));
|
||||
left: 50%;
|
||||
z-index: 145;
|
||||
display: grid;
|
||||
@@ -216,7 +217,7 @@
|
||||
|
||||
/* Keep required map attribution clear of the full-width command surface. */
|
||||
body:not(.ui-clean-view):not(.recording-mode) #cesium-credits {
|
||||
bottom: calc(2vh + 7rem);
|
||||
bottom: calc(2vh + 7rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
@@ -244,11 +245,11 @@ body.recording-mode #cesium-credits {
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-left {
|
||||
bottom: calc(2vh + 7.5rem);
|
||||
bottom: calc(2vh + 7.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-bar {
|
||||
bottom: calc(2vh + 11.5rem);
|
||||
bottom: calc(2vh + 11.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
@@ -275,21 +276,21 @@ body.recording-mode #cesium-credits {
|
||||
}
|
||||
|
||||
body:not(.ui-clean-view):not(.recording-mode) #cesium-credits {
|
||||
bottom: calc(2vh + 9.5rem);
|
||||
bottom: calc(2vh + 9.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-left {
|
||||
bottom: calc(2vh + 12rem);
|
||||
bottom: calc(2vh + 12rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='minimal'] .hud-bottom-bar {
|
||||
bottom: calc(2vh + 16rem);
|
||||
bottom: calc(2vh + 16rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
#command-dock {
|
||||
bottom: 8px;
|
||||
bottom: calc(8px + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#command-dock .location-search-wrap {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1590,7 +1590,7 @@
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='cyber'] .hud-bottom-bar {
|
||||
bottom: calc(2vh + 9.8rem);
|
||||
bottom: calc(2vh + 9.8rem + var(--world-timeline-lift, 0px));
|
||||
width: min(48vw, 680px);
|
||||
}
|
||||
|
||||
@@ -1601,13 +1601,13 @@
|
||||
|
||||
#intel-hud[data-variant='cyber'] .hud-bottom-left,
|
||||
#intel-hud[data-variant='cyber'] .hud-bottom-right {
|
||||
bottom: calc(2vh + 6.5rem);
|
||||
bottom: calc(2vh + 6.5rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
/* Attribution's logo row extends above its text baseline. Reserve the whole
|
||||
row plus a gap above the dock-relative 2vh + 5rem credit position. */
|
||||
#intel-hud[data-variant='cyber'] .hud-bottom-left {
|
||||
bottom: calc(2vh + 7.75rem);
|
||||
bottom: calc(2vh + 7.75rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
#intel-hud[data-variant='cyber'] .hud-corner {
|
||||
@@ -1652,7 +1652,7 @@
|
||||
below its 650px threshold. Keep the left rail inside the same telemetry
|
||||
and attribution-safe floor while its panel bodies take over scrolling. */
|
||||
:root[data-ui-theme='cyber'] #left-panel-stack {
|
||||
bottom: calc(2vh + 13rem);
|
||||
bottom: calc(2vh + 13rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@
|
||||
/* The stack holds still, so its rail needs no offset (leftPanelRail.js). */
|
||||
--panel-stack-top-pinned: 1;
|
||||
top: var(--cyber-left-rail-top) !important;
|
||||
bottom: calc(2vh + 13rem);
|
||||
bottom: calc(2vh + 13rem + var(--world-timeline-lift, 0px));
|
||||
inset-inline-start: calc(54px + var(--panel-rail-clearance));
|
||||
width: 300px;
|
||||
padding-inline-start: 10px;
|
||||
|
||||
@@ -200,7 +200,7 @@ body.mobile-shell #command-dock {
|
||||
/* The dock's tray rules size voice by this basis; a column makes it a height. */
|
||||
--dock-voice-width: auto;
|
||||
top: auto;
|
||||
bottom: calc(var(--mobile-tab-space) + 10px);
|
||||
bottom: calc(var(--mobile-tab-space) + 10px + var(--world-timeline-lift, 0px));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
@@ -380,7 +380,7 @@ body.mobile-shell #command-dock #gev-voice-control {
|
||||
body.mobile-shell:not(.recording-mode):not(.cockpit-mode):not(.ui-clean-view)
|
||||
#cesium-credits {
|
||||
right: auto;
|
||||
bottom: calc(var(--mobile-tab-space) + 106px) !important;
|
||||
bottom: calc(var(--mobile-tab-space) + 106px + var(--world-timeline-lift, 0px)) !important;
|
||||
left: 10px;
|
||||
/* With the base rule's nowrap the credits run off the right edge, and a
|
||||
max-width alone wrapped them into a narrow column: the line needs wrapping
|
||||
@@ -407,7 +407,7 @@ body.mobile-shell[data-mobile-sheet]:not(.recording-mode):not(
|
||||
/* The view switcher clears the tab bar and the voice bar, opposite the credit. */
|
||||
body.mobile-shell:not(.cockpit-mode) #view-switcher {
|
||||
right: 12px;
|
||||
bottom: calc(var(--mobile-tab-space) + 106px);
|
||||
bottom: calc(var(--mobile-tab-space) + 106px + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
|
||||
body.mobile-shell #corner-actions {
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
drawn straight over the notice. Track the credit's own anchor instead
|
||||
and the 12px of clear air holds regardless of height; the rail already
|
||||
scrolls (overflow-y below), so it loses reach, not content. */
|
||||
bottom: calc(2vh + 7.5rem);
|
||||
bottom: calc(2vh + 7.5rem + var(--world-timeline-lift, 0px));
|
||||
left: 16px;
|
||||
width: auto;
|
||||
max-height: none;
|
||||
|
||||
@@ -390,7 +390,7 @@ html:not([lang='en']) #global-loading-detail {
|
||||
/* ── Toast Notification ──────────────────────── */
|
||||
#toast {
|
||||
position: fixed;
|
||||
bottom: 100px;
|
||||
bottom: calc(100px + var(--world-timeline-lift, 0px));
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(20px);
|
||||
z-index: 200;
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
/* ── World timeline ─────────────────────────── */
|
||||
/* Shown while a layer with time to show is on, centred along the bottom of
|
||||
the screen; the command dock and what sits above it rise by its height. */
|
||||
:root {
|
||||
--world-timeline-lift: 0px;
|
||||
}
|
||||
|
||||
/* The bar and the time's bubble over its handle. */
|
||||
body:has(#world-timeline) {
|
||||
--world-timeline-lift: 66px;
|
||||
}
|
||||
|
||||
/* Clean view, recording and the cockpit put the dock away; the bar goes too. */
|
||||
body.ui-clean-view,
|
||||
body.recording-mode,
|
||||
body.cockpit-mode {
|
||||
--world-timeline-lift: 0px !important;
|
||||
}
|
||||
|
||||
body.ui-clean-view #world-timeline,
|
||||
body.recording-mode #world-timeline,
|
||||
body.cockpit-mode #world-timeline {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Time runs left to right in every language, so the handle, the fill, the
|
||||
ticks and the bubble agree under a right-to-left page too. */
|
||||
#world-timeline {
|
||||
direction: ltr;
|
||||
position: fixed;
|
||||
bottom: 2vh;
|
||||
left: 50%;
|
||||
z-index: 146;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: min(820px, calc(100vw - 24px));
|
||||
height: 42px;
|
||||
box-sizing: border-box;
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--glass-border);
|
||||
border-radius: 10px;
|
||||
background: var(--glass-bg);
|
||||
backdrop-filter: blur(24px) saturate(1.4);
|
||||
-webkit-backdrop-filter: blur(24px) saturate(1.4);
|
||||
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-play,
|
||||
#world-timeline .world-timeline-live {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 32px;
|
||||
height: 32px;
|
||||
padding: 0 8px;
|
||||
border: 1px solid rgba(123, 189, 211, 0.28);
|
||||
border-radius: 8px;
|
||||
background: rgba(0, 212, 255, 0.08);
|
||||
color: var(--text-primary);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-play:hover,
|
||||
#world-timeline .world-timeline-live:hover {
|
||||
background: rgba(0, 212, 255, 0.18);
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-live.is-live {
|
||||
border-color: rgba(0, 212, 255, 0.6);
|
||||
background: rgba(0, 212, 255, 0.2);
|
||||
color: var(--accent);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-live {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-speed {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* The time rides over the handle. It slides across itself as the handle
|
||||
crosses the track (its start at the handle at the track's start, its end at
|
||||
the end), so however wide its date it stays within the track. */
|
||||
#world-timeline .world-timeline-time {
|
||||
--inset: 0px;
|
||||
position: absolute;
|
||||
bottom: calc(100% + 6px);
|
||||
left: calc(var(--inset) + (100% - var(--inset)) * var(--at));
|
||||
padding: 2px 8px;
|
||||
border: 1px solid rgba(0, 212, 255, 0.4);
|
||||
border-radius: 6px;
|
||||
background: var(--glass-bg);
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
transform: translateX(calc(var(--at) * -100%));
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Playing, held while a layer loads the time's data: a spinner by the time. */
|
||||
#world-timeline .world-timeline-time.is-waiting {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-spinner {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.2);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: world-timeline-spin 0.9s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes world-timeline-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
#world-timeline .world-timeline-spinner {
|
||||
animation: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
}
|
||||
|
||||
/* The track: ticks for each launch or frame, the elapsed fill, and a native
|
||||
range input on top for dragging and the keyboard. */
|
||||
#world-timeline .world-timeline-track {
|
||||
position: relative;
|
||||
/* Two fingers pinch the track, not the page. */
|
||||
touch-action: none;
|
||||
flex: 1 1 auto;
|
||||
cursor: pointer;
|
||||
min-width: 80px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
/* Zoomed, the track's ends fade, as it goes on past them. */
|
||||
#world-timeline .world-timeline-track.is-zoomed::before {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(123, 189, 211, 0.22) 12px,
|
||||
rgba(123, 189, 211, 0.22) calc(100% - 12px),
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-track::before {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
left: 0;
|
||||
height: 4px;
|
||||
border-radius: 2px;
|
||||
background: rgba(123, 189, 211, 0.22);
|
||||
content: '';
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-fill {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
height: 4px;
|
||||
border-radius: 2px;
|
||||
background: var(--accent);
|
||||
opacity: 0.7;
|
||||
transform: translateY(-50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-tick {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
width: 2px;
|
||||
height: 12px;
|
||||
margin-left: -1px;
|
||||
border-radius: 1px;
|
||||
background: rgba(0, 212, 255, 0.75);
|
||||
transform: translateY(-50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Zoomed, the track drags along. */
|
||||
#world-timeline .world-timeline-track.is-zoomed {
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-track.is-zoomed:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
/* Only the handle takes the pointer as a slider; the track around it takes
|
||||
taps, drags and pinches itself. */
|
||||
#world-timeline .world-timeline-scrub {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
appearance: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-webkit-slider-thumb {
|
||||
cursor: ew-resize;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-moz-range-thumb {
|
||||
cursor: ew-resize;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* The time dragged off the track: the handle waits at its edge, unseen. */
|
||||
#world-timeline .world-timeline-scrub.is-off-view::-webkit-slider-thumb {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub.is-off-view::-moz-range-thumb {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-webkit-slider-runnable-track {
|
||||
height: 100%;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-moz-range-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-webkit-slider-thumb {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
margin-top: 5px;
|
||||
border: 2px solid var(--accent);
|
||||
border-radius: 50%;
|
||||
background: #031018;
|
||||
box-shadow: 0 0 8px rgba(0, 212, 255, 0.6);
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-moz-range-thumb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 2px solid var(--accent);
|
||||
border-radius: 50%;
|
||||
background: #031018;
|
||||
}
|
||||
|
||||
/* A finger needs a bigger handle. */
|
||||
@media (pointer: coarse) {
|
||||
#world-timeline .world-timeline-scrub::-webkit-slider-thumb {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub::-moz-range-thumb {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
#world-timeline .world-timeline-scrub:focus-visible {
|
||||
outline: 1px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
#world-timeline {
|
||||
bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* On phones the bar sits just above the tab bar, under the voice dock, with
|
||||
the track and the speed on a row of their own beneath play and live. */
|
||||
body.mobile-shell:has(#world-timeline) {
|
||||
--world-timeline-lift: 80px;
|
||||
}
|
||||
|
||||
body.mobile-shell #world-timeline {
|
||||
bottom: calc(var(--mobile-tab-space) + 6px);
|
||||
flex-wrap: wrap;
|
||||
row-gap: 4px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* The bubble rises into the first row, clear of play on its left. */
|
||||
body.mobile-shell #world-timeline .world-timeline-time {
|
||||
--inset: 48px;
|
||||
}
|
||||
|
||||
/* The speed sits on the track's row, a full-size target beside it. */
|
||||
body.mobile-shell #world-timeline .world-timeline-track {
|
||||
order: 1;
|
||||
flex: 1 1 calc(100% - 96px);
|
||||
}
|
||||
|
||||
body.mobile-shell #world-timeline .world-timeline-live {
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
|
||||
body.mobile-shell #world-timeline .world-timeline-speed {
|
||||
order: 2;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ 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';
|
||||
|
||||
@@ -23,13 +25,48 @@ import CockpitUtilityControls from './panels/CockpitUtilityControls.vue';
|
||||
const { presence, instruments, route, vision, utilityLayout } =
|
||||
storeToRefs(useCockpitStore());
|
||||
const active = computed(() => Boolean(presence.value?.active));
|
||||
// A vessel subject swaps the aviation readouts for bridge ones.
|
||||
const bridge = computed(() => presence.value?.subjectKind === 'vessel');
|
||||
// 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')
|
||||
: orbital.value
|
||||
? t('Satellite orbital view')
|
||||
: t('Aircraft cockpit view'),
|
||||
);
|
||||
const exitLabel = computed(() =>
|
||||
bridge.value
|
||||
? t('Exit bridge view')
|
||||
: orbital.value
|
||||
? t('Exit orbital view')
|
||||
: t('Exit cockpit view'),
|
||||
);
|
||||
const exitText = computed(() =>
|
||||
bridge.value
|
||||
? t('EXIT BRIDGE')
|
||||
: orbital.value
|
||||
? t('EXIT ORBIT')
|
||||
: t('EXIT COCKPIT'),
|
||||
);
|
||||
const globe = useGlobeActionsStore();
|
||||
const { resetBusy } = storeToRefs(globe);
|
||||
const initialInstruments = createInstrumentState();
|
||||
const initialRoute = createRouteState();
|
||||
const initialVision = createVisionState();
|
||||
const hud = computed(() => instruments.value ?? initialInstruments);
|
||||
// The bridge tape scrolls continuously: its minor ticks shift with the
|
||||
// division nearest the caret.
|
||||
const tapeShift = computed(
|
||||
() => hud.value.compass?.find((division) => division.active)?.slot ?? 0,
|
||||
);
|
||||
const direction = computed(() => (route.value ?? initialRoute).direction);
|
||||
// Where a bridge view is turned; an aircraft's always rests.
|
||||
const look = computed(() => hud.value.look ?? initialInstruments.look);
|
||||
const v = computed(() => vision.value ?? initialVision);
|
||||
const visionLabel = computed(() =>
|
||||
t('Current cockpit vision style: {style}. Activate for next style.', {
|
||||
@@ -54,11 +91,22 @@ const tickStyle = (tick) =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Aircraft first-person view. It can be entered from the visible view switcher. -->
|
||||
<section id="cockpit-hud" :aria-label="t('Aircraft cockpit view')" :hidden="!active" :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. -->
|
||||
<svg class="cockpit-frame-lines" viewBox="0 0 1200 720" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
||||
Decorative only; telemetry and interactive panels remain separate.
|
||||
A bridge looks out through straight window mullions instead: a header
|
||||
beam, two pane posts and the sill either side of the console. -->
|
||||
<svg v-if="bridge" class="cockpit-frame-lines cockpit-bridge-frame" viewBox="0 0 1200 720" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
||||
<g fill="none" stroke="currentColor">
|
||||
<path d="M0 96H1200 M0 101H1200"/>
|
||||
<path d="M324 101V600 M876 101V600"/>
|
||||
<path d="M0 600H324 M876 600H1200"/>
|
||||
</g>
|
||||
</svg>
|
||||
<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"/>
|
||||
@@ -68,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 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"/>
|
||||
@@ -100,8 +148,9 @@ const tickStyle = (tick) =>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="cockpit-visor-shell" aria-hidden="true">
|
||||
<div class="cockpit-roll-arc">
|
||||
<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>
|
||||
<span style="--slot:-2;--depth:2">−20</span>
|
||||
<span style="--slot:-1;--depth:1">−10</span>
|
||||
@@ -110,10 +159,10 @@ const tickStyle = (tick) =>
|
||||
<span style="--slot:2;--depth:2">+20</span>
|
||||
<span style="--slot:3;--depth:3">+30</span>
|
||||
</div>
|
||||
<div class="cockpit-pitch-rail cockpit-pitch-rail-left">
|
||||
<div v-if="!bridge" class="cockpit-pitch-rail cockpit-pitch-rail-left">
|
||||
<span>+20</span><span>+10</span><span class="active">00</span><span>−10</span><span>−20</span>
|
||||
</div>
|
||||
<div class="cockpit-pitch-rail cockpit-pitch-rail-right">
|
||||
<div v-if="!bridge" class="cockpit-pitch-rail cockpit-pitch-rail-right">
|
||||
<span>+20</span><span>+10</span><span class="active">00</span><span>−10</span><span>−20</span>
|
||||
</div>
|
||||
<div class="cockpit-horizon-guide">
|
||||
@@ -125,11 +174,11 @@ const tickStyle = (tick) =>
|
||||
</svg>
|
||||
<small id="cockpit-route-direction-label">{{ direction.label }}</small>
|
||||
</div>
|
||||
<div class="cockpit-visor-status cockpit-visor-status-left">{{ t('OPTICAL PLANE · 01') }}</div>
|
||||
<div class="cockpit-visor-status cockpit-visor-status-right">{{ t('VISOR LOCK · ACTIVE') }}</div>
|
||||
<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 }">
|
||||
<span class="cockpit-altitude-rim-label">{{ t('GROUND SPEED · KTS') }}</span>
|
||||
<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">
|
||||
<span v-for="(tick, index) in hud.speedRim.ticks" :key="index" data-speed-rim-tick :hidden="tick.hidden" :class="{ major: tick.major }" :style="tickStyle(tick)"><b>{{ tick.label }}</b><i></i></span>
|
||||
@@ -139,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" 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">
|
||||
@@ -152,7 +201,7 @@ const tickStyle = (tick) =>
|
||||
</div>
|
||||
<div class="cockpit-topline">
|
||||
<div>
|
||||
<span class="cockpit-kicker">{{ t('FIRST PERSON') }}</span>
|
||||
<span class="cockpit-kicker">{{ bridge ? t('BRIDGE VIEW') : t('FIRST PERSON') }}</span>
|
||||
<strong id="cockpit-callsign">{{ hud.callsign }}</strong>
|
||||
<span id="cockpit-aircraft-meta" v-class-toggle="{ emergency: hud.meta.emergency }" class="cockpit-aircraft-meta">{{ hud.meta.text }}</span>
|
||||
</div>
|
||||
@@ -171,32 +220,48 @@ const tickStyle = (tick) =>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cockpit-reticle material-symbols-outlined" aria-hidden="true">my_location</div>
|
||||
<div class="cockpit-compass" :aria-label="t('Current aircraft heading')">
|
||||
<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>
|
||||
<button id="cockpit-look-ahead" type="button" class="cockpit-look-ahead" :aria-label="t('Look ahead: turn the bridge view back to the bow')" :title="t('Look ahead (Home or 0)')" aria-keyshortcuts="Home 0">
|
||||
<span>{{ t('LOOK AHEAD') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<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">{{ t('GROUND SPEED') }}</span>
|
||||
<span class="cockpit-readout-label">{{ bridge ? t('SPEED OVER GROUND') : t('GROUND SPEED') }}</span>
|
||||
<CockpitRollingValue id="cockpit-speed-value" tag="strong" :reading="hud.speed" placeholder="---" />
|
||||
<span class="cockpit-readout-unit">{{ t('KTS') }}</span>
|
||||
</div>
|
||||
<div class="cockpit-heading-value"><CockpitRollingValue id="cockpit-heading-value" :reading="hud.heading" placeholder="---" :circular-range="360" /><small>°</small></div>
|
||||
<div class="cockpit-readout cockpit-altitude">
|
||||
<div v-if="bridge" class="cockpit-readout cockpit-altitude cockpit-course">
|
||||
<span class="cockpit-readout-label">{{ t('COURSE OVER GROUND') }}</span>
|
||||
<CockpitRollingValue id="cockpit-course-value" tag="strong" :reading="hud.course" placeholder="---" :circular-range="360" />
|
||||
<span class="cockpit-readout-unit">°</span>
|
||||
</div>
|
||||
<div v-else class="cockpit-readout cockpit-altitude">
|
||||
<span class="cockpit-readout-label">{{ t('ALTITUDE') }}</span>
|
||||
<CockpitRollingValue id="cockpit-altitude-value" tag="strong" :reading="hud.altitude" placeholder="-----" />
|
||||
<span class="cockpit-readout-unit">{{ t('FT') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<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"><span v-for="division in hud.compass" :key="division.slot" :class="division.slot === 0 ? 'active' : ''" :style="{ '--slot': division.slot, '--depth': Math.abs(division.slot) }">{{ division.label }}</span></div>
|
||||
<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>
|
||||
<CockpitContext />
|
||||
<CockpitBriefing />
|
||||
<!-- The bridge radar's console: bottom right, below the briefing card. -->
|
||||
<div v-if="bridge" class="cockpit-radar-console">
|
||||
<CockpitRadar />
|
||||
</div>
|
||||
<CockpitUtilityControls />
|
||||
<div class="cockpit-help"><bdi>{{ t('ESC EXIT') }}</bdi> <span>·</span> <bdi>{{ t('C TOGGLE') }}</bdi></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')">
|
||||
@@ -204,9 +269,9 @@ 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="t('Exit cockpit view')" aria-keyshortcuts="Escape C" :title="t('Exit cockpit view')" :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>{{ t('EXIT COCKPIT') }}</span>
|
||||
<span>{{ exitText }}</span>
|
||||
</button>
|
||||
</nav>
|
||||
</template>
|
||||
@@ -20,8 +20,8 @@ import { cockpitEntryFace } from '../cockpitPresentation.js';
|
||||
// publishes them; until it does, the panel shows its initial markup.
|
||||
const { view: ctx } = storeToRefs(useContextStore());
|
||||
const { presence: cockpit } = storeToRefs(useCockpitStore());
|
||||
// The entry rides the tracked aircraft (cockpitEntryFace).
|
||||
const entry = computed(() => cockpitEntryFace('aircraft'));
|
||||
// The entry names the subject it would ride (cockpitEntryFace).
|
||||
const entry = computed(() => cockpitEntryFace(cockpit.value?.entryKind));
|
||||
// While the Bhote Koshi event is on, its panel is the rail's only content.
|
||||
const { panel: bhotePanel } = storeToRefs(useBhoteKoshiPanelStore());
|
||||
// The Scene runtime chip SceneControls presents while a scene plays.
|
||||
|
||||
@@ -16,8 +16,8 @@ const view = computed(() => hud.value ?? EMPTY);
|
||||
// button, so first person needs no Contacts panel. The Cockpit controller
|
||||
// answers its clicks.
|
||||
const { presence: cockpit } = storeToRefs(useCockpitStore());
|
||||
// The entry rides the tracked aircraft (cockpitEntryFace).
|
||||
const entry = computed(() => cockpitEntryFace('aircraft'));
|
||||
// The entry names the subject it would ride (cockpitEntryFace).
|
||||
const entry = computed(() => cockpitEntryFace(cockpit.value?.entryKind));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -18,6 +18,7 @@ import ScreenAnnotations from './panels/ScreenAnnotations.vue';
|
||||
import AwarenessDirection from './panels/AwarenessDirection.vue';
|
||||
import UiButton from '../kit/UiButton.vue';
|
||||
import GlobeActions from './panels/GlobeActions.vue';
|
||||
import WorldTimeline from './panels/WorldTimeline.vue';
|
||||
|
||||
// The ACTIVE STYLE corner shows the style VisualSettings publishes.
|
||||
const { style } = storeToRefs(useDisplayStore());
|
||||
@@ -117,4 +118,5 @@ const vToastText = {
|
||||
<MissionReplayOverlay />
|
||||
<ScreenAnnotations />
|
||||
<AwarenessDirection />
|
||||
<WorldTimeline />
|
||||
</template>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,164 @@
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { formatNumber, t, tn } from '../../../i18n/index.js';
|
||||
import { useCockpitStore } from '../../stores/cockpit.js';
|
||||
|
||||
// The bridge radar: a heading-up scope of nearby AIS vessels, with a line
|
||||
// where the bridge view looks when it is turned off the bow. The Cockpit
|
||||
// controller presents them as positions on the range circle and keeps the
|
||||
// range button's listener; this view draws them. The sweep and each
|
||||
// contact's afterglow are compositor animations sharing one clock, so a
|
||||
// contact brightens as the sweep crosses its bearing without a frame loop.
|
||||
|
||||
/** One sweep turn, in milliseconds. */
|
||||
const SWEEP_MS = 4000;
|
||||
/** Relative bearings of the rim ticks. */
|
||||
const RIM_TICKS = Array.from({ length: 12 }, (_, index) => index * 30);
|
||||
const SWEEP_FRAMES = [
|
||||
{ transform: 'rotate(0turn)' },
|
||||
{ transform: 'rotate(1turn)' },
|
||||
];
|
||||
const GLOW_FRAMES = [
|
||||
{ opacity: 1, offset: 0 },
|
||||
{ opacity: 0.6, offset: 0.2 },
|
||||
{ opacity: 0.25, offset: 1 },
|
||||
];
|
||||
|
||||
const { radar, instruments } = storeToRefs(useCockpitStore());
|
||||
|
||||
// The bridge view's look line: the yaw the view is turned to off the bow,
|
||||
// kept unwrapped so its turn eases the short way across astern. Unwrapping
|
||||
// needs the last angle shown, so it is state a watch keeps, not a computed.
|
||||
const lookDeg = ref(null);
|
||||
watch(
|
||||
() => {
|
||||
const look = instruments.value?.look;
|
||||
return look?.offset && look.yawDeg !== 0 ? look.yawDeg : null;
|
||||
},
|
||||
(yawDeg) => {
|
||||
if (yawDeg === null) {
|
||||
lookDeg.value = null;
|
||||
return;
|
||||
}
|
||||
const from = lookDeg.value ?? 0;
|
||||
lookDeg.value = from + ((((yawDeg - from) % 360) + 540) % 360) - 180;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const motionQuery =
|
||||
typeof window.matchMedia === 'function'
|
||||
? window.matchMedia('(prefers-reduced-motion: reduce)')
|
||||
: null;
|
||||
const reducedMotion = ref(Boolean(motionQuery?.matches));
|
||||
const onMotionChange = (event) => {
|
||||
reducedMotion.value = event.matches;
|
||||
};
|
||||
motionQuery?.addEventListener?.('change', onMotionChange);
|
||||
onBeforeUnmount(() =>
|
||||
motionQuery?.removeEventListener?.('change', onMotionChange),
|
||||
);
|
||||
|
||||
/**
|
||||
* Run an element's sweep-phased animation, or stop it (`phaseMs` null).
|
||||
* Each animation starts on the document timeline at its phase, so every
|
||||
* one keeps time with the sweep however late it was created.
|
||||
*/
|
||||
function phase(el, frames, phaseMs) {
|
||||
if (phaseMs === null || typeof el.animate !== 'function') {
|
||||
el._radarAnimation?.cancel();
|
||||
el._radarAnimation = null;
|
||||
return;
|
||||
}
|
||||
if (!el._radarAnimation) {
|
||||
el._radarAnimation = el.animate(frames, {
|
||||
duration: SWEEP_MS,
|
||||
iterations: Infinity,
|
||||
easing: 'linear',
|
||||
});
|
||||
// Cancelling on unmount rejects `finished`; nothing waits on it.
|
||||
el._radarAnimation.finished?.catch(() => {});
|
||||
}
|
||||
// Before zero, so the animation is already running at page start.
|
||||
const startTime = phaseMs - SWEEP_MS;
|
||||
if (el._radarAnimation.startTime !== startTime)
|
||||
el._radarAnimation.startTime = startTime;
|
||||
}
|
||||
|
||||
const vSweep = {
|
||||
mounted: (el) => phase(el, SWEEP_FRAMES, 0),
|
||||
unmounted: (el) => phase(el, SWEEP_FRAMES, null),
|
||||
};
|
||||
|
||||
const vAfterglow = {
|
||||
mounted: (el, { value }) => phase(el, GLOW_FRAMES, value),
|
||||
updated: (el, { value }) => phase(el, GLOW_FRAMES, value),
|
||||
unmounted: (el) => phase(el, GLOW_FRAMES, null),
|
||||
};
|
||||
|
||||
/** When in the sweep's turn a bearing is crossed, or null when steady. */
|
||||
function glowPhase(relativeBearingDeg) {
|
||||
if (reducedMotion.value) return null;
|
||||
const clockwise = (((relativeBearingDeg % 360) + 360) % 360) / 360;
|
||||
return Math.round(clockwise * SWEEP_MS);
|
||||
}
|
||||
|
||||
const percent = (fraction) => `${(fraction * 100).toFixed(2)}%`;
|
||||
const contactStyle = (contact) => ({
|
||||
left: percent(0.5 + contact.x / 2),
|
||||
top: percent(0.5 - contact.y / 2),
|
||||
'--radar-contact-color': contact.color || undefined,
|
||||
});
|
||||
const rotate = (deg) => ({ transform: `rotate(${deg}deg)` });
|
||||
|
||||
const rangeLabel = computed(() => radar.value?.rangeLabel ?? '');
|
||||
const ringFractions = computed(() =>
|
||||
radar.value
|
||||
? radar.value.ringsNm.map((ring) => ring / radar.value.rangeNm)
|
||||
: [],
|
||||
);
|
||||
const ringLabel = computed(() =>
|
||||
radar.value?.ringsNm.length
|
||||
? t('RINGS {spacing} NM', {
|
||||
spacing: formatNumber(radar.value.ringsNm[0]),
|
||||
})
|
||||
: '',
|
||||
);
|
||||
const countLabel = computed(() => {
|
||||
const count = radar.value?.contacts.length ?? 0;
|
||||
return tn(count, '{count} CONTACT', '{count} CONTACTS', {
|
||||
count: formatNumber(count),
|
||||
});
|
||||
});
|
||||
const rangeAction = computed(() =>
|
||||
t('Radar range {range}. Select for the next range.', {
|
||||
range: rangeLabel.value,
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section id="cockpit-radar" class="cockpit-radar" :aria-label="t('Bridge radar')" :hidden="!radar">
|
||||
<div class="cockpit-radar-scope" aria-hidden="true">
|
||||
<template v-if="radar">
|
||||
<span v-for="fraction in ringFractions" :key="fraction" class="cockpit-radar-ring" :style="{ width: percent(fraction), height: percent(fraction) }"></span>
|
||||
<span v-for="tick in RIM_TICKS" :key="tick" class="cockpit-radar-tick" :class="{ 'cockpit-radar-tick-major': tick % 90 === 0 }" :style="rotate(tick)"></span>
|
||||
<span v-if="!reducedMotion" v-sweep class="cockpit-radar-sweep"></span>
|
||||
<span class="cockpit-radar-heading-line"></span>
|
||||
<span v-if="lookDeg !== null" class="cockpit-radar-look" :style="rotate(lookDeg)"></span>
|
||||
<span v-for="contact in radar.contacts" :key="contact.id" v-afterglow="glowPhase(contact.relativeBearingDeg)" class="cockpit-radar-contact" :class="{ 'cockpit-radar-contact-stale': contact.stale }" :style="contactStyle(contact)">
|
||||
<span v-if="contact.relativeCourseDeg !== null" class="cockpit-radar-vector" :style="rotate(contact.relativeCourseDeg)"></span>
|
||||
</span>
|
||||
<span class="cockpit-radar-own">
|
||||
<span v-if="radar.ownRelativeCourseDeg !== null && radar.ownRelativeCourseDeg !== undefined" class="cockpit-radar-vector cockpit-radar-own-vector" :style="rotate(radar.ownRelativeCourseDeg)"></span>
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
<div class="cockpit-radar-readout">
|
||||
<button id="cockpit-radar-range" type="button" class="cockpit-radar-range" :aria-label="rangeAction" :title="rangeAction">{{ rangeLabel }}</button>
|
||||
<span class="cockpit-radar-rings">{{ ringLabel }}</span>
|
||||
<span class="cockpit-radar-count">{{ countLabel }}</span>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -14,17 +14,17 @@ const r = computed(() => route.value ?? initial);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section id="cockpit-route" class="cockpit-route-card" :aria-label="t('Estimated flight plan')" :hidden="!r.visible">
|
||||
<section id="cockpit-route" class="cockpit-route-card" :aria-label="r.kind === 'vessel' ? t('Reported voyage') : t('Estimated flight plan')" :hidden="!r.visible">
|
||||
<div class="cockpit-route-heading">
|
||||
<span class="cockpit-route-kicker">{{ t('ESTIMATED FLIGHT PLAN') }}</span>
|
||||
<span class="cockpit-route-kicker">{{ r.kind === 'vessel' ? t('REPORTED VOYAGE') : t('ESTIMATED FLIGHT PLAN') }}</span>
|
||||
<small id="cockpit-route-status">{{ r.status }}</small>
|
||||
</div>
|
||||
<div class="cockpit-route-endpoints">
|
||||
<div class="cockpit-route-airport">
|
||||
<div v-if="r.kind !== 'vessel'" class="cockpit-route-airport">
|
||||
<span>{{ t('FROM') }}</span>
|
||||
<strong id="cockpit-route-from">{{ r.from }}</strong>
|
||||
</div>
|
||||
<span class="cockpit-route-arrow material-symbols-outlined" aria-hidden="true">east</span>
|
||||
<span v-if="r.kind !== 'vessel'" class="cockpit-route-arrow material-symbols-outlined" aria-hidden="true">east</span>
|
||||
<div class="cockpit-route-airport">
|
||||
<span>{{ t('TO') }}</span>
|
||||
<strong id="cockpit-route-to">{{ r.to }}</strong>
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,548 @@
|
||||
// The world timeline shows the world time while a layer with time to show is
|
||||
// on, with play and pause on the left and the way back to live on the right.
|
||||
import '../../../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createApp, nextTick } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import { worldClock } from '../../../time/worldClock.js';
|
||||
import WorldTimeline from './WorldTimeline.vue';
|
||||
import { useWorldTimeStore } from '../../stores/worldTime.js';
|
||||
|
||||
function mount(t) {
|
||||
document.body.replaceChildren();
|
||||
const pinia = createPinia();
|
||||
const app = createApp(WorldTimeline).use(pinia);
|
||||
app.mount(document.body.appendChild(document.createElement('div')));
|
||||
t.after(() => {
|
||||
app.unmount();
|
||||
// The store outlives the view; dispose it with its clock subscription.
|
||||
useWorldTimeStore(pinia).$dispose();
|
||||
worldClock.goLive();
|
||||
});
|
||||
return () => document.getElementById('world-timeline');
|
||||
}
|
||||
|
||||
// A layer that moves with the clock and has an hour of frames.
|
||||
function supportingLayer(t, at) {
|
||||
const release = worldClock.hold('test-radar');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-radar',
|
||||
coverage: () => ({ start: at - 3_600_000, end: at }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
return () => {
|
||||
unregister();
|
||||
release();
|
||||
};
|
||||
}
|
||||
|
||||
test('the timeline shows live, and plays, pauses and goes back', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.UTC(2026, 9, 30, 6, 15, 42);
|
||||
supportingLayer(t, at);
|
||||
await nextTick();
|
||||
assert.ok(bar(), 'shown while live');
|
||||
const live = bar().querySelector('.world-timeline-live');
|
||||
assert.equal(live.disabled, true, 'already live');
|
||||
assert.equal(live.getAttribute('aria-pressed'), 'true');
|
||||
|
||||
worldClock.seek(at);
|
||||
await nextTick();
|
||||
assert.ok(bar());
|
||||
const time = bar().querySelector('time');
|
||||
assert.equal(time.getAttribute('datetime'), new Date(at).toISOString());
|
||||
assert.match(time.textContent, /UTC$/);
|
||||
const play = bar().querySelector('.world-timeline-play');
|
||||
assert.equal(play.getAttribute('aria-label'), 'Play');
|
||||
|
||||
play.click();
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), true);
|
||||
assert.equal(play.getAttribute('aria-label'), 'Pause');
|
||||
play.click();
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), false);
|
||||
|
||||
assert.equal(bar().querySelector('.world-timeline-live').disabled, false);
|
||||
bar().querySelector('.world-timeline-live').click();
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), true);
|
||||
assert.ok(bar(), 'still shown, live');
|
||||
assert.equal(bar().querySelector('.world-timeline-live').disabled, true);
|
||||
});
|
||||
|
||||
test('the timeline hides while no layer with time to show is on', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.UTC(2026, 9, 30, 6, 15, 42);
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'live, nothing to play');
|
||||
worldClock.seek(at);
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'away from live, but nothing to play');
|
||||
const remove = supportingLayer(t, at);
|
||||
await nextTick();
|
||||
assert.ok(bar());
|
||||
remove();
|
||||
await nextTick();
|
||||
assert.equal(bar(), null, 'the layer went off');
|
||||
});
|
||||
|
||||
test('the track runs over the time the layers show, to now, and scrubs', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const at = now - 2 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start: at - 86_400_000, end: at, marks: [at - 86_400_000, at] }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
assert.equal(Number(input.min), at - 86_400_000);
|
||||
assert.ok(Number(input.max) >= now, 'reaches to now');
|
||||
assert.equal(bar().querySelectorAll('.world-timeline-tick').length, 2);
|
||||
|
||||
worldClock.play();
|
||||
input.value = String(at);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), false, 'a scrub stops playback');
|
||||
assert.equal(worldClock.now(), at);
|
||||
assert.equal(bar().querySelector('time').getAttribute('datetime'), new Date(at).toISOString());
|
||||
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), at - 86_400_000, 'the arrow goes to the previous mark');
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.now(), at, 'and back to the next');
|
||||
|
||||
input.value = String(Date.now() + 2_000);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), true, 'a scrub to now goes live');
|
||||
|
||||
// A layer that reaches ahead of now, as satellites do.
|
||||
const holdAhead = worldClock.hold('test-ahead');
|
||||
const unregisterAhead = worldClock.register({
|
||||
id: 'test-ahead',
|
||||
coverage: () => ({ start: now, end: now + 3 * 86_400_000 }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterAhead();
|
||||
holdAhead();
|
||||
});
|
||||
await nextTick();
|
||||
const ahead = Date.now() + 86_400_000;
|
||||
input.value = String(ahead);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), false, 'a scrub past now stays there');
|
||||
assert.equal(worldClock.now(), ahead);
|
||||
});
|
||||
|
||||
test('play runs in real time, from the start of the track when at live', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 10 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start, end: now - 86_400_000 }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
// Weather's replay stepping its own frames does not take the track's play.
|
||||
const stepped = [];
|
||||
const driver = worldClock.attachDriver({
|
||||
play: () => stepped.push('play'),
|
||||
pause: () => stepped.push('pause'),
|
||||
});
|
||||
t.after(() => driver.detach());
|
||||
bar().querySelector('.world-timeline-play').click();
|
||||
worldClock.pause();
|
||||
await nextTick();
|
||||
assert.deepEqual(stepped, []);
|
||||
const rate = worldClock.getRate();
|
||||
assert.ok(worldClock.now() - start < rate * 1_000, 'from the start of the track');
|
||||
assert.equal(rate, 1, 'real time to start with');
|
||||
worldClock.play({ continuous: true });
|
||||
|
||||
// Playing on to now goes live.
|
||||
worldClock.seek(Date.now() + 1_000);
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), true);
|
||||
assert.equal(worldClock.isPlaying(), false);
|
||||
assert.equal(worldClock.getRate(), 1, 'live plays at the rate of the world');
|
||||
});
|
||||
|
||||
test('play holds at the end of a track that reaches past now', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
// An hour ahead is within the track's share of now, but still ahead of it.
|
||||
const end = now + 3_600_000;
|
||||
const release = worldClock.hold('test-ahead');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-ahead',
|
||||
coverage: () => ({ start: now - 10 * 86_400_000, end }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
// Paused just past now, play plays on rather than from the top.
|
||||
worldClock.seek(Date.now() + 1_000);
|
||||
await nextTick();
|
||||
const from = worldClock.now();
|
||||
bar().querySelector('.world-timeline-play').click();
|
||||
worldClock.pause();
|
||||
assert.ok(worldClock.now() >= from, 'plays on from where it was');
|
||||
worldClock.play();
|
||||
worldClock.seek(end + 60_000);
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), false);
|
||||
assert.equal(worldClock.isLive(), false);
|
||||
assert.equal(worldClock.now(), end);
|
||||
});
|
||||
|
||||
test('the speed chosen sets how fast play runs, at once while playing', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start: now - 10 * 86_400_000, end: now - 86_400_000 }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const select = bar().querySelector('select.world-timeline-speed');
|
||||
assert.equal(select.value, 'real');
|
||||
assert.deepEqual(
|
||||
[...select.options].map((option) => option.value),
|
||||
['real', 'minute', 'hour', 'day', 'week'],
|
||||
);
|
||||
select.value = 'week';
|
||||
select.dispatchEvent(new Event('change'));
|
||||
await nextTick();
|
||||
bar().querySelector('.world-timeline-play').click();
|
||||
assert.equal(worldClock.getRate(), 604_800, 'a week a second');
|
||||
select.value = 'hour';
|
||||
select.dispatchEvent(new Event('change'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isPlaying(), true);
|
||||
assert.equal(worldClock.getRate(), 3_600, 'changed while playing');
|
||||
select.value = 'minute';
|
||||
select.dispatchEvent(new Event('change'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.getRate(), 60, 'a minute a second');
|
||||
select.value = 'real';
|
||||
select.dispatchEvent(new Event('change'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.getRate(), 1, 'the world as it goes');
|
||||
});
|
||||
|
||||
test('a speed chosen while weather replay steps takes playback over', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.now() - 3_600_000;
|
||||
supportingLayer(t, at);
|
||||
const calls = [];
|
||||
const driver = worldClock.attachDriver({
|
||||
play() {
|
||||
calls.push('play');
|
||||
driver.driven(true, at - 600_000);
|
||||
},
|
||||
pause() {
|
||||
calls.push('pause');
|
||||
driver.driven(false);
|
||||
},
|
||||
});
|
||||
t.after(() => driver.detach());
|
||||
worldClock.play();
|
||||
await nextTick();
|
||||
assert.equal(worldClock.getState().stepping, true);
|
||||
const select = bar().querySelector('select.world-timeline-speed');
|
||||
select.value = 'hour';
|
||||
select.dispatchEvent(new Event('change'));
|
||||
await nextTick();
|
||||
assert.deepEqual(calls, ['play', 'pause']);
|
||||
assert.equal(worldClock.getState().stepping, false);
|
||||
assert.equal(worldClock.isPlaying(), true);
|
||||
assert.equal(worldClock.getRate(), 3_600);
|
||||
assert.ok(worldClock.now() - (at - 600_000) < 3_600 * 1_000, 'on from where it was');
|
||||
worldClock.pause();
|
||||
});
|
||||
|
||||
test('paused just before the end, play carries on rather than restarting', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const end = now + 86_400_000;
|
||||
const release = worldClock.hold('test-ahead');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-ahead',
|
||||
coverage: () => ({ start: now - 86_400_000, end }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
worldClock.seek(end - 4_000);
|
||||
await nextTick();
|
||||
bar().querySelector('.world-timeline-play').click();
|
||||
worldClock.pause();
|
||||
assert.ok(worldClock.now() >= end - 4_000, 'not back to the start');
|
||||
});
|
||||
|
||||
test('the track zooms around the handle, follows it, and shows it all again', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 26 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
// A month of launches and three hours of lightning, sharing one track.
|
||||
coverage: () => ({
|
||||
start,
|
||||
end: now,
|
||||
marks: [start, now - 3 * 3_600_000, now - 2 * 3_600_000, now - 3_600_000],
|
||||
}),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const track = bar().querySelector('.world-timeline-track');
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
const length = () => Number(input.max) - Number(input.min);
|
||||
const full = length();
|
||||
assert.equal(bar().querySelectorAll('.world-timeline-tick').length, 4);
|
||||
|
||||
// Live, the handle is at the end: zooming in keeps the view on now.
|
||||
for (let i = 0; i < 10; i++) {
|
||||
track.dispatchEvent(new WheelEvent('wheel', { deltaY: -200, cancelable: true }));
|
||||
await nextTick();
|
||||
}
|
||||
assert.ok(length() < full / 100, 'zoomed in');
|
||||
assert.ok(Number(input.max) >= now, 'still ending at now');
|
||||
assert.equal(track.classList.contains('is-zoomed'), true);
|
||||
assert.equal(bar().querySelectorAll('.world-timeline-tick').length, 3, 'only the ticks in view');
|
||||
|
||||
// A seek off the view takes the view along.
|
||||
worldClock.seek(start + 86_400_000);
|
||||
await nextTick();
|
||||
assert.ok(Number(input.min) <= start + 86_400_000 && Number(input.max) >= start + 86_400_000);
|
||||
assert.ok(length() < full / 100, 'at the same zoom');
|
||||
|
||||
// Minus widens, zero and a double-click show it all.
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: '-' }));
|
||||
await nextTick();
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: '0' }));
|
||||
await nextTick();
|
||||
assert.ok(Math.abs(length() - full) < 1_000, 'all of it');
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: '+' }));
|
||||
await nextTick();
|
||||
assert.ok(length() < full);
|
||||
track.dispatchEvent(new MouseEvent('dblclick'));
|
||||
await nextTick();
|
||||
assert.equal(track.classList.contains('is-zoomed'), false);
|
||||
});
|
||||
|
||||
test('zoomed, a scrub near now stays off live, and the view keeps a still handle', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 26 * 86_400_000;
|
||||
let end = now;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start, end, marks: [start, now - 3_600_000] }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const track = bar().querySelector('.world-timeline-track');
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
// Ten notches of a line-mode wheel, as Firefox sends them.
|
||||
for (let i = 0; i < 10; i++) {
|
||||
track.dispatchEvent(new WheelEvent('wheel', { deltaY: -12, deltaMode: 1, cancelable: true }));
|
||||
await nextTick();
|
||||
}
|
||||
assert.ok(Number(input.max) - Number(input.min) < 6 * 3_600_000, 'lines zoom like pixels');
|
||||
|
||||
// Twenty minutes back is near now on a month, not on a few hours.
|
||||
input.value = String(now - 20 * 60_000);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
await nextTick();
|
||||
assert.equal(worldClock.isLive(), false);
|
||||
assert.ok(Math.abs(worldClock.now() - (now - 20 * 60_000)) < 1_000);
|
||||
|
||||
// The span running on past the paused handle takes the view back to it.
|
||||
end = now + 86_400_000;
|
||||
worldClock.coverageChanged();
|
||||
await nextTick();
|
||||
const at = worldClock.now();
|
||||
assert.ok(Number(input.min) <= at && Number(input.max) >= at, 'handle in view');
|
||||
|
||||
// With a modifier, plus is the browser's zoom.
|
||||
const browserZoom = new KeyboardEvent('keydown', { key: '+', ctrlKey: true, cancelable: true });
|
||||
input.dispatchEvent(browserZoom);
|
||||
assert.equal(browserZoom.defaultPrevented, false);
|
||||
|
||||
// A double-click puts back the time its first press moved.
|
||||
track.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, pointerId: 1 }));
|
||||
track.dispatchEvent(new PointerEvent('pointerup', { bubbles: true, pointerId: 1 }));
|
||||
input.value = String(at - 3_600_000);
|
||||
input.dispatchEvent(new Event('input'));
|
||||
track.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
|
||||
await nextTick();
|
||||
assert.equal(track.classList.contains('is-zoomed'), false);
|
||||
assert.ok(Math.abs(worldClock.now() - at) < 1_000, 'time as it was');
|
||||
});
|
||||
|
||||
test('play held for a layer to load shows a spinner once the hold lasts', async (t) => {
|
||||
const bar = mount(t);
|
||||
const at = Date.UTC(2026, 9, 30, 6, 15, 42);
|
||||
supportingLayer(t, at);
|
||||
worldClock.seek(at - 1_800_000);
|
||||
worldClock.play({ continuous: true });
|
||||
await nextTick();
|
||||
const bubble = () => bar().querySelector('.world-timeline-time');
|
||||
const release = worldClock.wait('test-radar');
|
||||
t.after(release);
|
||||
// A clock tick (a quarter second) tells of the hold; the spinner waits on.
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
await nextTick();
|
||||
assert.equal(bubble().querySelector('.world-timeline-spinner'), null, 'not for a quick frame');
|
||||
// The clock tells of the hold on its next tick, and the bar shows it after.
|
||||
const until = async (shown) => {
|
||||
for (let waited = 0; waited < 3_000; waited += 50) {
|
||||
if (Boolean(bubble().querySelector('.world-timeline-spinner')) === shown) return true;
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
await nextTick();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
assert.ok(await until(true), 'spinner once the hold lasts');
|
||||
assert.match(bubble().textContent, /UTC$/, 'the time stays');
|
||||
release();
|
||||
assert.ok(await until(false), 'gone once play goes on');
|
||||
});
|
||||
|
||||
test('the track drags along, a tap goes to its time, and the handle waits off it', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 26 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start, end: now, marks: [start] }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const track = bar().querySelector('.world-timeline-track');
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
// A 1000 px track from x = 0.
|
||||
Object.defineProperty(track, 'clientWidth', { value: 1_000 });
|
||||
track.getBoundingClientRect = () => ({ left: 0, width: 1_000, top: 0, height: 24 });
|
||||
const press = (type, clientX, pointerId = 1) =>
|
||||
track.dispatchEvent(new PointerEvent(type, { bubbles: true, clientX, pointerId }));
|
||||
const view = () => ({ min: Number(input.min), max: Number(input.max) });
|
||||
|
||||
// All of it shown, a tap goes to the time under it.
|
||||
press('pointerdown', 500);
|
||||
press('pointerup', 500);
|
||||
await nextTick();
|
||||
const middle = start + (now - start) / 2;
|
||||
assert.ok(Math.abs(worldClock.now() - middle) < 60_000, 'went to the middle');
|
||||
|
||||
// Zoomed to a day around it, dragging right by half the track goes back half a day.
|
||||
for (let i = 0; i < 6; i++) {
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: '+' }));
|
||||
await nextTick();
|
||||
}
|
||||
const before = view();
|
||||
const day = before.max - before.min;
|
||||
press('pointerdown', 600, 2);
|
||||
press('pointermove', 700, 2);
|
||||
press('pointermove', 1_100, 2);
|
||||
press('pointerup', 1_100, 2);
|
||||
await nextTick();
|
||||
assert.ok(Math.abs(view().max - (before.max - day / 2)) < 1_000, 'dragged half a view');
|
||||
assert.ok(Math.abs(worldClock.now() - middle) < 60_000, 'a drag leaves the time');
|
||||
|
||||
// Dragged off the handle, it waits unseen at the edge; a sideways swipe drags too.
|
||||
track.dispatchEvent(new WheelEvent('wheel', { deltaX: -2_000, deltaY: 0, cancelable: true }));
|
||||
await nextTick();
|
||||
assert.ok(view().max < worldClock.now(), 'the handle is past the view');
|
||||
assert.equal(input.classList.contains('is-off-view'), true);
|
||||
// Moving the time takes the view back to it.
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'PageUp' }));
|
||||
await nextTick();
|
||||
assert.equal(input.classList.contains('is-off-view'), false);
|
||||
});
|
||||
|
||||
test('a pinch measures from where the fingers are, and a lifted finger ends it', async (t) => {
|
||||
const bar = mount(t);
|
||||
const now = Date.now();
|
||||
const start = now - 26 * 86_400_000;
|
||||
const release = worldClock.hold('test-launches');
|
||||
const unregister = worldClock.register({
|
||||
id: 'test-launches',
|
||||
coverage: () => ({ start, end: now, marks: [start] }),
|
||||
});
|
||||
t.after(() => {
|
||||
unregister();
|
||||
release();
|
||||
});
|
||||
await nextTick();
|
||||
const track = bar().querySelector('.world-timeline-track');
|
||||
const input = bar().querySelector('input[type=range]');
|
||||
Object.defineProperty(track, 'clientWidth', { value: 1_000 });
|
||||
track.getBoundingClientRect = () => ({ left: 0, width: 1_000, top: 0, height: 24 });
|
||||
const on = (target, type, clientX, pointerId) =>
|
||||
target.dispatchEvent(new PointerEvent(type, { bubbles: true, clientX, pointerId }));
|
||||
const length = () => Number(input.max) - Number(input.min);
|
||||
for (let i = 0; i < 4; i++) {
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: '+' }));
|
||||
await nextTick();
|
||||
}
|
||||
const before = length();
|
||||
// A finger on the handle moves before the second comes down.
|
||||
on(input, 'pointerdown', 300, 1);
|
||||
on(input, 'pointermove', 500, 1);
|
||||
on(track, 'pointerdown', 700, 2);
|
||||
on(input, 'pointermove', 500, 1);
|
||||
await nextTick();
|
||||
assert.ok(Math.abs(length() - before) < 1_000, 'no zoom from a stale finger');
|
||||
on(track, 'pointermove', 900, 2);
|
||||
await nextTick();
|
||||
assert.ok(length() < before, 'spread apart, it zooms in');
|
||||
// One finger up: the other moving does nothing, and throws nothing.
|
||||
const zoomedTo = length();
|
||||
on(track, 'pointerup', 900, 2);
|
||||
on(input, 'pointermove', 100, 1);
|
||||
await nextTick();
|
||||
assert.ok(Math.abs(length() - zoomedTo) < 1_000);
|
||||
on(input, 'pointercancel', 100, 1);
|
||||
});
|
||||
@@ -0,0 +1,355 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, shallowRef, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { formatDate, t } from '../../../i18n/index.js';
|
||||
import { useWorldTimeStore } from '../../stores/worldTime.js';
|
||||
import UiButton from '../../kit/UiButton.vue';
|
||||
import UiIcon from '../../kit/UiIcon.vue';
|
||||
import UiSelect from '../../kit/UiSelect.js';
|
||||
|
||||
// The world timeline: play and pause and the speed on the left, a track
|
||||
// across the stretch the layers on can show (each launch or frame a tick)
|
||||
// with a handle to scrub and the time in a bubble over it, and the way back
|
||||
// to live on the right, lit while live. Scrolling or pinching the track
|
||||
// zooms it around the handle, dragging it moves along it, and a double-click
|
||||
// shows it all again. It shows
|
||||
// while a layer with a time of its own (weather, satellites, launches,
|
||||
// or one a host follows) is on with time to show; with only live feeds such
|
||||
// as flights on, the bar stays hidden.
|
||||
const store = useWorldTimeStore();
|
||||
const { time, speed } = storeToRefs(store);
|
||||
const speeds = computed(() => [
|
||||
{ value: 'real', label: '1×' },
|
||||
{ value: 'minute', label: t('1 min/s') },
|
||||
{ value: 'hour', label: t('1 h/s') },
|
||||
{ value: 'day', label: t('1 d/s') },
|
||||
{ value: 'week', label: t('1 wk/s') },
|
||||
]);
|
||||
|
||||
const DATE_TIME = Object.freeze({
|
||||
dateStyle: 'medium',
|
||||
timeStyle: 'medium',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
// The bubble over the handle: the date and the minute, kept short.
|
||||
const BUBBLE_DATE = Object.freeze({
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
const BUBBLE_TIME = Object.freeze({
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
// The keyboard's fallback step, as a share of the track, with no mark to go to.
|
||||
const KEY_STEP = 0.01;
|
||||
const PAGE_STEP = 0.1;
|
||||
// Zooming: the shortest stretch the track narrows to, the step a key or a
|
||||
// notch of the wheel takes, and how far a wheel's pixel of scroll zooms.
|
||||
const MIN_VIEW_MS = 5 * 60_000;
|
||||
const ZOOM_STEP = 1.5;
|
||||
const WHEEL_ZOOM = 0.0025;
|
||||
// Two presses this close are a double-click.
|
||||
const DOUBLE_PRESS_MS = 500;
|
||||
|
||||
const readout = computed(() =>
|
||||
Number.isFinite(time.value.timeMs)
|
||||
? `${formatDate(time.value.timeMs, DATE_TIME)} UTC`
|
||||
: '',
|
||||
);
|
||||
const bubble = computed(() =>
|
||||
Number.isFinite(time.value.timeMs)
|
||||
? `${formatDate(time.value.timeMs, BUBBLE_DATE)} · ${formatDate(time.value.timeMs, BUBBLE_TIME)} UTC`
|
||||
: '',
|
||||
);
|
||||
// Play held while a layer loads the time's data shows a spinner by the time,
|
||||
// once the hold lasts long enough to notice, so a quick frame does not flash
|
||||
// it, and until play has run a while, so a run of slow frames keeps it still.
|
||||
const WAIT_SHOWN_MS = 300;
|
||||
const WAIT_HIDDEN_MS = 500;
|
||||
const waiting = shallowRef(false);
|
||||
let waitTimer = null;
|
||||
watch(
|
||||
() => time.value.buffering,
|
||||
(buffering) => {
|
||||
clearTimeout(waitTimer);
|
||||
waitTimer = null;
|
||||
if (buffering === waiting.value) return;
|
||||
waitTimer = setTimeout(
|
||||
() => {
|
||||
waitTimer = null;
|
||||
waiting.value = buffering;
|
||||
},
|
||||
buffering ? WAIT_SHOWN_MS : WAIT_HIDDEN_MS,
|
||||
);
|
||||
},
|
||||
);
|
||||
onBeforeUnmount(() => clearTimeout(waitTimer));
|
||||
const span = computed(() => time.value.span);
|
||||
// Where the handle is, or null with no track.
|
||||
const at = computed(() => {
|
||||
if (!span.value) return null;
|
||||
const { start, end } = span.value;
|
||||
return Math.min(end, Math.max(start, time.value.timeMs));
|
||||
});
|
||||
|
||||
// The track shows the whole span, or zoomed, a stretch of it: `length` long,
|
||||
// ending at `end`, or at the span's end (and so at now) while `end` is null.
|
||||
// Everything still plays together; zooming only changes what the track shows.
|
||||
const zoom = shallowRef(null);
|
||||
const view = computed(() => {
|
||||
if (!span.value) return null;
|
||||
const { start, end } = span.value;
|
||||
const length = zoom.value?.length;
|
||||
if (!length || length >= end - start) return { start, end };
|
||||
const viewEnd = Math.min(end, Math.max(start + length, zoom.value.end ?? end));
|
||||
return { start: viewEnd - length, end: viewEnd };
|
||||
});
|
||||
const zoomed = computed(() => zoom.value !== null);
|
||||
const viewLength = () => view.value.end - view.value.start;
|
||||
// Show `length` of the span ending at `viewEnd`, held to the span.
|
||||
function showView(length, viewEnd) {
|
||||
const { start, end } = span.value;
|
||||
if (length >= end - start) {
|
||||
showWhole();
|
||||
return;
|
||||
}
|
||||
const clamped = Math.min(end, Math.max(start + length, viewEnd));
|
||||
zoom.value = { length, end: clamped >= end ? null : clamped };
|
||||
}
|
||||
// Narrow or widen the view to `length`, keeping the handle where it is on it,
|
||||
// or with the handle off it, the middle.
|
||||
function zoomTo(length) {
|
||||
const { start: from, end: to } = view.value;
|
||||
const pivot = offView(at.value) ? (from + to) / 2 : at.value;
|
||||
const share = (pivot - from) / (to - from);
|
||||
const next = Math.max(MIN_VIEW_MS, length);
|
||||
showView(next, pivot + (1 - share) * next);
|
||||
}
|
||||
const zoomBy = (factor) => zoomTo(viewLength() * factor);
|
||||
// A view dragged off the handle stays where it was put while the handle only
|
||||
// creeps on with now; playing or a move of the handle takes it back.
|
||||
let panned = false;
|
||||
const follow = (ms) => {
|
||||
panned = false;
|
||||
showView(zoom.value.length, ms + zoom.value.length / 2);
|
||||
};
|
||||
const offView = (ms) => ms < view.value.start || ms > view.value.end;
|
||||
const showWhole = () => {
|
||||
zoom.value = null;
|
||||
panned = false;
|
||||
};
|
||||
// The span narrowing to the zoom or less, or going, lets go of the zoom.
|
||||
watch(span, (next) => {
|
||||
if (zoom.value && (!next || zoom.value.length >= next.end - next.start))
|
||||
showWhole();
|
||||
});
|
||||
watch(at, (ms) => {
|
||||
if (!zoom.value || ms === null || !offView(ms)) return;
|
||||
if (panned && time.value.live && !time.value.playing) return;
|
||||
follow(ms);
|
||||
});
|
||||
// Left behind as now moves the view on, the handle takes the view back.
|
||||
watch(view, () => {
|
||||
if (zoom.value && !panned && at.value !== null && offView(at.value))
|
||||
follow(at.value);
|
||||
});
|
||||
const pan = (ms) => {
|
||||
panned = true;
|
||||
showView(zoom.value.length, view.value.end + ms);
|
||||
};
|
||||
// A wheel's lines and pages, in pixels.
|
||||
const WHEEL_UNITS = [1, 16, 400];
|
||||
const onWheel = (event) => {
|
||||
const unit = WHEEL_UNITS[event.deltaMode] ?? 1;
|
||||
const sideways = Math.abs(event.deltaX) > Math.abs(event.deltaY);
|
||||
// A sideways swipe, or a wheel with shift, drags; a wheel zooms.
|
||||
if (sideways || event.shiftKey) {
|
||||
if (!zoom.value) return;
|
||||
event.preventDefault();
|
||||
const width = event.currentTarget.clientWidth;
|
||||
const pixels = (sideways ? event.deltaX : event.deltaY) * unit;
|
||||
if (width > 0) pan((pixels / width) * viewLength());
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
zoomBy(Math.exp(event.deltaY * unit * WHEEL_ZOOM));
|
||||
};
|
||||
// A double-click starts with presses that move the time, so it puts back the
|
||||
// time from before its first; so does a pinch, which may start on the handle.
|
||||
let before = null;
|
||||
let pressedAt = -Infinity;
|
||||
const onPress = (event) => {
|
||||
if (event.timeStamp - pressedAt > DOUBLE_PRESS_MS)
|
||||
before = { live: time.value.live, timeMs: time.value.timeMs };
|
||||
pressedAt = event.timeStamp;
|
||||
};
|
||||
const restore = () => {
|
||||
if (!before) return;
|
||||
if (before.live) store.goLive();
|
||||
else store.scrub(before.timeMs, 0);
|
||||
};
|
||||
const showAll = () => {
|
||||
restore();
|
||||
showWhole();
|
||||
};
|
||||
|
||||
// The handle drags the time. The rest of the track takes the pointer: a tap
|
||||
// goes to the time under it, a drag drags a zoomed track along (or the time,
|
||||
// with all of it shown), and two fingers pinch it.
|
||||
const DRAG_PX = 4;
|
||||
const pointers = new Map();
|
||||
let gesture = null;
|
||||
const timeAt = (clientX, track) => {
|
||||
const { left, width } = track.getBoundingClientRect();
|
||||
const share = width > 0 ? Math.min(1, Math.max(0, (clientX - left) / width)) : 1;
|
||||
return view.value.start + share * viewLength();
|
||||
};
|
||||
// Whether the first finger has moved the time, for a pinch to put it back.
|
||||
let movedTime = false;
|
||||
const onPointerDown = (event) => {
|
||||
// Only the main button: a right-click is for the menu.
|
||||
if (event.button > 0) return;
|
||||
const onHandle = event.target instanceof HTMLInputElement;
|
||||
pointers.set(event.pointerId, { x: event.clientX, onHandle });
|
||||
if (pointers.size === 1) {
|
||||
onPress(event);
|
||||
movedTime = onHandle;
|
||||
// The keys zoom and step the track as soon as it is touched.
|
||||
if (!onHandle)
|
||||
event.currentTarget.querySelector('input')?.focus({ preventScroll: true });
|
||||
}
|
||||
if (pointers.size === 2) {
|
||||
const [a, b] = [...pointers.values()];
|
||||
if (movedTime) restore();
|
||||
gesture = {
|
||||
kind: 'pinch',
|
||||
spread: Math.abs(a.x - b.x),
|
||||
length: viewLength(),
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (onHandle || pointers.size !== 1) return;
|
||||
// The drag goes on past the track's ends; without the capture, to them.
|
||||
try {
|
||||
event.currentTarget.setPointerCapture?.(event.pointerId);
|
||||
} catch {
|
||||
// A pointer the page no longer knows of drags no further than the track.
|
||||
}
|
||||
gesture = { kind: 'press', x: event.clientX, end: view.value.end };
|
||||
};
|
||||
const onPointerMove = (event) => {
|
||||
const pointer = pointers.get(event.pointerId);
|
||||
if (!pointer) return;
|
||||
pointer.x = event.clientX;
|
||||
if (!gesture) return;
|
||||
const track = event.currentTarget;
|
||||
if (gesture.kind === 'pinch') {
|
||||
const [a, b] = [...pointers.values()];
|
||||
const spreadNow = Math.abs(a.x - b.x);
|
||||
if (spreadNow > 0) zoomTo((gesture.length * gesture.spread) / spreadNow);
|
||||
return;
|
||||
}
|
||||
if (gesture.kind === 'press') {
|
||||
if (Math.abs(event.clientX - gesture.x) < DRAG_PX) return;
|
||||
gesture.kind = zoom.value ? 'pan' : 'scrub';
|
||||
movedTime = gesture.kind === 'scrub';
|
||||
}
|
||||
if (gesture.kind === 'pan') {
|
||||
if (!track.clientWidth) return;
|
||||
panned = true;
|
||||
const moved = ((gesture.x - event.clientX) / track.clientWidth) * viewLength();
|
||||
showView(zoom.value.length, gesture.end + moved);
|
||||
} else store.scrub(timeAt(event.clientX, track), viewLength());
|
||||
};
|
||||
const onPointerUp = (event) => {
|
||||
if (!pointers.delete(event.pointerId)) return;
|
||||
if (gesture?.kind === 'press' && event.type === 'pointerup')
|
||||
store.scrub(timeAt(event.clientX, event.currentTarget), viewLength());
|
||||
// A finger lifted from a pinch ends it; the other one moves nothing.
|
||||
gesture = null;
|
||||
};
|
||||
|
||||
const place = (ms) => {
|
||||
const { start, end } = view.value;
|
||||
return end > start ? ((ms - start) / (end - start)) * 100 : 100;
|
||||
};
|
||||
const ticks = computed(() => {
|
||||
const { start, end } = view.value;
|
||||
return span.value.marks
|
||||
.filter((mark) => mark >= start && mark <= end)
|
||||
.map((mark) => `${place(mark)}%`);
|
||||
});
|
||||
const shown = computed(() =>
|
||||
Math.min(view.value.end, Math.max(view.value.start, at.value)),
|
||||
);
|
||||
const handleOff = computed(() => at.value !== shown.value);
|
||||
const scrub = (event) => {
|
||||
// A pinch only zooms; the input goes back to the handle.
|
||||
if (gesture?.kind === 'pinch') {
|
||||
event.target.value = shown.value;
|
||||
return;
|
||||
}
|
||||
store.scrub(Number(event.target.value), viewLength());
|
||||
};
|
||||
// Arrows go to the previous or next mark (a launch, a frame), or a step along
|
||||
// the track as shown; Page keys take a tenth of it; Home and End go to the
|
||||
// ends of all of it. Plus and minus zoom, and zero shows it all; with a
|
||||
// modifier they are the browser's own zoom.
|
||||
const ZOOM_KEYS = ['+', '=', '-', '0'];
|
||||
const onKey = (event) => {
|
||||
if (ZOOM_KEYS.includes(event.key)) {
|
||||
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
||||
event.preventDefault();
|
||||
if (event.key === '-') zoomBy(ZOOM_STEP);
|
||||
else if (event.key === '0') showWhole();
|
||||
else zoomBy(1 / ZOOM_STEP);
|
||||
return;
|
||||
}
|
||||
const { start, end, marks } = span.value;
|
||||
const now = at.value;
|
||||
const length = viewLength();
|
||||
let to = null;
|
||||
if (event.key === 'ArrowLeft' || event.key === 'ArrowDown')
|
||||
to = marks.findLast((mark) => mark < now) ?? now - length * KEY_STEP;
|
||||
else if (event.key === 'ArrowRight' || event.key === 'ArrowUp')
|
||||
to = marks.find((mark) => mark > now) ?? now + length * KEY_STEP;
|
||||
else if (event.key === 'PageDown') to = now - length * PAGE_STEP;
|
||||
else if (event.key === 'PageUp') to = now + length * PAGE_STEP;
|
||||
else if (event.key === 'Home') to = start;
|
||||
else if (event.key === 'End') to = end;
|
||||
if (to === null) return;
|
||||
event.preventDefault();
|
||||
store.scrub(Math.min(end, Math.max(start, to)), length);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="time.supported && time.span" id="world-timeline" role="group" :aria-label="t('World time')"
|
||||
><UiButton class="world-timeline-play" :label="time.playing ? t('Pause') : t('Play')" @click="store.togglePlay()"
|
||||
><UiIcon :name="time.playing ? 'pause' : 'play_arrow'" :size="20" /></UiButton
|
||||
><UiSelect class="gev-field gev-field--compact world-timeline-speed" :aria-label="t('Play speed')" :title="t('Play speed')" :options="speeds" :model-value="speed" @update:model-value="store.setSpeed($event)"
|
||||
/><div class="world-timeline-track" :class="{ 'is-zoomed': zoomed }" :title="t('Scroll or pinch to zoom, drag to move along · double-click to see it all')" @wheel="onWheel" @dblclick="showAll" @pointerdown="onPointerDown" @pointermove="onPointerMove" @pointerup="onPointerUp" @pointercancel="onPointerUp"
|
||||
><time class="world-timeline-time" :class="{ 'is-waiting': waiting }" :style="{ '--at': place(shown) / 100 }" :datetime="new Date(time.timeMs).toISOString()" aria-live="off"
|
||||
><span v-if="waiting" class="world-timeline-spinner" aria-hidden="true"></span>{{ bubble }}</time
|
||||
><span v-for="(left, index) in ticks" :key="index" class="world-timeline-tick" :style="{ left }" aria-hidden="true"></span
|
||||
><span class="world-timeline-fill" :style="{ width: `${place(shown)}%` }" aria-hidden="true"></span
|
||||
><input
|
||||
class="world-timeline-scrub"
|
||||
:class="{ 'is-off-view': handleOff }"
|
||||
type="range"
|
||||
:aria-label="t('World time')"
|
||||
:aria-valuetext="readout"
|
||||
:min="view.start"
|
||||
:max="view.end"
|
||||
step="any"
|
||||
:value="shown"
|
||||
@input="scrub"
|
||||
aria-keyshortcuts="+ - 0"
|
||||
@keydown="onKey"
|
||||
/></div
|
||||
><UiButton class="world-timeline-live" :label="time.live ? t('Live') : t('Back to live')" :pressed="time.live" pressed-class="is-live" :disabled="time.live" @click="store.goLive()">{{ t('Live') }}</UiButton
|
||||
></div>
|
||||
</template>
|
||||
Reference in new issue
Block a user