Draw imported files through the draw port, off Cesium

Import no longer loads KML, KMZ, GeoJSON and GPX through Cesium's data
source loaders. geoImportFeatures.js reads the sanitized file into plain
pins, lines, walls, polygons and ground overlays with the looks those
loaders gave them: icon, scale, colour, heading and hot spot, the shared
and inline style precedence, line and polygon colours and widths,
extruded and clamped geometry, rotated boxes and quads, and GeoJSON's
48 px pins, draped lines along rhumb lines and quarter-opacity fills.
geoImportPins.js draws them in three draw sets per file, places ground
pins through the height service (0 on the bare ellipsoid, whose coarse
tiles sag below it; the mesh nearby on photoreal maps), follows a
double-clicked pin, frames Fly-to, and shows, hides and removes them.

The Cesium adapter now draws two members the contract already had: an
icon's pixel offset and the wall shape. Image fills draw in the
translucent pass, so an overlay's own alpha blends as it did.

The Cesium allow-list is now empty; the ratchet test checks that its
scan still sees each way of reaching Cesium. The QA scripts read what a
file drew through the import's drawn(id), and the large-file check
compares it with Cesium's own reading of the same KML. A file the
renderer refuses to draw is refused by itself, without stopping its
batch. Two translations no longer used are dropped.
This commit is contained in:
Sameh Khamis committed 2026-11-09 15:50:53 -08:00
1 parent c073064507
commit 6c1f91014c
33 files changed
+2608 -1177

No files matched your search

