mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
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:
1 parent
d0ef5250ac
commit
fe5470a852
39 files changed
+1985
-31
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user