mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
The Street Level view maths no longer reads Cesium. The camera's place comes from the camera port's pose; the visible box and the view focus cast the query port's screen rays and meet them with the ground, the WGS84 ellipsoid raised to the ground height, in geo; heights come from the query port; the horizon cull for the marker and the cones tests against an ellipsoid 1,000 m below WGS84 in geo and re-culls on the frame port's pre-render. Ground clicks, the screen-centre aim, the nearest-image point, photo framing, the coverage refresh and the ground re-measure read the same ports and convert positions with geo. geo's ellipsoid functions (toLonLatH, rayEllipsoid and those under them) and horizonFrom take an optional ellipsoid, made with ellipsoidOf or offsetEllipsoid; anything else, a map index included, means WGS84. Tests check them against Cesium on raised and lowered ellipsoids. view, index, cameraFraming, groundClick and selection leave the Cesium allow-list. The Street Level entries are Cesium-free callers of the unbound factories: given a viewer of a caller's own, with no renderer bound, the caller loads ./render/cesium/unbound first. GhostMaps, which uses the horizon cull and is still on the list, loads the camera factory itself. Differences the contract does not let us avoid: - The ground under the camera no longer reads whether the globe is shown (the globe port has no visibility getter). Where 3D tiles answer under the camera they decide, as they did under Google 3D; elsewhere the terrain answers, then the drawn surface below the camera. Over 3D tiles shown on a map with the globe (and under other primitives at the nadir) those now count as ground. - Without depth-texture support the query port answers no heights, the terrain included, so the ground then reads as the ellipsoid. - selection and groundClick still read the click dispatcher's own pick for now; they move to draw-set hits with the coverage lines.
322 lines
12 KiB
JavaScript
322 lines
12 KiB
JavaScript
/**
|
|
* A public entry that reaches the renderer bridge (`rendererOf.js`) may hand
|
|
* `cameraOf` a viewer of the caller's own, with no renderer bound. The
|
|
* bridge builds a camera port for it with the factory the Cesium adapter
|
|
* provides as `render/cesium/camera.js` loads, so every such entry must load
|
|
* that module too. It loads `render/cesium/credits.js`, whose factory
|
|
* builds `findCredits`' port for such a viewer the same way.
|
|
* Likewise an entry that reaches a caller of `findEffects` must load
|
|
* `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 (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. An entry that reaches a caller of
|
|
* `findQuery` or `queryOf` loads `render/cesium/query.js`, and one that
|
|
* reaches a caller of `findFrame` or `frameOf` loads
|
|
* `render/cesium/frame.js` (the camera factory loads both), or is such a
|
|
* Cesium-free entry.
|
|
*
|
|
* 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
|
|
* ratchet uses; bare specifiers (packages) end the walk.
|
|
*/
|
|
import assert from 'node:assert/strict';
|
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { parsers } from 'prettier/plugins/babel.mjs';
|
|
import { parse as parseSfc } from 'vue/compiler-sfc';
|
|
|
|
const root = path.resolve(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'../..',
|
|
);
|
|
const BRIDGE = 'src/render/rendererOf.js';
|
|
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 QUERY_FACTORY = 'src/render/cesium/query.js';
|
|
const FRAME_FACTORY = 'src/render/cesium/frame.js';
|
|
const UNBOUND = 'src/render/cesium/unbound.js';
|
|
|
|
/**
|
|
* Entries that take their Cesium code injected: the module named here is
|
|
* GEV's Cesium side for them, and must load the factories. Given another, the
|
|
* entry's flight finds no camera (`findCamera`) and does nothing. Visual
|
|
* settings are given their viewer by the application shell, which loads
|
|
* both factories; without it, their styles keep records and draw nothing.
|
|
*/
|
|
const INJECTED = {
|
|
'./layers/recent-imagery': 'src/layers/recentImagery/rendering.js',
|
|
'./ui/visual-settings': 'src/ui/applicationShell.js',
|
|
};
|
|
|
|
/**
|
|
* Modules whose use of the bridge holds up without the factory: with no
|
|
* port they read Cesium's `trackedEntity` instead, which is all an unbound
|
|
* viewer can follow by.
|
|
*/
|
|
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/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([
|
|
'./layers/earthquakes',
|
|
'./layers/bikeshare',
|
|
'./layers/gnss',
|
|
'./layers/perimeters',
|
|
'./layers/awareness',
|
|
'./layers/submarine-cables',
|
|
'./layers/alpr',
|
|
'./layers/vessels',
|
|
'./layers/street-level',
|
|
'./layers/street-level/mapillary',
|
|
'./layers/street-level/kartaview',
|
|
'./layers/street-level/panoramax',
|
|
]);
|
|
|
|
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
|
|
/** The browser module an export resolves to, or null for Node-only ones. */
|
|
function browserTarget(declaration) {
|
|
if (typeof declaration === 'string') return declaration;
|
|
if (!declaration || typeof declaration !== 'object') return null;
|
|
for (const condition of ['browser', 'import', 'default']) {
|
|
const target = browserTarget(declaration[condition]);
|
|
if (target) return target;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function specifiersOf(file) {
|
|
let code = readFileSync(path.join(root, file), 'utf8');
|
|
if (file.endsWith('.vue')) {
|
|
const { descriptor } = parseSfc(code, { filename: file });
|
|
code = [descriptor.script, descriptor.scriptSetup]
|
|
.filter(Boolean)
|
|
.map((block) => block.content)
|
|
.join('\n');
|
|
}
|
|
const found = [];
|
|
const walk = (node) => {
|
|
if (!node || typeof node !== 'object') return;
|
|
if (Array.isArray(node)) return node.forEach(walk);
|
|
if (
|
|
(node.type === 'ImportDeclaration' ||
|
|
node.type === 'ExportNamedDeclaration' ||
|
|
node.type === 'ExportAllDeclaration') &&
|
|
node.source
|
|
)
|
|
found.push({ specifier: node.source.value, lazy: false });
|
|
if (
|
|
node.type === 'ImportExpression' &&
|
|
node.source?.type === 'StringLiteral'
|
|
)
|
|
found.push({ specifier: node.source.value, lazy: true });
|
|
if (
|
|
node.type === 'CallExpression' &&
|
|
node.callee?.type === 'Import' &&
|
|
node.arguments[0]?.type === 'StringLiteral'
|
|
)
|
|
found.push({ specifier: node.arguments[0].value, lazy: true });
|
|
for (const key of Object.keys(node))
|
|
if (key !== 'loc' && key !== 'start' && key !== 'end') walk(node[key]);
|
|
};
|
|
walk(parsers.babel.parse(code));
|
|
return found;
|
|
}
|
|
|
|
/** A relative specifier as a repository file, or null when it is a package. */
|
|
function resolve(from, specifier) {
|
|
const bare = specifier.split('?')[0];
|
|
if (!bare.startsWith('.')) return null;
|
|
const base = path.join(path.dirname(from), bare);
|
|
const candidates = ['', '.js', '.mjs', '.vue', '/index.js', '/index.mjs'];
|
|
for (const suffix of candidates) {
|
|
const full = path.join(root, base + suffix);
|
|
if (existsSync(full) && statSync(full).isFile())
|
|
return path.normalize(base + suffix);
|
|
}
|
|
// A subgraph dropped here would hide a missing factory.
|
|
throw new Error(`${from}: cannot resolve ${specifier}`);
|
|
}
|
|
|
|
/**
|
|
* The modules `entry` reaches. With `eager`, only through static imports:
|
|
* what has loaded once the entry has, before any lazy import resolves.
|
|
*/
|
|
function reachable(entry, { eager = false } = {}) {
|
|
const seen = new Set([entry]);
|
|
const queue = [entry];
|
|
while (queue.length) {
|
|
const file = queue.pop();
|
|
if (!/\.(m?js|vue)$/.test(file)) continue;
|
|
for (const { specifier, lazy } of specifiersOf(file)) {
|
|
if (eager && lazy) continue;
|
|
const next = resolve(file, specifier);
|
|
if (next === BRIDGE && FALLS_BACK.has(file)) continue;
|
|
if (next && !seen.has(next)) {
|
|
seen.add(next);
|
|
queue.push(next);
|
|
}
|
|
}
|
|
}
|
|
return seen;
|
|
}
|
|
|
|
test('the unbound camera factory loads the unbound credits factory', () => {
|
|
assert.ok(
|
|
reachable(FACTORY, { eager: true }).has('src/render/cesium/credits.js'),
|
|
);
|
|
});
|
|
|
|
test('every public entry that reaches the renderer bridge loads the unbound camera factory', () => {
|
|
const missing = [];
|
|
let bridged = 0;
|
|
for (const [key, declaration] of Object.entries(pkg.exports)) {
|
|
const target = browserTarget(declaration);
|
|
if (typeof target !== 'string' || !target.startsWith('./src/')) continue;
|
|
const entry = path.normalize(target.slice(2));
|
|
const graph = reachable(entry);
|
|
// Any path to the bridge counts, lazy or not; only an eager one loads
|
|
// the factory in time for the first `cameraOf`.
|
|
if (!graph.has(BRIDGE)) continue;
|
|
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');
|
|
assert.deepEqual(
|
|
missing,
|
|
[],
|
|
`These entries can reach cameraOf without ${FACTORY}; import it where the entry first reaches the bridge.`,
|
|
);
|
|
});
|
|
|
|
/**
|
|
* Every public entry reaching a caller of `lookup` loads `factory`. With
|
|
* `reached`, at least one entry must reach one, or the walk is broken.
|
|
* With `fromCaller`, the Cesium-free entries listed in
|
|
* `DRAW_FROM_CALLER` may leave the factory to their caller.
|
|
*/
|
|
function checkLookupFactory(
|
|
lookup,
|
|
factory,
|
|
{ reached = true, fromCaller = false } = {},
|
|
) {
|
|
const missing = [];
|
|
let reaching = 0;
|
|
const calls = (file) =>
|
|
!file.startsWith('src/render/') &&
|
|
/\.(m?js|vue)$/.test(file) &&
|
|
new RegExp(`\\b${lookup}\\b`).test(
|
|
readFileSync(path.join(root, file), 'utf8'),
|
|
);
|
|
for (const [key, declaration] of Object.entries(pkg.exports)) {
|
|
const target = browserTarget(declaration);
|
|
if (typeof target !== 'string' || !target.startsWith('./src/')) continue;
|
|
const entry = path.normalize(target.slice(2));
|
|
if (![...reachable(entry)].some(calls)) continue;
|
|
reaching += 1;
|
|
if (fromCaller && DRAW_FROM_CALLER.has(key)) continue;
|
|
const carrier = INJECTED[key];
|
|
const loads = (file) => reachable(file, { eager: true }).has(factory);
|
|
if (!loads(entry) && !(carrier && loads(carrier))) missing.push(key);
|
|
}
|
|
if (reached)
|
|
assert.ok(reaching > 0, `no entry reaches ${lookup}: the walk is broken`);
|
|
assert.deepEqual(
|
|
missing,
|
|
[],
|
|
`These entries can reach ${lookup} without ${factory}; import it where the entry first reaches the lookup.`,
|
|
);
|
|
}
|
|
|
|
test('every public entry that reaches a findEffects caller loads the unbound effects factory', () => {
|
|
checkLookupFactory('findEffects', EFFECTS_FACTORY);
|
|
});
|
|
|
|
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
|
|
// A caller may take `findGlobe` as a default rather than call it, so any
|
|
// use of the name counts.
|
|
checkLookupFactory('findGlobe', GLOBE_FACTORY);
|
|
});
|
|
|
|
test('every public entry that reaches a findQuery or queryOf caller loads the unbound query factory, or its caller can', () => {
|
|
checkLookupFactory('findQuery', QUERY_FACTORY, { fromCaller: true });
|
|
checkLookupFactory('queryOf', QUERY_FACTORY, {
|
|
reached: false,
|
|
fromCaller: true,
|
|
});
|
|
});
|
|
|
|
test('every public entry that reaches a findFrame or frameOf caller loads the unbound frame factory, or its caller can', () => {
|
|
checkLookupFactory('findFrame', FRAME_FACTORY, { fromCaller: true });
|
|
checkLookupFactory('frameOf', FRAME_FACTORY, {
|
|
reached: false,
|
|
fromCaller: true,
|
|
});
|
|
});
|
|
|
|
test('the unbound camera factory loads the unbound query and frame factories', () => {
|
|
const loaded = reachable(FACTORY, { eager: true });
|
|
assert.ok(loaded.has(QUERY_FACTORY));
|
|
assert.ok(loaded.has(FRAME_FACTORY));
|
|
});
|
|
|
|
test('the unbound export brings every unbound factory', () => {
|
|
const loaded = reachable(UNBOUND, { eager: true });
|
|
for (const factory of [
|
|
FACTORY,
|
|
EFFECTS_FACTORY,
|
|
DRAW_FACTORY,
|
|
QUERY_FACTORY,
|
|
FRAME_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) =>
|
|
!file.startsWith('src/render/') &&
|
|
/\.(m?js|vue)$/.test(file) &&
|
|
/\b(findDraw|drawOf)\(/.test(readFileSync(path.join(root, file), 'utf8'));
|
|
assert.equal(
|
|
pkg.exports['./render/cesium/unbound'],
|
|
`./${UNBOUND}`,
|
|
'the factory loads through this export',
|
|
);
|
|
for (const [key, declaration] of Object.entries(pkg.exports)) {
|
|
const target = browserTarget(declaration);
|
|
if (typeof target !== 'string' || !target.startsWith('./src/')) continue;
|
|
const entry = path.normalize(target.slice(2));
|
|
if (![...reachable(entry)].some(callsFindDraw)) continue;
|
|
const carrier = INJECTED[key];
|
|
const loads = (file) => reachable(file, { eager: true }).has(DRAW_FACTORY);
|
|
if (DRAW_FROM_CALLER.has(key)) {
|
|
assert.ok(!loads(entry), `${key} loads the factory: unlist it`);
|
|
continue;
|
|
}
|
|
if (!loads(entry) && !(carrier && loads(carrier))) missing.push(key);
|
|
}
|
|
assert.deepEqual(
|
|
missing,
|
|
[],
|
|
`These entries can reach findDraw without ${DRAW_FACTORY}; import it, or list a Cesium-free entry in DRAW_FROM_CALLER.`,
|
|
);
|
|
});
|