mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw the local GeoJSON layers through the draw port and take them off the Cesium list
The data centre and dam layers (src/data/localGeojsonCore.js) no longer load a Cesium GeoJSON data source. Each build is six draw sets: ground fills, raised fills, draped lines, pins, stems and their tip dots. A walk changes what moved or showed in place. Ground heights come from the heights query, with the globe visibility getter deciding whether terrain is a floor. The stems are sized from the camera pose, and clicks select and fly through the input and camera ports. Point-and-ask reads a draw hit's meta as the feature's context record (drawItemMeta in src/data/pickedContext.js). The drawn parts keep the loader's ids and its reading of each feature: simplestyle fill, stroke and marker colours, opacities, widths and marker sizes; polygons with heights drawn at them and outlined; 3D points standing their pin on the stem tip; ground edges along rhumb lines. Differences: a marker-symbol draws the plain pin; named CSS colours fall back to the layer colour; a raised polygon's outline is 1 px around its outer ring only, and its fill is unlit; the layer no longer sets the viewer's selectedEntity, so Cesium's stock double-click no longer follows a feature; a caller's own Cesium viewer needs gods-eye-view/render/cesium/unbound loaded first.
This commit is contained in:
1 parent
333c9b39fe
commit
b0ed9d7e90
14 files changed
+1547
-947
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { localGeoJsonServices } from '../app/localGeojsonServices.js';
|
||||
import { createLocalGeoJsonLayer as createLayer } from './localGeojsonCore.js';
|
||||
import { getContextStore } from './contextStore.js';
|
||||
import { bindFakeGroundRenderer } from '../testSupport/fakeGroundRenderer.mjs';
|
||||
|
||||
/** The catalog's services, with the overlay host each test supplies. */
|
||||
const createLocalGeoJsonLayer = (options) =>
|
||||
@@ -28,20 +28,21 @@ function harness(t) {
|
||||
globalThis.window = { dispatchEvent() {} };
|
||||
t.after(() => {
|
||||
layer.destroy(viewer);
|
||||
fake.unbind();
|
||||
if (previousWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = previousWindow;
|
||||
});
|
||||
const sources = new Set();
|
||||
const listeners = new Set();
|
||||
const event = { addEventListener(fn) { listeners.add(fn); return () => listeners.delete(fn); } };
|
||||
let handlers = 0;
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
async add(source) { sources.add(source); return source; },
|
||||
remove(source) { return sources.delete(source); },
|
||||
},
|
||||
scene: { canvas: {}, preRender: event, requestRender() {} },
|
||||
camera: { moveEnd: event },
|
||||
const viewer = {};
|
||||
const fake = bindFakeGroundRenderer(viewer);
|
||||
// The builds drawn now: one per five live sets (fills, lines, pins,
|
||||
// stems and dots).
|
||||
const sources = {
|
||||
get size() { return fake.liveSets().length / 6; },
|
||||
get shown() { return fake.liveSets().every((set) => set.show); },
|
||||
};
|
||||
const listeners = {
|
||||
get size() { return fake.preRender.listeners.size + fake.moveEnd.listeners.size; },
|
||||
};
|
||||
const create = () => createLocalGeoJsonLayer({
|
||||
id: 'local-dams', name: 'Dams', color: '#0088ff', url: '/dams.geojsonl',
|
||||
@@ -55,7 +56,7 @@ function harness(t) {
|
||||
}),
|
||||
});
|
||||
const layer = create();
|
||||
return { layer, create, viewer, sources, listeners, handlers: () => handlers };
|
||||
return { layer, create, viewer, fake, sources, listeners, handlers: () => handlers };
|
||||
}
|
||||
|
||||
test('destroy removes context records and permits a fresh replacement', async t => {
|
||||
@@ -66,7 +67,7 @@ test('destroy removes context records and permits a fresh replacement', async t
|
||||
assert.equal(getContextStore().entities.size, 1);
|
||||
env.layer.disable(env.viewer);
|
||||
assert.equal(getContextStore().entities.size, 0, 'disable releases its records with the source');
|
||||
assert.equal(env.sources.size, 0, 'disable removes the built source from the scene');
|
||||
assert.equal(env.sources.size, 0, 'disable disposes the built sets');
|
||||
env.layer.destroy(env.viewer);
|
||||
assert.equal(getContextStore().entities.size, 0);
|
||||
assert.equal(env.sources.size, 0);
|
||||
@@ -81,7 +82,7 @@ test('destroy removes context records and permits a fresh replacement', async t
|
||||
assert.equal(getContextStore().entities.size, 0);
|
||||
});
|
||||
|
||||
for (const phase of ['fetch', 'text', 'parse', 'add']) {
|
||||
for (const phase of ['fetch', 'text']) {
|
||||
test(`destroy during ${phase} leaves no late objects or context records`, async t => {
|
||||
const env = harness(t);
|
||||
const entered = deferred();
|
||||
@@ -94,17 +95,6 @@ for (const phase of ['fetch', 'text', 'parse', 'add']) {
|
||||
if (phase === 'text') return { ok: true, text: () => pause(dataset) };
|
||||
return response();
|
||||
});
|
||||
if (phase === 'parse') {
|
||||
const load = Cesium.GeoJsonDataSource.load;
|
||||
t.mock.method(Cesium.GeoJsonDataSource, 'load', async (...args) => pause(await load(...args)));
|
||||
}
|
||||
if (phase === 'add') {
|
||||
t.mock.method(env.viewer.dataSources, 'add', async source => {
|
||||
await pause();
|
||||
env.sources.add(source);
|
||||
return source;
|
||||
});
|
||||
}
|
||||
const loading = env.layer.enable(env.viewer);
|
||||
await entered.promise;
|
||||
env.layer.destroy(env.viewer);
|
||||
@@ -135,7 +125,7 @@ test('concurrent enable and disable/re-enable share one pending dataset load', a
|
||||
assert.equal(env.sources.size, 1);
|
||||
assert.equal(env.handlers(), 1);
|
||||
assert.equal(env.listeners.size, 2);
|
||||
assert.equal([...env.sources][0].show, true);
|
||||
assert.equal(env.sources.shown, true);
|
||||
});
|
||||
|
||||
test('disable during loading releases the completed source; re-enable rebuilds without refetching', async t => {
|
||||
@@ -151,7 +141,7 @@ test('disable during loading releases the completed source; re-enable rebuilds w
|
||||
assert.equal(getContextStore().entities.size, 0);
|
||||
await env.layer.enable(env.viewer);
|
||||
assert.equal(env.sources.size, 1);
|
||||
assert.equal([...env.sources][0].show, true);
|
||||
assert.equal(env.sources.shown, true);
|
||||
assert.equal(fetchMock.mock.callCount(), 1, 'the parsed dataset is cached across the toggle');
|
||||
});
|
||||
|
||||
@@ -159,19 +149,19 @@ test('a toggle-off frees the entities and a toggle-on rebuilds them from the cac
|
||||
const env = harness(t);
|
||||
const fetchMock = t.mock.method(globalThis, 'fetch', async () => response());
|
||||
await env.layer.enable(env.viewer);
|
||||
const first = [...env.sources][0];
|
||||
assert.equal(first.entities.values.length, 1);
|
||||
const first = env.fake.set('fills');
|
||||
assert.equal(first.items.size, 1);
|
||||
assert.equal(getContextStore().entities.size, 1);
|
||||
env.layer.disable(env.viewer);
|
||||
assert.equal(env.sources.size, 0, 'no data source stays registered while the layer is off');
|
||||
assert.equal(env.sources.size, 0, 'no set stays drawn while the layer is off');
|
||||
assert.equal(getContextStore().entities.size, 0);
|
||||
assert.equal(env.layer.getLodDiagnostics().total, 0);
|
||||
assert.equal(env.layer.getStats().count, 1, 'the row keeps reporting the dataset size');
|
||||
await env.layer.enable(env.viewer);
|
||||
const second = [...env.sources][0];
|
||||
assert.notEqual(second, first, 're-enable builds a fresh source');
|
||||
assert.equal(second.show, true);
|
||||
assert.equal(second.entities.values.length, 1);
|
||||
const second = env.fake.set('fills');
|
||||
assert.notEqual(second, first, 're-enable builds fresh sets');
|
||||
assert.equal(env.sources.shown, true);
|
||||
assert.equal(second.items.size, 1);
|
||||
assert.equal(getContextStore().entities.size, 1);
|
||||
assert.equal(fetchMock.mock.callCount(), 1, 'no second fetch for a bundled dataset');
|
||||
assert.equal(env.layer.getLodDiagnostics().total, 1);
|
||||
|
||||
Reference in new issue
Block a user