mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 10:42:22 +00:00
Draw the air quality stations through the renderer's draw port
The station discs are now one draw set of ground-clamped filled ellipses per layer, with the same band colours, alpha and radius, and their readings as item meta; they had no visible outline before either (Cesium turns outlines off on clamped entity ellipses). The readout's in-view list reads the view rectangle through the camera port. The layer no longer imports Cesium and leaves the allow-list; a caller handing it a Cesium viewer of their own, with no renderer bound, loads the ./render/cesium/unbound export once first. Double-clicking a station no longer starts the viewer's entity follow, since draw items are not entities.
This commit is contained in:
1 parent
03ff8f291f
commit
2061f5647c
9 files changed
+186
-82
No files matched your search
@@ -3,20 +3,12 @@ import test from 'node:test';
|
||||
import { createAirQualityLayer } from './index.js';
|
||||
import { layerFeedState } from '../../data/feedState.js';
|
||||
import { STALE_AFTER_MS } from './model.js';
|
||||
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
|
||||
function harness(source) {
|
||||
const sources = [];
|
||||
function harness(source, renderer = {}) {
|
||||
const events = [];
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
add(value) {
|
||||
sources.push(value);
|
||||
},
|
||||
remove(value) {
|
||||
sources.splice(sources.indexOf(value), 1);
|
||||
},
|
||||
},
|
||||
};
|
||||
const viewer = {};
|
||||
const { draw } = bindFakeDraw(viewer, renderer);
|
||||
const layer = createAirQualityLayer({
|
||||
source,
|
||||
overlayHost: {
|
||||
@@ -29,7 +21,8 @@ function harness(source) {
|
||||
});
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
return { layer, viewer, sources, events };
|
||||
const markers = () => draw.find('air-quality:');
|
||||
return { layer, viewer, draw, markers, events };
|
||||
}
|
||||
|
||||
const reading = (id, value, overrides = {}) => ({
|
||||
@@ -61,12 +54,68 @@ test('a layer requires both a snapshot source and an overlay host', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('initialization is single-use and owns exactly one data source', () => {
|
||||
const { layer, viewer, sources } = harness(staticSource([]));
|
||||
assert.equal(sources.length, 1);
|
||||
test('initialization is single-use and owns exactly one draw set', () => {
|
||||
const { layer, viewer, draw, markers } = harness(staticSource([]));
|
||||
const owned = markers();
|
||||
assert.equal(owned.kind, 'shapes');
|
||||
assert.equal(
|
||||
[...draw.sets.values()].filter((set) => !set.disposed).length,
|
||||
1,
|
||||
);
|
||||
assert.throws(() => layer.init(viewer), /already initialized/);
|
||||
layer.destroy(viewer);
|
||||
assert.equal(sources.length, 0);
|
||||
assert.equal(owned.disposed, true);
|
||||
});
|
||||
|
||||
test('stations are ground discs in their band colour, shown only while enabled', async () => {
|
||||
const { layer, markers } = harness(
|
||||
staticSource([reading('A', 2), reading('B', 7, { color: '#c1121f' })]),
|
||||
);
|
||||
assert.equal(await layer.update(), true);
|
||||
const set = markers();
|
||||
assert.equal(set.show, true);
|
||||
assert.deepEqual(
|
||||
[...set.items.keys()],
|
||||
['air-quality:eccc:A', 'air-quality:eccc:B'],
|
||||
);
|
||||
const disc = set.items.get('air-quality:eccc:B');
|
||||
assert.deepEqual(disc.geometry, {
|
||||
kind: 'ellipse',
|
||||
center: { lon: -79.38, lat: 43.65 },
|
||||
semiMajor: 6_000,
|
||||
semiMinor: 6_000,
|
||||
});
|
||||
assert.equal(disc.height, 'clampGround');
|
||||
assert.equal(disc.clampTo, 'both');
|
||||
assert.deepEqual(disc.fill, [0xc1 / 255, 0x12 / 255, 0x1f / 255, 0.35]);
|
||||
assert.equal(disc.outline, undefined);
|
||||
assert.equal(disc.meta.name, 'B');
|
||||
assert.equal(disc.meta.value, 7);
|
||||
layer.disable();
|
||||
assert.equal(set.show, false);
|
||||
layer.enable();
|
||||
assert.equal(set.show, true);
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(set.items.size, 2, 'a refresh replaces, not appends');
|
||||
});
|
||||
|
||||
test('the readout lists only readings inside the camera port view rectangle', async () => {
|
||||
const { layer } = harness(
|
||||
staticSource([
|
||||
reading('Toronto', 2),
|
||||
reading('Vancouver', 4, { lat: 49.28, lon: -123.12 }),
|
||||
]),
|
||||
{
|
||||
camera: {
|
||||
viewRectangle: () => ({ west: -90, south: 40, east: -70, north: 50 }),
|
||||
},
|
||||
},
|
||||
);
|
||||
await layer.update();
|
||||
assert.deepEqual(
|
||||
layer.getRowControls().list.items.map((item) => item.text),
|
||||
['Toronto · Low health risk'],
|
||||
);
|
||||
});
|
||||
|
||||
test('a refresh renders readings and publishes an overlay cohort', async () => {
|
||||
|
||||
Reference in new issue
Block a user