Files
gods-eye-view/src/ui/flyToDataSource.js
T
Sameh Khamis 6c1f91014c 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.
2026-11-09 15:50:53 -08:00

64 lines
2.1 KiB
JavaScript

/** Frame the complete finite footprint of a session-local file. */
import { guardCameraAboveGround } from '../cameraGroundGuard.js';
import { rangeForBoundingSphere } from '../data/cameraFraming.js';
import { cancelCameraArrival } from '../data/cameraArrival.js';
import { distance, fromDegrees, toLonLatH } from '../geo/index.js';
import { sphereFromPoints } from '../geo/sphere.js';
import { heightsOf } from '../queries/heights.js';
import { findCamera } from '../render/rendererOf.js';
/**
* Fly synchronously to a footprint, `[lon, lat, height]` points (degrees,
* 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(
viewer,
points,
{ duration = 1.5, ground = null } = {},
) {
if (!points?.length) return false;
const camera = findCamera(viewer);
if (!camera) return false;
cancelCameraArrival(viewer);
const positions = points.map(([lon, lat, height]) =>
fromDegrees(lon, lat, height),
);
const sphere = sphereFromPoints(positions);
const center = toLonLatH(sphere.center) || {
lon: points[0][0],
lat: points[0][1],
height: 0,
};
const { lat, lon } = center;
const terrain = viewer
? heightsOf(viewer).now({ lon, lat }, { against: 'terrain' })
: null;
const cached = ground?.cachedGroundFloor?.(lat, lon);
const height =
Number.isFinite(terrain) && terrain > 0
? terrain
: Number.isFinite(cached)
? cached
: Number.isFinite(terrain)
? terrain
: 0;
ground?.warmGroundFloor?.([{ lat, lon }]);
const framed = {
center: fromDegrees(lon, lat, Math.max(0, height, center.height)),
radius: 0,
};
for (const position of positions)
framed.radius = Math.max(framed.radius, distance(framed.center, position));
camera.flyToBounds(framed, {
offset: {
heading: camera.pose().heading || 0,
pitch: -Math.PI / 2,
range: Math.max(800, rangeForBoundingSphere(viewer, framed.radius)),
},
durationS: duration,
onComplete: () => guardCameraAboveGround(viewer, { lat, lon }),
});
return true;
}