mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw earthquakes through the renderer's draw port
The earthquake discs are now one draw set of ground-clamped filled ellipses per layer, with the same colours, alphas and radii; they had no visible outline before either (Cesium turns outlines off on clamped entity ellipses). The layer and its model no longer import Cesium and leave the allow-list. depthColor now returns a renderer colour [r, g, b, a] rather than a Cesium colour, and depthAccent its CSS. A caller handing the layer a Cesium viewer of their own, with no renderer bound, first loads the new ./render/cesium/unbound export, which provides every unbound factory; the camera factory now loads the draw factory too, so entries that already load it draw as well. A fake draw port for layer tests comes with it.
This commit is contained in:
1 parent
8b2859e501
commit
bb3106991e
16 files changed
+384
-149
No files matched your search
@@ -12,8 +12,9 @@ import { cameraFlightActive } from './internals.js';
|
||||
import { createCesiumFollow } from './follow.js';
|
||||
import { createCesiumControls } from './cameraControls.js';
|
||||
import { cameraOf, findCamera, provideUnboundCamera } from '../rendererOf.js';
|
||||
// Loads the factory an unbound viewer gets its credits port from.
|
||||
// Loads the factories an unbound viewer gets its credits and draw ports from.
|
||||
import './credits.js';
|
||||
import './draw.js';
|
||||
|
||||
/**
|
||||
* `cameraOf` and `findCamera`, for code that already reaches Cesium:
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { provideUnboundDraw } from '../rendererOf.js';
|
||||
import { listenerList, toCartesian, uncaught } from './common.js';
|
||||
// A caller loads this module for a viewer of its own; what draws there
|
||||
// flies through `cameraOf` too, so the camera factory comes with it.
|
||||
import './camera.js';
|
||||
|
||||
/** The contract's colour as Cesium's. */
|
||||
export function toColor(color, alpha = 1) {
|
||||
|
||||
@@ -322,3 +322,40 @@ test('clamped shapes refuse what they cannot draw', () => {
|
||||
);
|
||||
set.dispose();
|
||||
});
|
||||
|
||||
test('the earthquakes layer draws its discs as ground fills on a viewer of its own', async () => {
|
||||
const { createEarthquakesLayer } =
|
||||
await import('../../layers/earthquakes/index.js');
|
||||
const scene = fakeScene();
|
||||
const viewer = { scene };
|
||||
const row = (stableId, lon, mag) => ({
|
||||
stableId,
|
||||
usgsId: stableId,
|
||||
lon,
|
||||
lat: 0,
|
||||
depthKm: 10,
|
||||
mag,
|
||||
place: null,
|
||||
time: null,
|
||||
});
|
||||
const layer = createEarthquakesLayer({
|
||||
source: { getSnapshot: async () => [row('a', 0, 5), row('b', 0.2, 3)] },
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
});
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
const host = scene.added[0];
|
||||
const grounds = [];
|
||||
for (let i = 0; i < host.length; i++)
|
||||
if (host.get(i) instanceof Cesium.GroundPrimitive)
|
||||
grounds.push(host.get(i));
|
||||
// Overlapping discs: one batch each, as the entities' batches had them.
|
||||
assert.equal(grounds.length, 2);
|
||||
const [instance] = grounds[0].geometryInstances;
|
||||
assert.ok(instance.geometry instanceof Cesium.EllipseGeometry);
|
||||
assert.equal(instance.id.id, 'earthquake:a');
|
||||
assert.equal(grounds[0].classificationType, Cesium.ClassificationType.BOTH);
|
||||
layer.destroy();
|
||||
assert.equal(scene.added.length, 0);
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @module render/cesium/unbound
|
||||
* @description What to load, once, before handing the Cesium-free
|
||||
* layers a Cesium viewer with no renderer bound: the factories
|
||||
* that build a camera, credits, effects and draw port over such a viewer
|
||||
* when code first asks for one (`rendererOf.js`).
|
||||
*/
|
||||
import './camera.js';
|
||||
import './effects.js';
|
||||
@@ -70,8 +70,6 @@
|
||||
"src/layers/cyclones/index.js",
|
||||
"src/layers/cyclones/rendering.js",
|
||||
"src/layers/directions/index.js",
|
||||
"src/layers/earthquakes/index.js",
|
||||
"src/layers/earthquakes/model.js",
|
||||
"src/layers/firms/cards.js",
|
||||
"src/layers/firms/lifecycle.js",
|
||||
"src/layers/firms/model.js",
|
||||
|
||||
@@ -248,7 +248,7 @@ export function drawOf(host) {
|
||||
host?.isDestroyed?.()
|
||||
? 'This scene has been destroyed'
|
||||
: 'This scene has no renderer to draw with: bind one, or load the ' +
|
||||
"Cesium adapter's draw port (render/cesium/draw.js) for a viewer " +
|
||||
"Cesium adapter's factories (the ./render/cesium/unbound export) for a viewer " +
|
||||
'with no renderer bound',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
* `render/cesium/effects.js`, which provides the effects factory, and one
|
||||
* that reaches a caller of `findGlobe` must load `render/cesium/globe.js`.
|
||||
* An entry that reaches a caller of `findDraw` or `drawOf` loads
|
||||
* `render/cesium/draw.js` the same way, unless it is Cesium-free: then it
|
||||
* is listed in `DRAW_FROM_CALLER`, and a caller handing it a viewer of
|
||||
* their own loads the package's `./render/cesium/draw` export once.
|
||||
* `render/cesium/draw.js` the same way (the camera factory loads it),
|
||||
* unless it is Cesium-free: then it is listed in `DRAW_FROM_CALLER`, and
|
||||
* a caller handing it a viewer with no renderer bound loads the package's
|
||||
* `./render/cesium/unbound` export once.
|
||||
*
|
||||
* The graph is every static import, re-export and literal dynamic import of
|
||||
* the entry's module and those it reaches, read by the parsers the Cesium
|
||||
@@ -34,6 +35,7 @@ const FACTORY = 'src/render/cesium/camera.js';
|
||||
const EFFECTS_FACTORY = 'src/render/cesium/effects.js';
|
||||
const GLOBE_FACTORY = 'src/render/cesium/globe.js';
|
||||
const DRAW_FACTORY = 'src/render/cesium/draw.js';
|
||||
const UNBOUND = 'src/render/cesium/unbound.js';
|
||||
|
||||
/**
|
||||
* Entries that take their Cesium code injected: the module named here is
|
||||
@@ -57,10 +59,12 @@ const FALLS_BACK = new Set(['src/data/followed.js']);
|
||||
/**
|
||||
* Cesium-free entries that draw through `drawOf`: their own modules cannot
|
||||
* load the Cesium adapter (the Cesium ratchet), so a viewer with no
|
||||
* renderer bound draws once its owner has loaded `./render/cesium/draw`;
|
||||
* until then `drawOf` throws, naming it, rather than draw nothing.
|
||||
* renderer bound draws once its owner has loaded `./render/cesium/unbound`;
|
||||
* until then `drawOf` throws, naming it, rather than draw nothing. That
|
||||
* export loads the camera factory too, so these entries' camera is the
|
||||
* caller's to load the same way.
|
||||
*/
|
||||
const DRAW_FROM_CALLER = new Set([]);
|
||||
const DRAW_FROM_CALLER = new Set(['./layers/earthquakes']);
|
||||
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
|
||||
@@ -171,6 +175,7 @@ test('every public entry that reaches the renderer bridge loads the unbound came
|
||||
bridged += 1;
|
||||
const carrier = INJECTED[key];
|
||||
const loads = (file) => reachable(file, { eager: true }).has(FACTORY);
|
||||
if (DRAW_FROM_CALLER.has(key)) continue;
|
||||
if (!loads(entry) && !(carrier && loads(carrier))) missing.push(key);
|
||||
}
|
||||
assert.ok(bridged > 0, 'no entry reaches the bridge: the walk is broken');
|
||||
@@ -220,6 +225,17 @@ test('every public entry that reaches a findGlobe caller loads the unbound globe
|
||||
checkLookupFactory('findGlobe', GLOBE_FACTORY, { reached: false });
|
||||
});
|
||||
|
||||
test('the unbound export brings every unbound factory', () => {
|
||||
const loaded = reachable(UNBOUND, { eager: true });
|
||||
for (const factory of [
|
||||
FACTORY,
|
||||
EFFECTS_FACTORY,
|
||||
DRAW_FACTORY,
|
||||
'src/render/cesium/credits.js',
|
||||
])
|
||||
assert.ok(loaded.has(factory), factory);
|
||||
});
|
||||
|
||||
test('every public entry that reaches a findDraw caller loads the unbound draw factory, or its caller can', () => {
|
||||
const missing = [];
|
||||
const callsFindDraw = (file) =>
|
||||
@@ -227,8 +243,8 @@ test('every public entry that reaches a findDraw caller loads the unbound draw f
|
||||
/\.(m?js|vue)$/.test(file) &&
|
||||
/\b(findDraw|drawOf)\(/.test(readFileSync(path.join(root, file), 'utf8'));
|
||||
assert.equal(
|
||||
pkg.exports['./render/cesium/draw'],
|
||||
`./${DRAW_FACTORY}`,
|
||||
pkg.exports['./render/cesium/unbound'],
|
||||
`./${UNBOUND}`,
|
||||
'the factory loads through this export',
|
||||
);
|
||||
for (const [key, declaration] of Object.entries(pkg.exports)) {
|
||||
|
||||
Reference in new issue
Block a user