feat(cockpit): zoom the orbital view to the imaging sensor's swath

An imaging satellite with a known sensor can now zoom past 8x, up to 128x,
as far as the view stays at least as wide as the sensor's narrowest
standard swath at its live altitude; only swaths confirmed on a cited page
open those steps. The top step follows the altitude and window shape and
steps back when it falls below the zoom shown.

The view draws the sensor's swath to scale along the ground track with a
SENSOR SWATH readout (approximate off nadir), and a SENSOR button zooms to
exactly that width when it lies in range at nadir. From 16x the imagery
tiles the view will need 5 to 20 s ahead along the ground track are
pre-loaded at the matching level. The mouse wheel steps the zoom one notch
at a time, and the identity line shows how old the TLE is. The sensor
figures come from a new bundled pack of 46 Earth-observation platforms,
each value cited to its operator or agency, with its own data credit.
This commit is contained in:
Denis Groshev committed 2026-11-09 00:25:06 +01:00
1 parent d0ef5250ac
commit fe5470a852
39 files changed
+1985 -31

No files matched your search

+18
View File
@@ -20,6 +20,8 @@ import {
beginOrbital,
endOrbital,
resetOrbitalLook,
jumpToSensorSwath,
onOrbitalWheel,
stepOrbitalZoom,
turnOrbitalLook,
updateOrbital,
@@ -290,6 +292,14 @@ export class CockpitViewController {
true,
);
this._listenerRemovers.push(routeSceneDoubleClick.call(this));
// In orbit the wheel steps the optical zoom (Cesium's own wheel zoom is
// off while the Cockpit holds the camera).
this._listen(
viewer.scene?.canvas,
'wheel',
(event) => this.onOrbitalWheel(event),
{ passive: false },
);
// The readout's entry renders inside the Intel HUD, which may mount after
// this controller; delegated like the radar's range button.
this._listen(document, 'click', (event) => {
@@ -338,6 +348,8 @@ export class CockpitViewController {
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 }),
@@ -406,6 +418,12 @@ export class CockpitViewController {
stepOrbitalZoom(direction) {
return stepOrbitalZoom.call(this, direction);
}
jumpToSensorSwath() {
return jumpToSensorSwath.call(this);
}
onOrbitalWheel(event) {
return onOrbitalWheel.call(this, event);
}
/**
* Tilt the orbital view one arrow step off nadir.
* @param {{axis: 'yaw'|'pitch', sign: number, stepDeg: number}} step
+18
View File
@@ -214,6 +214,24 @@ test('the readout names the owner, operator and element set', async (t) => {
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');
+250 -4
View File
@@ -1,14 +1,19 @@
/** 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_BASE_MAX_ZOOM,
ORBITAL_DEFAULT_ZOOM,
ORBITAL_PREFETCH_INTERVAL_MS,
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,
@@ -16,7 +21,12 @@ import {
offNadirOrientation,
offNadirSwathScale,
orbitalBaseFovRad,
orbitalMaxZoom,
previousOrbitalZoom,
sensorStripFraction,
sensorSwathZoom,
tilesForPoints,
wheelZoomStep,
zoomSettleHolding,
zoomTransitionState,
} from '../cockpitOrbital.js';
@@ -28,6 +38,8 @@ import {
} 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 {
COCKPIT_CONTEXT_UPDATE_MS,
COCKPIT_HUD_UPDATE_MS,
@@ -66,6 +78,12 @@ export function beginOrbital() {
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(),
// A zoom step in flight: the magnification it started from and when.
transition: null,
previousUp: null,
@@ -283,6 +301,14 @@ export function updateOrbital(nowMs) {
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);
}
state.lookView = easeLook(
state.lookView,
state.lookTarget,
@@ -322,6 +348,136 @@ export function updateOrbital(nowMs) {
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;
/**
* 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. Nothing below 16x, while the view is tilted off
* nadir (it no longer looks at the track), 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;
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;
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,
groundTrackAhead(info, viewKm),
level,
{
maxTiles: ORBITAL_PREFETCH_MAX_TILES,
skip: (key) => memory.has(key),
},
);
let asked = 0;
for (const tile of tiles) {
let pending;
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,
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;
Promise.resolve(pending).catch(() => {});
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;
}
/**
@@ -409,6 +565,8 @@ export function publishOrbitalView(info, transition = IDLE_TRANSITION) {
: canvasAspect(this.viewer);
const settledFov = fovForZoom(orbitalBaseFovRad(info.altitudeM), state.zoom);
const footprintKm = footprintWidthKm(info.altitudeM, settledFov, aspect);
const maxZoom = orbitalMaxZoomFor.call(this, info);
const swathKm = sensorSwathKm(info);
const trackUp = Number.isFinite(info.groundTrackDeg);
const swathScale = offset
? offNadirSwathScale(lookTilt(orbitalLookReadoutParts(state.lookTarget)))
@@ -421,9 +579,22 @@ export function publishOrbitalView(info, transition = IDLE_TRANSITION) {
latitude: info.latitude,
longitude: info.longitude,
zoom: state.zoom,
zoomSteps: [...ORBITAL_ZOOM_LADDER],
maxZoom: ORBITAL_BASE_MAX_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.
sensor:
swathKm === null
? null
: {
label: info.sensor?.label ?? null,
swathKm,
// Off nadir the view and the swath widen alike: the strip
// keeps its share of the frame.
stripFraction: sensorStripFraction(swathKm, footprintKm),
zoom: sensorSwathZoom(info.altitudeM, swathKm, aspect, maxZoom),
},
transition: { ...transition },
look: {
offset,
@@ -444,6 +615,10 @@ export function publishOrbitalView(info, transition = IDLE_TRANSITION) {
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.
tleAgeMs: Number.isFinite(info.tle?.epochMs)
? Date.now() - info.tle.epochMs
: null,
owner: info.owner ?? null,
operator: info.operator ?? null,
});
@@ -490,11 +665,82 @@ export function stepOrbitalZoom(direction) {
const state = this.orbital;
const next =
direction > 0
? nextOrbitalZoom(state.zoom)
? 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.
+370 -1
View File
@@ -15,6 +15,8 @@ import CockpitView from './views/CockpitView.vue';
import ContextView from './views/ContextView.vue';
import IntelHudView from './views/IntelHudView.vue';
import {
ORBITAL_PREFETCH_INTERVAL_MS,
ORBITAL_PREFETCH_MAX_TILES,
ORBITAL_SETTLE_BLUR_PX,
ORBITAL_SETTLE_MAX_MS,
ORBITAL_ZOOM_TRANSITION_MS,
@@ -23,6 +25,8 @@ import {
orbitalBaseFovRad,
} from '../cockpitOrbital.js';
import { vesselCockpitInfo } from '../layers/vessels/cockpitSubject.js';
import { prefetchImageryAhead } from './cockpitOrbitalView.js';
import { imageryLevelForView } from '../cockpitOrbital.js';
import { claimPointer, releasePointer } from '../data/inputOwnership.js';
const ISS = Object.freeze({
@@ -1012,6 +1016,302 @@ test('a tracked aircraft takes entry before a tracked satellite', async (t) => {
assert.equal(store.presence.entryKind, 'aircraft');
});
/** An imaging satellite with a narrow confirmed sensor swath. */
const WORLDVIEW = Object.freeze({
...ISS,
id: '40115',
noradId: 40115,
name: 'WORLDVIEW-3 (WV-3)',
classKey: 'visual',
classLabel: 'IMAGING',
altitudeM: 617_000,
sensor: Object.freeze({
label: 'WorldView-3',
narrowestSwathKm: 13.1,
swathConfirmed: true,
}),
});
/** A wide-area imager whose swath fits inside 8x. */
const LANDSAT = Object.freeze({
...WORLDVIEW,
id: '49260',
noradId: 49260,
name: 'LANDSAT 9',
altitudeM: 705_000,
sensor: Object.freeze({
label: 'Landsat 8 / Landsat 9',
narrowestSwathKm: 185,
swathConfirmed: true,
}),
});
test('an imaging satellite zooms past 8x as far as its sensor swath', async (t) => {
const { $, cockpit, store } = await orbitAt(t, { satellite: WORLDVIEW });
assert.equal(store.orbital.maxZoom, 64);
assert.deepEqual(store.orbital.zoomSteps, [1, 2, 4, 8, 16, 32, 64]);
for (let step = 0; step < 8; step += 1) press(cockpit, '+');
assert.equal(store.orbital.zoom, 64, 'stops at the cap');
await settle();
assert.equal($('#cockpit-orbital-zoom-in').disabled, true);
assert.match($('.cockpit-orbital-zoom').textContent, /64×/);
// The swath, to scale: 13.1 km of a ~20 km view.
assert.match(
$('.cockpit-orbital-sensor-swath').textContent,
/SENSOR SWATH 13\.1 KM/,
);
const width = parseFloat($('.cockpit-orbital-sensor-strip').style.width);
assert.ok(width > 50 && width < 100, String(width));
// The swath is narrower than the 64x view: no SENSOR step to take.
assert.equal($('#cockpit-orbital-sensor'), null);
});
test("the SENSOR step frames a wide sensor's swath", async (t) => {
const { $, cockpit, store } = await orbitAt(t, { satellite: LANDSAT });
assert.equal(store.orbital.maxZoom, 8, 'a wide swath adds no steps');
await settle();
const button = $('#cockpit-orbital-sensor');
assert.ok(button, 'the SENSOR step is offered');
assert.equal(button.getAttribute('aria-keyshortcuts'), null, 'no key');
assert.doesNotMatch(button.title, /\(S\)/);
button.click();
const zoom = store.orbital.zoom;
assert.ok(zoom > 4 && zoom < 8, String(zoom));
assert.ok(Math.abs(store.orbital.footprintKm - 185) < 1, 'view = swath');
await settle();
assert.match($('.cockpit-orbital-zoom').textContent, /ZOOM \d\.\d×/);
press(cockpit, '+');
assert.equal(store.orbital.zoom, 8, 'on to the step above');
press(cockpit, '-');
press(cockpit, '-');
assert.equal(store.orbital.zoom, 2);
$('#cockpit-orbital-sensor').click();
assert.equal(store.orbital.zoom, zoom, 'the button takes it again');
});
test('off nadir the sensor strip stays and its swath reads approximate', async (t) => {
const { $, cockpit, store } = await orbitAt(t, { satellite: LANDSAT });
await settle();
assert.equal(
$('.cockpit-orbital-sensor-swath').textContent,
'SENSOR SWATH 185 KM',
);
const nadirWidth = $('.cockpit-orbital-sensor-strip').style.width;
press(cockpit, 'ArrowRight');
press(cockpit, 'ArrowRight');
await settle();
assert.equal(store.orbital.look.offset, true);
// Across the frame by 10°: 185 km / cos² 10° ≈ 190.8 km.
const text = $('.cockpit-orbital-sensor-swath').textContent;
const km = Number(text.match(/^SENSOR SWATH ≈ ([\d.]+) KM$/)[1]);
assert.ok(Math.abs(km - 185 / Math.cos((10 * Math.PI) / 180) ** 2) < 0.1);
assert.equal(
$('.cockpit-orbital-sensor-strip').style.width,
nadirWidth,
'the strip keeps its share of the view',
);
assert.equal($('#cockpit-orbital-sensor'), null, 'no SENSOR step tilted');
press(cockpit, 'Home');
await settle();
assert.equal(
$('.cockpit-orbital-sensor-swath').textContent,
'SENSOR SWATH 185 KM',
);
assert.ok($('#cockpit-orbital-sensor'));
});
test('S does nothing in an orbital view, even with a SENSOR step', async (t) => {
const { $, cockpit, store } = await orbitAt(t, { satellite: LANDSAT });
await settle();
assert.ok($('#cockpit-orbital-sensor'), 'the SENSOR step is offered');
for (const key of ['s', 'S']) {
const event = press(cockpit, key, { shiftKey: key === 'S' });
assert.equal(event.defaultPrevented, false, key);
assert.equal(store.orbital.zoom, 1, key);
}
assert.doesNotMatch(
document.querySelector('.cockpit-help')?.textContent ?? '',
/SENSOR/,
'no key hint',
);
});
/** A globe draping one Web Mercator imagery layer that records requests. */
function imageryGlobe(viewer, { requestImage } = {}) {
const requests = [];
const requestObjects = [];
const provider = {
tilingScheme: new Cesium.WebMercatorTilingScheme(),
tileWidth: 256,
maximumLevel: 19,
requestImage:
requestImage ??
((x, y, level, request) => {
requests.push(`${level}/${x}/${y}`);
requestObjects.push(request);
return Promise.resolve({});
}),
};
viewer.scene.globe = { show: true, tilesLoaded: true };
viewer.scene.canvas = { clientWidth: 1600, clientHeight: 900 };
viewer.imageryLayers = {
length: 1,
get: () => ({ show: true, alpha: 1, imageryProvider: provider }),
};
return { requests, requestObjects, provider };
}
const WORLDVIEW_ON_TRACK = Object.freeze({ ...WORLDVIEW, groundTrackDeg: 52 });
test('from 16x the imagery ahead of the ground track is pre-loaded', async (t) => {
const { cockpit, viewer, store, clock } = await orbitAt(t, {
satellite: WORLDVIEW_ON_TRACK,
});
const { requests } = imageryGlobe(viewer);
for (const zoom of [2, 4, 8]) {
press(cockpit, '+');
assert.equal(store.orbital.zoom, zoom);
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
}
assert.deepEqual(requests, [], 'nothing below 16x');
press(cockpit, '+');
assert.equal(store.orbital.zoom, 16);
clock.advance(16);
cockpit.update();
assert.ok(requests.length > 0, 'tiles ahead are asked for');
assert.ok(requests.length <= ORBITAL_PREFETCH_MAX_TILES, 'bounded');
assert.equal(new Set(requests.map((key) => key.split('/')[0])).size, 1);
const first = requests.length;
// Not again until the interval has passed, and never the same tile twice.
clock.advance(16);
cockpit.update();
assert.equal(requests.length, first);
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
assert.equal(new Set(requests).size, requests.length, 'no repeats');
// A tighter zoom needs a finer level.
press(cockpit, '+');
assert.equal(store.orbital.zoom, 32);
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
const levels = requests.map((key) => Number(key.split('/')[0]));
assert.equal(levels.at(-1), levels[0] + 1);
// Back below 16x, and after the exit: no more work.
const before = requests.length;
press(cockpit, '-');
press(cockpit, '-');
assert.equal(store.orbital.zoom, 8);
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
assert.equal(requests.length, before, 'stops below 16x');
press(cockpit, '+');
cockpit.exit();
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
assert.equal(
prefetchImageryAhead.call(cockpit, WORLDVIEW_ON_TRACK, Infinity),
0,
);
assert.equal(requests.length, before, 'stops after the exit');
});
test('the pre-load skips a hidden globe and a provider that cannot fetch', async (t) => {
const { cockpit, viewer, store, clock } = await orbitAt(t, {
satellite: WORLDVIEW_ON_TRACK,
});
const { requests, provider } = imageryGlobe(viewer);
for (let i = 0; i < 4; i += 1) press(cockpit, '+');
assert.equal(store.orbital.zoom, 16);
// Google 3D tiles drawn, the globe hidden: nothing to pre-load.
viewer.scene.globe.show = false;
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
assert.deepEqual(requests, []);
viewer.scene.globe.show = true;
// No requestImage, or one that throws: no error, nothing remembered.
delete provider.requestImage;
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
assert.doesNotThrow(() => cockpit.update());
provider.requestImage = () => {
throw new Error('offline');
};
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
assert.doesNotThrow(() => cockpit.update());
assert.equal(store.orbital.zoom, 16, 'the view carries on');
});
test('an unconfirmed sensor swath is drawn but adds no zoom steps', async (t) => {
const { store } = await orbitAt(t, {
satellite: {
...WORLDVIEW,
sensor: {
label: 'SuperView Neo-1',
narrowestSwathKm: 12,
swathConfirmed: false,
},
},
});
assert.equal(store.orbital.maxZoom, 8);
assert.equal(store.orbital.sensor.swathKm, 12);
});
test('the wheel steps the orbital zoom one notch at a time', async (t) => {
const { cockpit, store, clock } = await orbitAt(t, { satellite: WORLDVIEW });
const wheel = (deltaY) => {
const event = {
deltaY,
deltaMode: 0,
defaultPrevented: false,
preventDefault() {
this.defaultPrevented = true;
},
};
cockpit.onOrbitalWheel(event);
return event;
};
assert.equal(wheel(-100).defaultPrevented, true);
assert.equal(store.orbital.zoom, 2);
// The same notch's trailing events do nothing.
assert.equal(wheel(-100).defaultPrevented, false);
assert.equal(store.orbital.zoom, 2);
clock.advance(300);
wheel(-100);
assert.equal(store.orbital.zoom, 4);
clock.advance(300);
wheel(120);
assert.equal(store.orbital.zoom, 2, 'toward the viewer zooms out');
// A tool that owns the pointer keeps the wheel.
const lease = claimPointer('measure');
t.after(() => releasePointer(lease));
clock.advance(300);
wheel(-100);
assert.equal(store.orbital.zoom, 2);
releasePointer(lease);
cockpit.exit();
await settle();
assert.equal(cockpit.onOrbitalWheel({ deltaY: -100 }), false, 'orbit only');
});
test('the orbital view reads the TLE age on each HUD publish', async (t) => {
const HOUR = 3_600_000;
const { cockpit, store, clock } = await orbitAt(t, {
satellite: {
...ISS,
tle: {
line1: '1 25544U',
line2: '2 25544',
epochMs: START_MS - 13.5 * HOUR,
},
},
});
const ageH = () => store.orbital.tleAgeMs / HOUR;
assert.ok(Math.abs(ageH() - 13.5) < 0.01, String(ageH()));
clock.advance(HOUR);
cockpit.update();
assert.ok(Math.abs(ageH() - 14.5) < 0.01, 'kept current by the HUD cadence');
});
/** The ISS climbing north-east along its ground track. */
const ISS_ON_TRACK = Object.freeze({ ...ISS, groundTrackDeg: 52 });
@@ -1059,8 +1359,25 @@ test('a satellite with no ground track stays north-up', async (t) => {
assert.match($('.cockpit-orbital-north').textContent, /NORTH UP/);
});
test('a narrower window pulls the zoom back to the new top step', async (t) => {
const { cockpit, viewer, store, clock } = await orbitAt(t, {
satellite: WORLDVIEW,
});
for (let step = 0; step < 8; step += 1) press(cockpit, '+');
assert.equal(store.orbital.zoom, 64);
// A portrait window: the same zoom now shows finer ground than the sensor
// images, so the top step drops.
viewer.camera.frustum.aspectRatio = 0.5;
clock.advance(16);
cockpit.update();
await settle();
assert.ok(store.orbital.maxZoom < 64, String(store.orbital.maxZoom));
assert.equal(store.orbital.zoom, store.orbital.maxZoom);
assert.ok(store.orbital.zoomSteps.includes(store.orbital.zoom));
});
test('a zoom button that turns off hands focus to the other one', async (t) => {
const { $, cockpit } = await orbitAt(t);
const { $, cockpit } = await orbitAt(t, { satellite: WORLDVIEW });
await settle();
$('#cockpit-orbital-zoom-in').focus();
for (let step = 0; step < 8; step += 1) press(cockpit, '+');
@@ -1074,6 +1391,16 @@ test('a zoom button that turns off hands focus to the other one', async (t) => {
assert.match($('#cockpit-orbital-zoom-in').title, /\(\+\)/);
});
test('SENSOR hands focus to NADIR when a tilt takes it away', async (t) => {
const { $, cockpit } = await orbitAt(t, { satellite: LANDSAT });
await settle();
$('#cockpit-orbital-sensor').focus();
press(cockpit, 'ArrowUp');
await settle();
assert.equal($('#cockpit-orbital-sensor'), null);
assert.equal(document.activeElement?.id, 'cockpit-orbital-nadir');
});
test('the readout says OFF-NADIR while the view is tilted', async (t) => {
const { $, cockpit } = await orbitAt(t);
await settle();
@@ -1088,3 +1415,45 @@ test('the readout says OFF-NADIR while the view is tilted', async (t) => {
'ORBITAL VIEW · OFF-NADIR',
);
});
test('the pre-load is throttled, at the level Cesium draws, and waits out a tilt', async (t) => {
const { cockpit, viewer, store, clock } = await orbitAt(t, {
satellite: WORLDVIEW_ON_TRACK,
});
const { requests, requestObjects } = imageryGlobe(viewer);
for (let i = 0; i < 4; i += 1) press(cockpit, '+');
assert.equal(store.orbital.zoom, 16);
// Tilted off nadir the view looks away from the track: nothing asked.
press(cockpit, 'ArrowRight');
clock.advance(ORBITAL_PREFETCH_INTERVAL_MS);
cockpit.update();
assert.deepEqual(requests, [], 'nothing while tilted');
press(cockpit, 'Home');
for (let frame = 0; frame < 30; frame += 1) {
clock.advance(16);
cockpit.update();
}
assert.ok(requests.length > 0, 'back at nadir it pre-loads');
// Every request may be declined while Cesium is busy with the screen.
for (const request of requestObjects) {
assert.ok(request instanceof Cesium.Request);
assert.equal(request.throttle, true);
assert.equal(request.throttleByServer, true);
assert.equal(
request.priority,
Number.MAX_VALUE,
'never ahead of the screen',
);
assert.equal(request.type, Cesium.RequestType.IMAGERY);
}
// The level Cesium's own selection takes for this view.
const fov = fovForZoom(orbitalBaseFovRad(WORLDVIEW.altitudeM), 16);
const metresPerPixel =
(WORLDVIEW.altitudeM * 2 * Math.tan(fov / 2)) /
viewer.scene.canvas.clientHeight;
const expected = imageryLevelForView(new Cesium.WebMercatorTilingScheme(), {
metresPerPixel,
latitudeDeg: WORLDVIEW.latitude,
});
assert.equal(Number(requests[0].split('/')[0]), expected);
});
+16
View File
@@ -156,6 +156,22 @@ export function formatTleEpochUtc(epochMs) {
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
+16
View File
@@ -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);
});
+8 -2
View File
@@ -91,11 +91,13 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
* 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 }, 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
@@ -103,8 +105,12 @@ export const useCockpitStore = defineStore('gev-cockpit', () => {
* 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
* and 8, the tightest being `maxZoom`), `footprintKm` is the nadir ground width across the frame at that zoom
* 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
+47
View File
@@ -354,6 +354,15 @@
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;
@@ -497,3 +506,41 @@
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;
}
+60 -5
View File
@@ -5,6 +5,7 @@ import { formatNumber, getLocale, t } from '../../../i18n/index.js';
import {
formatCockpitCoordinate,
formatTleEpochUtc,
tleAgeParts,
} from '../../cockpitPresentation.js';
import {
loadFlagUrl,
@@ -52,8 +53,11 @@ const subPointText = computed(() => {
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) }),
t('ZOOM {zoom}×', {
zoom: formatNumber(zoom.value, { maximumFractionDigits: 1 }),
}),
);
const maxZoom = computed(
() => orbital.value?.maxZoom ?? Math.max(...zoomSteps.value),
@@ -61,6 +65,11 @@ const maxZoom = computed(
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(() => {
@@ -77,11 +86,42 @@ const northLetterStyle = computed(() => {
: null;
});
// A focused zoom button that turns off at the end of its range hands focus
// on instead of dropping it to the page. The watchers run before the
// re-render, while it still has focus.
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(() =>
@@ -100,6 +140,11 @@ watch(
(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 ≈.
@@ -185,6 +230,12 @@ const identParts = computed(() => {
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(' · '));
@@ -229,6 +280,8 @@ const lensStyle = computed(() => {
<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">
@@ -265,7 +318,7 @@ const lensStyle = computed(() => {
<!-- 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="polite">{{ look.readout }}</span>
<button id="cockpit-orbital-nadir" 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>
<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>
</div>
<div class="cockpit-orbital-optics">
@@ -273,6 +326,8 @@ const lensStyle = computed(() => {
<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>