mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read the weather layers' camera and map centre through the renderer's ports
The weather layers listen for the camera's moveEnd through the camera port, find the map centre through the query port's ellipsoid pick and the app's WGS84 helpers, and fly through the port's cameraOf. The shell rendering part, which stays Cesium-bound, now defaults the Cesium namespace, provides the fallback globe imagery host, and loads the adapter factories for a viewer with no renderer bound. The weather entry leaves the allow-list. It still reads the viewer's canvas size for the centre pick.
This commit is contained in:
1 parent
2061f5647c
commit
b774bd84c8
5 files changed
+45
-32
No files matched your search
@@ -8,6 +8,7 @@ import { createShellScene } from './shellFixture.mjs';
|
|||||||
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
|
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
|
||||||
import { formatScaleLabel } from '../../ui/unitLabels.js';
|
import { formatScaleLabel } from '../../ui/unitLabels.js';
|
||||||
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
|
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
|
||||||
|
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||||
import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs';
|
import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs';
|
||||||
|
|
||||||
const times = ['2026-09-15T20:00:00.000Z', '2026-09-15T20:05:00.000Z'];
|
const times = ['2026-09-15T20:00:00.000Z', '2026-09-15T20:05:00.000Z'];
|
||||||
@@ -61,20 +62,23 @@ async function shownLayer(id, manifest, params, view = {}) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
layer.init(
|
layer.init(
|
||||||
bindFakeCesiumCamera({
|
bindFakeCesiumCamera(
|
||||||
|
{
|
||||||
camera: {
|
camera: {
|
||||||
moveEnd: { addEventListener: () => () => {} },
|
moveEnd: { addEventListener: () => () => {} },
|
||||||
flyTo: ({ destination }) => flights.push(destination),
|
flyTo: ({ destination }) => flights.push(destination),
|
||||||
pickEllipsoid: () =>
|
|
||||||
view.center
|
|
||||||
? Cesium.Cartesian3.fromDegrees(...view.center)
|
|
||||||
: undefined,
|
|
||||||
},
|
},
|
||||||
scene: {
|
scene: { canvas: { clientWidth: 800, clientHeight: 600 } },
|
||||||
canvas: { clientWidth: 800, clientHeight: 600 },
|
|
||||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
|
||||||
},
|
},
|
||||||
}),
|
{
|
||||||
|
query: {
|
||||||
|
pickEllipsoid: (x, y) =>
|
||||||
|
x === 400 && y === 300 && view.center
|
||||||
|
? fromDegrees(...view.center)
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
if (params) layer.setParams(params);
|
if (params) layer.setParams(params);
|
||||||
layer.enable();
|
layer.enable();
|
||||||
|
|||||||
+12
-21
@@ -1,6 +1,5 @@
|
|||||||
import * as Cesium from 'cesium';
|
|
||||||
import { createWeatherRendering } from './rendering.js';
|
import { createWeatherRendering } from './rendering.js';
|
||||||
import { createWeatherShell } from './shellRendering.js';
|
import { createWeatherShell, globeImageryHost } from './shellRendering.js';
|
||||||
import { imageryHostStatus } from './imageryHost.js';
|
import { imageryHostStatus } from './imageryHost.js';
|
||||||
import { weatherDisplay, insideExtent } from './display.js';
|
import { weatherDisplay, insideExtent } from './display.js';
|
||||||
import {
|
import {
|
||||||
@@ -11,10 +10,8 @@ import {
|
|||||||
} from './clock.js';
|
} from './clock.js';
|
||||||
import { formatUtcDayMonth, t, msg } from '../../i18n/index.js';
|
import { formatUtcDayMonth, t, msg } from '../../i18n/index.js';
|
||||||
import { formatScaleLabel } from '../../ui/unitLabels.js';
|
import { formatScaleLabel } from '../../ui/unitLabels.js';
|
||||||
import { cameraOf } from '../../render/cesium/camera.js';
|
import { toLonLatH } from '../../geo/ellipsoid.js';
|
||||||
// The renderer drapes through `findGlobe`; a viewer with no renderer bound
|
import { cameraOf, findCamera, findQuery } from '../../render/rendererOf.js';
|
||||||
// gets its globe port from the factory this module provides.
|
|
||||||
import '../../render/cesium/globe.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stored (English) failure in the language. HTTP failures from source.js
|
* A stored (English) failure in the language. HTTP failures from source.js
|
||||||
@@ -62,7 +59,6 @@ export function createWeatherLayer({
|
|||||||
feed,
|
feed,
|
||||||
clock,
|
clock,
|
||||||
id = 'weather-radar',
|
id = 'weather-radar',
|
||||||
cesium = Cesium,
|
|
||||||
createRendering = createWeatherRendering,
|
createRendering = createWeatherRendering,
|
||||||
documentRef = globalThis.document,
|
documentRef = globalThis.document,
|
||||||
eventTarget = globalThis.window,
|
eventTarget = globalThis.window,
|
||||||
@@ -108,8 +104,7 @@ export function createWeatherLayer({
|
|||||||
: REGIONAL_INFRARED_MAX_GAP_MS;
|
: REGIONAL_INFRARED_MAX_GAP_MS;
|
||||||
const isLatest = () =>
|
const isLatest = () =>
|
||||||
clock ? clock.getState().mode === 'latest' : followLatest;
|
clock ? clock.getState().mode === 'latest' : followLatest;
|
||||||
const getHost = () =>
|
const getHost = () => imageryHost?.() ?? globeImageryHost(viewer);
|
||||||
imageryHost?.() ?? { collection: viewer?.imageryLayers, kind: 'globe' };
|
|
||||||
const notify = () => listener?.();
|
const notify = () => listener?.();
|
||||||
const shownTime = () => (noFrame ? null : rendering?.getDiagnostics().time);
|
const shownTime = () => (noFrame ? null : rendering?.getDiagnostics().time);
|
||||||
const unsubscribeClock = clock?.subscribe(() => {
|
const unsubscribeClock = clock?.subscribe(() => {
|
||||||
@@ -288,7 +283,7 @@ export function createWeatherLayer({
|
|||||||
viewer = nextViewer;
|
viewer = nextViewer;
|
||||||
rendering = createRendering({
|
rendering = createRendering({
|
||||||
viewer,
|
viewer,
|
||||||
createShell: (options) => createWeatherShell({ ...options, cesium }),
|
createShell: createWeatherShell,
|
||||||
getHost,
|
getHost,
|
||||||
onChange: notify,
|
onChange: notify,
|
||||||
});
|
});
|
||||||
@@ -318,10 +313,11 @@ export function createWeatherLayer({
|
|||||||
enable() {
|
enable() {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
if (!removeCamera) {
|
if (!removeCamera) {
|
||||||
removeCamera = viewer.camera.moveEnd?.addEventListener(() => {
|
removeCamera =
|
||||||
|
findCamera(viewer)?.on('moveEnd', () => {
|
||||||
checkHost();
|
checkHost();
|
||||||
notify();
|
notify();
|
||||||
});
|
}) ?? null;
|
||||||
}
|
}
|
||||||
registerClock();
|
registerClock();
|
||||||
},
|
},
|
||||||
@@ -587,18 +583,13 @@ export function createWeatherLayer({
|
|||||||
const canvas = viewer?.scene?.canvas;
|
const canvas = viewer?.scene?.canvas;
|
||||||
const point =
|
const point =
|
||||||
canvas &&
|
canvas &&
|
||||||
viewer.camera.pickEllipsoid?.(
|
findQuery(viewer)?.pickEllipsoid(
|
||||||
new cesium.Cartesian2(
|
|
||||||
canvas.clientWidth / 2,
|
canvas.clientWidth / 2,
|
||||||
canvas.clientHeight / 2,
|
canvas.clientHeight / 2,
|
||||||
),
|
|
||||||
viewer.scene.globe.ellipsoid,
|
|
||||||
);
|
);
|
||||||
const camera = point
|
const camera = point ? toLonLatH(point) : null;
|
||||||
? cesium.Cartographic.fromCartesian(point, viewer.scene.globe.ellipsoid)
|
const lon = camera ? camera.lon : 0;
|
||||||
: null;
|
const lat = camera ? camera.lat : 0;
|
||||||
const lon = camera ? cesium.Math.toDegrees(camera.longitude) : 0;
|
|
||||||
const lat = camera ? cesium.Math.toDegrees(camera.latitude) : 0;
|
|
||||||
const outside =
|
const outside =
|
||||||
b &&
|
b &&
|
||||||
camera &&
|
camera &&
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
|
import * as Cesium from 'cesium';
|
||||||
|
// The weather layers fly through `cameraOf`, drape through `findGlobe` and
|
||||||
|
// read `findCamera` and `findQuery`; this module is their Cesium side, so it
|
||||||
|
// brings the factories a viewer with no renderer bound gets those ports from.
|
||||||
|
import '../../render/cesium/camera.js';
|
||||||
|
import '../../render/cesium/globe.js';
|
||||||
import { acquireWeatherImage } from './infraredImage.js';
|
import { acquireWeatherImage } from './infraredImage.js';
|
||||||
import { imageryHostStatus } from './imageryHost.js';
|
import { imageryHostStatus } from './imageryHost.js';
|
||||||
import { WEATHER_DETAIL_SIZE, WEATHER_IMAGE_SIZES } from './source.js';
|
import { WEATHER_DETAIL_SIZE, WEATHER_IMAGE_SIZES } from './source.js';
|
||||||
import { msg } from '../../i18n/index.js';
|
import { msg } from '../../i18n/index.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The viewer's own globe imagery, as a weather imagery host: where a layer
|
||||||
|
* drapes when the application shell names no host of its own.
|
||||||
|
* @param {object|null|undefined} viewer A Cesium viewer.
|
||||||
|
* @returns {{collection: object|undefined, kind: 'globe'}}
|
||||||
|
*/
|
||||||
|
export function globeImageryHost(viewer) {
|
||||||
|
return { collection: viewer?.imageryLayers, kind: 'globe' };
|
||||||
|
}
|
||||||
|
|
||||||
/** Metres above the ellipsoid. Lower shells draw first, so lightning draws last. */
|
/** Metres above the ellipsoid. Lower shells draw first, so lightning draws last. */
|
||||||
export const WEATHER_SHELL_HEIGHTS = Object.freeze({
|
export const WEATHER_SHELL_HEIGHTS = Object.freeze({
|
||||||
wind: 5_000,
|
wind: 5_000,
|
||||||
@@ -394,7 +410,7 @@ export function detailWindow(footprint, bounds, previous = null) {
|
|||||||
* that area, so the two images share one mesh and never blend. */
|
* that area, so the two images share one mesh and never blend. */
|
||||||
export function createWeatherShell({
|
export function createWeatherShell({
|
||||||
viewer,
|
viewer,
|
||||||
cesium,
|
cesium = Cesium,
|
||||||
product,
|
product,
|
||||||
height = WEATHER_SHELL_HEIGHTS[product],
|
height = WEATHER_SHELL_HEIGHTS[product],
|
||||||
getHost = () => ({ collection: null, kind: 'tileset' }),
|
getHost = () => ({ collection: null, kind: 'tileset' }),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { WEATHER_IMAGERY_Z } from './imageryOrder.js';
|
|||||||
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
|
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
|
||||||
import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs';
|
import { fakeSceneFrame } from '../../testSupport/fakeCesiumScene.mjs';
|
||||||
import { createCesiumGlobe } from '../../render/cesium/globe.js';
|
import { createCesiumGlobe } from '../../render/cesium/globe.js';
|
||||||
|
import { bindRenderer } from '../../render/rendererOf.js';
|
||||||
import {
|
import {
|
||||||
createShellCesium,
|
createShellCesium,
|
||||||
createShellScene,
|
createShellScene,
|
||||||
@@ -598,6 +599,7 @@ function layerHarness({
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
const viewer = { camera: { moveEnd } };
|
const viewer = { camera: { moveEnd } };
|
||||||
|
bindRenderer(viewer, { camera: cameraOver(viewer) });
|
||||||
const layer = createWeatherLayer({
|
const layer = createWeatherLayer({
|
||||||
clock,
|
clock,
|
||||||
id,
|
id,
|
||||||
@@ -1411,6 +1413,7 @@ for (const [id, product] of [
|
|||||||
positionCartographic: { height: 1200 },
|
positionCartographic: { height: 1200 },
|
||||||
};
|
};
|
||||||
h.viewer.camera = camera;
|
h.viewer.camera = camera;
|
||||||
|
bindRenderer(h.viewer, { camera: cameraOver(h.viewer) });
|
||||||
const events = target();
|
const events = target();
|
||||||
const layer = createWeatherLayer({
|
const layer = createWeatherLayer({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -94,7 +94,6 @@
|
|||||||
"src/layers/transit/lifecycle.js",
|
"src/layers/transit/lifecycle.js",
|
||||||
"src/layers/transit/rendering.js",
|
"src/layers/transit/rendering.js",
|
||||||
"src/layers/transit/testing.js",
|
"src/layers/transit/testing.js",
|
||||||
"src/layers/weather/index.js",
|
|
||||||
"src/layers/weather/shellRendering.js",
|
"src/layers/weather/shellRendering.js",
|
||||||
"src/layers/wind/gpuRendering.js",
|
"src/layers/wind/gpuRendering.js",
|
||||||
"src/layers/wind/relief.js",
|
"src/layers/wind/relief.js",
|
||||||
|
|||||||
Reference in new issue
Block a user