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

+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), []);
});