+1 -2
View File
@@ -411,12 +411,11 @@ test('the imported files render what the file import publishes and keep focus',
const viewer = {
container: document.createElement('div'),
scene: { requestRender() {} },
dataSources: { add: async (ds) => ds, remove: () => true },
};
const tool = initGeoFileImport({
viewer,
load: async (file) => ({
dataSource: { show: true },
drawing: { show: true, destroy() {} },
name: file.name,
format: file.name.endsWith('.kml') ? 'kml' : 'geojson',
entityCount: 2,
+1 -1
View File
@@ -9,7 +9,7 @@ import { findCamera } from '../render/rendererOf.js';
/**
* Fly synchronously to a footprint, `[lon, lat, height]` points (degrees,
* metres) such as a file's (`dataSourcePoints`); later navigation always
* metres) such as a file's (`importedDrawingPoints`); later navigation always
* owns its camera. False when there is nothing to frame or no camera.
*/
export function flyToFootprint(
+82 -79
View File
@@ -5,44 +5,66 @@ import {
cancelCameraArrival,
ownCameraArrival,
} from '../data/cameraArrival.js';
import { dataSourcePoints } from '../data/geoImportPins.js';
import {
createImportedDrawing,
importedDrawingPoints,
} from '../data/geoImportPins.js';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import { fakeSceneQuery } from '../testSupport/fakeCesiumScene.mjs';
import { flyToFootprint } from './flyToDataSource.js';
/** As the file import flies to one of its files. */
const flyToDataSource = (viewer, dataSource) =>
flyToFootprint(viewer, dataSourcePoints(dataSource));
const flyToDataSource = (viewer, drawing) =>
flyToFootprint(viewer, importedDrawingPoints(drawing));
/** An imported file's drawing of `features`, not drawn. */
const drawingOf = (features) => createImportedDrawing({}, features);
const pin = (lon, lat, height = 0, mode = 'absolute') => ({
kind: 'pin',
lon,
lat,
height,
mode,
image: 'pin.png',
size: [32, 32],
});
const line = (coords, mode = 'draped') => ({
kind: 'line',
coords,
mode,
color: [1, 1, 1, 1],
width: 1,
});
/** A Cesium-shaped viewer double, bound to the camera and query ports. */
const bound = (viewer) =>
bindFakeCesiumCamera(viewer, { query: fakeSceneQuery(viewer) });
function source() {
const ds = new Cesium.CustomDataSource('t');
ds.entities.add({
position: Cesium.Cartesian3.fromDegrees(-122.4862, 37.7694, -2667),
billboard: { heightReference: Cesium.HeightReference.CLAMP_TO_GROUND },
});
ds.entities.add({
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([
-122.49, 37.77, -122.48, 37.771,
]),
return drawingOf([
pin(-122.4862, 37.7694, 0, 'clamp'),
line([
[-122.49, 37.77, 0],
[-122.48, 37.771, 0],
]),
{
kind: 'polygon',
rings: [
[
[-122.5, 37.76, 0],
[-122.49, 37.76, 0],
[-122.49, 37.765, 0],
],
],
clamp: true,
fill: [1, 1, 1, 0.25],
outline: null,
},
});
ds.entities.add({
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
-122.5, 37.76, -122.49, 37.76, -122.49, 37.765,
]),
},
});
return ds;
]);
}
test('points come from positions, lines and polygons, as lon/lat only', () => {
const points = dataSourcePoints(source());
const points = importedDrawingPoints(source());
assert.equal(points.length, 6);
assert.ok(Math.abs(points[0][0] + 122.4862) < 1e-6);
assert.ok(Math.abs(points[0][1] - 37.7694) < 1e-6);
@@ -71,10 +93,7 @@ test('the camera frames the footprint at the surface, never a buried center', ()
calls[0].options.complete();
assert.equal(handedOver, true, 'the ground guard runs on landing');
cancelCameraArrival(viewer);
assert.equal(
flyToDataSource(viewer, new Cesium.CustomDataSource('empty')),
false,
);
assert.equal(flyToDataSource(viewer, drawingOf([])), false);
assert.equal(
calls.length,
1,
@@ -86,13 +105,11 @@ test('a very long track is framed without spreading it into a call', () => {
// 400k vertices: `push(...line)` throws RangeError (too many arguments)
// well below this; the walk keeps a bounded sample and both ends.
const n = 400_000;
const line = new Array(n);
for (let i = 0; i < n; i++)
line[i] = Cesium.Cartesian3.fromDegrees(-120 + (i / n) * 2, 40);
const ds = new Cesium.CustomDataSource('long');
ds.entities.add({ polyline: { positions: line } });
ds.entities.add({ position: Cesium.Cartesian3.fromDegrees(-110, 41) });
const points = dataSourcePoints(ds);
const coords = new Array(n);
for (let i = 0; i < n; i++) coords[i] = [-120 + (i / n) * 2, 40, 0];
const points = importedDrawingPoints(
drawingOf([line(coords), pin(-110, 41)]),
);
assert.equal(points.length, n + 1, 'every vertex contributes to framing');
const lons = points.map(([lon]) => lon);
assert.ok(
@@ -103,34 +120,37 @@ test('a very long track is framed without spreading it into a call', () => {
});
test('framing includes a sparse interior outlier, walls and rotated overlays', () => {
const ds = new Cesium.CustomDataSource('bounds');
const line = Array.from({ length: 200031 }, () =>
Cesium.Cartesian3.fromDegrees(0, 0),
const coords = Array.from({ length: 200031 }, () => [0, 0, 0]);
coords[12345] = [20, 10, 0];
const points = importedDrawingPoints(
drawingOf([
line(coords),
{
kind: 'wall',
coords: [
[30, 10, 0],
[31, 11, 0],
],
},
{
kind: 'overlay',
rect: { west: 40, south: 0, east: 41, north: 1 },
rotation: Math.PI / 4,
},
]),
);
line[12345] = Cesium.Cartesian3.fromDegrees(20, 10);
ds.entities.add({ polyline: { positions: line } });
ds.entities.add({
wall: { positions: Cesium.Cartesian3.fromDegreesArray([30, 10, 31, 11]) },
});
ds.entities.add({
rectangle: {
coordinates: Cesium.Rectangle.fromDegrees(40, 0, 41, 1),
rotation: Math.PI / 4,
},
});
const points = dataSourcePoints(ds);
assert.ok(points.some(([lon]) => Math.abs(lon - 20) < 1e-6));
assert.ok(points.some(([lon]) => Math.abs(lon - 31) < 1e-6));
assert.ok(points.some(([lon]) => lon > 41));
});
test('portrait framing accounts for FOV, high ground and symmetric extents', () => {
const ds = new Cesium.CustomDataSource('view');
ds.entities.add({
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray([-105, 39, -104.9, 39]),
},
});
const ds = drawingOf([
line([
[-105, 39, 0],
[-104.9, 39, 0],
]),
]);
const calls = [];
const viewer = bound({
scene: { globe: { getHeight: () => 2600 } },
@@ -149,34 +169,17 @@ test('portrait framing accounts for FOV, high ground and symmetric extents', ()
viewer.camera.frustum.aspectRatio = 16 / 9;
flyToDataSource(viewer, ds);
assert.ok(calls[0].options.offset.range > calls[1].options.offset.range);
const symmetric = {
entities: {
values: [
{ position: { getValue: () => new Cesium.Cartesian3(6378137, 0, 0) } },
{ position: { getValue: () => new Cesium.Cartesian3(-6378137, 0, 0) } },
],
},
};
const symmetric = drawingOf([pin(0, 0), pin(180, 0)]);
assert.doesNotThrow(() => flyToDataSource(viewer, symmetric));
assert.ok(Number.isFinite(calls.at(-1).options.offset.range));
assert.doesNotThrow(() => calls.at(-1).options.complete());
cancelCameraArrival(viewer);
});
test('non-finite positions and hidden features never enter the camera footprint', () => {
const position = (p) => ({ position: { getValue: () => p } });
const points = dataSourcePoints({
entities: {
values: [
position(new Cesium.Cartesian3(NaN, 1, 2)),
{
...position(Cesium.Cartesian3.fromDegrees(10, 10)),
isShowing: false,
},
position(Cesium.Cartesian3.fromDegrees(20, 20)),
],
},
});
assert.equal(points.length, 1);
assert.ok(Math.abs(points[0][0] - 20) < 1e-6);
test('non-finite positions are refused and a hidden file has no footprint', () => {
assert.throws(() => drawingOf([pin(Number.NaN, 1)]), /invalid point/);
const drawing = drawingOf([pin(20, 20)]);
assert.equal(importedDrawingPoints(drawing).length, 1);
drawing.show = false;
assert.deepEqual(importedDrawingPoints(drawing), []);
});
+35 -21
View File
@@ -5,10 +5,9 @@ import {
loadGeoFile,
} from '../data/geoFileImport.js';
import {
addImportedSource,
dataSourcePoints,
removeImportedSource,
showImportedSource,
importedDrawingPoints,
removeImportedDrawing,
showImportedDrawing,
} from '../data/geoImportPins.js';
import { formatNumber, t, tn, translateKnown } from '../i18n/index.js';
import { flyToFootprint } from './flyToDataSource.js';
@@ -19,9 +18,9 @@ import {
findGlobe,
} from '../render/rendererOf.js';
/** Fly to the whole footprint of one imported file's data source. */
const flyToDataSource = (viewer, dataSource, options) =>
flyToFootprint(viewer, dataSourcePoints(dataSource), options);
/** Fly to the whole footprint of one imported file's drawing. */
const flyToDrawing = (viewer, drawing, options) =>
flyToFootprint(viewer, importedDrawingPoints(drawing), options);
// One color per file, in import order, from the whiteboard palette.
const COLORS = ['#39d0ff', '#ffb547', '#5dff9f', '#ff6b6b', '#8be9ff'];
@@ -45,14 +44,14 @@ function localizedValues(values) {
* renders them. `connect(actions)` answers the view's pick and row buttons
* and returns their disconnect.
* @returns {{destroy: Function, importFiles: Function, list: Function,
* setVisible: Function, flyTo: Function, remove: Function,
* setVisible: Function, flyTo: Function, remove: Function, drawn: Function,
* diagnostics: Function}|null}
*/
export function initGeoFileImport({
viewer,
load = loadGeoFile,
document: doc = globalThis.document,
flyToSource = flyToDataSource,
flyToSource = flyToDrawing,
navigation = null,
ground = null,
subscribeMapSource = null,
@@ -188,7 +187,7 @@ export function initGeoFileImport({
const item = find(id);
if (!item) return false;
item.visible = Boolean(visible);
showImportedSource(item.dataSource, item.visible);
showImportedDrawing(item.drawing, item.visible);
if (item.visible) scheduleGround();
present();
render();
@@ -199,7 +198,7 @@ export function initGeoFileImport({
// destination's terrain has loaded (see ./flyToDataSource.js).
const fly = (item) => {
if (!item.visible) setVisible(item.id, true);
flyToSource(viewer, item.dataSource, { ground });
flyToSource(viewer, item.drawing, { ground });
return true;
};
@@ -236,7 +235,7 @@ export function initGeoFileImport({
const at = imports.findIndex((item) => item.id === id);
if (at < 0) return false;
const [item] = imports.splice(at, 1);
removeImportedSource(viewer, item.dataSource);
removeImportedDrawing(item.drawing);
item.revoke?.();
present();
render();
@@ -300,6 +299,18 @@ export function initGeoFileImport({
loaded.revoke?.();
break;
}
try {
loaded.mount?.();
} catch {
// Something in it the renderer would not draw: refused whole.
loaded.revoke?.();
outcomes.push({
name: fileName,
ok: false,
error: t('That file could not be read.'),
});
continue;
}
colorAt += 1;
seq += 1;
const item = {
@@ -311,17 +322,10 @@ export function initGeoFileImport({
removed: loaded.removed || 0,
color,
visible: true,
dataSource: loaded.dataSource,
drawing: loaded.drawing,
revoke: loaded.revoke,
refreshGround: loaded.refreshGround,
};
await addImportedSource(viewer, item.dataSource);
if (destroyed) {
removeImportedSource(viewer, item.dataSource);
item.revoke?.();
break;
}
loaded.mount?.();
imports.push(item);
present();
render();
@@ -409,6 +413,16 @@ export function initGeoFileImport({
setVisible,
flyTo,
remove,
/** What a file drew: its sets' ids, whether shown, and their items. */
drawn: (id) => {
const item = imports.find((entry) => entry.id === id);
if (!item?.drawing) return null;
return {
sets: { ...item.drawing.ids },
show: item.drawing.show,
...item.drawing.items?.(),
};
},
diagnostics: () => ({
files: imports.length,
entities: imports.reduce((n, item) => n + item.entityCount, 0),
@@ -424,7 +438,7 @@ export function initGeoFileImport({
clearTimeout(groundTimer);
for (const remove of groundRemovers) remove();
for (const item of imports.splice(0)) {
removeImportedSource(viewer, item.dataSource);
removeImportedDrawing(item.drawing);
item.revoke?.();
}
for (const [target, type, listener, options] of listeners.splice(0))
+62 -21
View File
@@ -1,6 +1,6 @@
// Behavioral tests for DISPLAY ▸ Import: the controller is driven against
// fake DOM and viewer doubles with an injected loader, and its observable
// effects are asserted — data sources added and removed, the rows and hint it
// effects are asserted — drawings mounted and removed, the rows and hint it
// publishes, drop handling, the file limit, and what destroy() gives back.
// The Display panel renders the published list (`displayPanel.test.mjs`);
// real parsing and rendering run in `scripts/qa-geo-import.mjs`.
@@ -85,16 +85,6 @@ function setup({
const viewer = {
container: new FakeElement('div', 'cesiumContainer'),
scene: { requestRender: () => (renders += 1) },
dataSources: {
add: async (ds) => {
added.push(ds);
return ds;
},
remove: (ds, destroy) => {
removed.push({ ds, destroy });
return true;
},
},
flyTo: (target) => flights.push(target),
};
// The renderer's ports, when the test gives them, bound before the import
@@ -107,7 +97,7 @@ function setup({
if (file.fail) throw new GeoImportError(file.fail);
if (file.crash) throw new Error('boom');
return {
dataSource: { show: true },
drawing: { show: true },
name: file.name,
format: 'geojson',
entityCount: 3,
@@ -115,9 +105,24 @@ function setup({
revoke: () => revoked.push(file.name),
};
};
// Each loaded file's drawing, recorded when the import mounts it and when
// it takes it off the globe.
const recorded = async (file, opts) => {
const loaded = await (load || defaultLoad)(file, opts);
const drawing = loaded.drawing ?? {};
drawing.destroy = () => removed.push({ ds: drawing, destroy: true });
return {
...loaded,
drawing,
mount() {
loaded.mount?.();
added.push(drawing);
},
};
};
const tool = initGeoFileImport({
viewer,
load: load || defaultLoad,
load: recorded,
document,
...(navigation ? { navigation } : {}),
...(subscribeMapSource ? { subscribeMapSource } : {}),
@@ -201,10 +206,19 @@ test('row buttons hide, show, fly to and remove a file', async () => {
await t.tool.importFiles([file('a.gpx')]);
const [{ id }] = t.tool.list();
const ds = t.added[0];
ds.ids = { icons: 'i', lines: 'l', shapes: 's' };
ds.items = () => ({ icons: [{ id: 'p0' }], lines: [], shapes: [] });
const glyphClick = (name) => press(t, rows(t)[0], name);
assert.equal(ds.show, true);
glyphClick('toggle');
assert.equal(ds.show, false);
assert.deepEqual(t.tool.drawn(id), {
sets: { icons: 'i', lines: 'l', shapes: 's' },
show: false,
icons: [{ id: 'p0' }],
lines: [],
shapes: [],
});
assert.equal(t.tool.list()[0].visible, false);
assert.equal(action(rows(t)[0], 'toggle').pressed, 'false');
assert.equal(action(rows(t)[0], 'toggle').icon, 'visibility_off');
@@ -217,6 +231,7 @@ test('row buttons hide, show, fly to and remove a file', async () => {
assert.deepEqual(t.revoked, ['a.gpx']);
assert.equal(t.tool.list().length, 0);
assert.deepEqual(rows(t), []);
assert.equal(t.tool.drawn(id), null);
assert.equal(t.tool.remove(id), false);
});
@@ -240,6 +255,32 @@ test('a refused file says why and does not stop the rest of the batch', async ()
assert.equal(t.tool.list().length, 1);
});
test('a file the renderer will not draw is refused and released, and the batch goes on', async () => {
const t = setup({
load: async (file) => ({
drawing: { show: true },
name: file.name,
format: 'kml',
entityCount: 1,
revoke: () => t.revoked.push(file.name),
mount() {
if (file.name === 'odd.kml') throw new Error('refused');
},
}),
});
const out = await t.tool.importFiles([file('odd.kml'), file('good.kml')]);
assert.deepEqual(
out.map((o) => o.ok),
[false, true],
);
assert.match(out[0].error, /could not be read\./);
assert.deepEqual(t.revoked, ['odd.kml']);
assert.deepEqual(
t.tool.list().map((f) => f.name),
['good.kml'],
);
});
test('the number of files on the globe is bounded', async () => {
const t = setup();
const many = Array.from({ length: MAX_IMPORTED_FILES + 2 }, (_, i) =>
@@ -314,7 +355,7 @@ test('a file that finishes loading after destroy is released, not added', async
load: async () => {
await gate;
return {
dataSource: {},
drawing: {},
name: 'late',
format: 'kml',
entityCount: 1,
@@ -418,7 +459,7 @@ test('a direct camera gesture cancels the fly-to of a file still being read', as
name: 'slow.geojson',
format: 'geojson',
entityCount: 1,
dataSource: {},
drawing: {},
};
},
});
@@ -464,7 +505,7 @@ test('ground refresh coalesces map changes and releases its subscription on tear
name: 'point.geojson',
format: 'geojson',
entityCount: 1,
dataSource: {},
drawing: {},
refreshGround: async () => refreshed++,
}),
});
@@ -500,7 +541,7 @@ test('the camera settling and the terrain queue running dry refresh the ground,
name: 'point.geojson',
format: 'geojson',
entityCount: 1,
dataSource: {},
drawing: {},
refreshGround: async () => refreshed++,
}),
});
@@ -569,7 +610,7 @@ test('a slow import does not fly once something newer took the camera', async ()
load: async (f) => {
await gate;
return {
dataSource: {},
drawing: {},
name: f.name,
format: 'geojson',
entityCount: 1,
@@ -603,7 +644,7 @@ test('a queued import cannot fly over navigation that happened while it waited',
load: async (f) => {
if (f.name === 'first.geojson') await gate;
return {
dataSource: {},
drawing: {},
name: f.name,
format: 'geojson',
entityCount: 1,
@@ -638,7 +679,7 @@ test('a refused deferred stamp (Cockpit) imports without flying', async () => {
test('KML and KMZ rows say they keep their own styles instead of showing a color', async () => {
const t = setup({
load: async (f) => ({
dataSource: {},
drawing: {},
name: f.name,
format: f.name.endsWith('.kml') ? 'kml' : 'gpx',
entityCount: 2,
@@ -657,7 +698,7 @@ test('KML and KMZ rows say they keep their own styles instead of showing a color
test('the map-object count in a row title keeps digit grouping', async () => {
const t = setup({
load: async (f) => ({
dataSource: {},
drawing: {},
name: f.name,
format: 'geojson',
entityCount: 12345,