Files
gods-eye-view/src/scenes/dataPacks/geometry.js
T
Sameh Khamis 71ff682c7f Draw scene data packs through the draw port and take their geometry and presentation off the Cesium list
Pack points, lines, polygons, image overlays and media markers are draw
sets now, one per pack resource and kind. Feature picks match the click's
draw hit by set and item id, and item ids are namespaced so code that reads
a bare pick id never takes a pack feature for a live contact. An image pack
draws its decoded pixels from a canvas: the Cesium draw port now fills
unclamped shapes with images, as the contract's fills allow, and frees
their materials with the set. The ./scenes export joins the entries whose
caller loads the unbound renderer factories.
2026-11-07 05:29:57 -08:00

73 lines
2.3 KiB
JavaScript

import { decodePackGeoJSON } from '../../director/packs/geojson.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
const CYAN = [0, 1, 1, 1];
const BLACK = [0, 0, 0, 1];
const lonLatHeight = ([lon, lat, height]) => ({ lon, lat, height });
/**
* A feature's item id. Code that reads a pick's bare item id (the pick
* registry, vessel and flight lookups) must never take a pack feature for a
* live contact, so the id is namespaced, never the feature's own.
*/
export const packItemId = (packId, featureId) =>
`data-pack:${JSON.stringify([packId, featureId])}`;
/**
* Render a bounded geometry pack as one draw set per kind (points, lines,
* polygons); no asynchronous geometry or update loop. Each feature's pick
* target is its set and item id.
*/
export function renderPackGeometry({ asset, pack }, handle) {
if (!['application/json', 'application/geo+json'].includes(asset.mimeType))
throw new Error('Expected GeoJSON');
const features = decodePackGeoJSON(asset.bytes);
const items = { points: [], lines: [], shapes: [] };
const kinds = new Map();
for (const feature of features) {
const id = packItemId(pack.id, feature.id);
if (feature.type === 'Point') {
kinds.set(feature.id, 'points');
items.points.push({
id,
pos: lonLatHeight(feature.coordinates),
pixelSize: 12,
color: CYAN,
outlineColor: BLACK,
outlineWidth: 2,
});
} else if (feature.type === 'LineString') {
kinds.set(feature.id, 'lines');
items.lines.push({
id,
positions: feature.coordinates.map((p) => fromDegrees(...p)),
widthPx: 4,
mode: '3d',
style: { kind: 'solid', color: CYAN },
});
} else {
kinds.set(feature.id, 'shapes');
items.shapes.push({
id,
geometry: {
kind: 'polygon',
rings: feature.coordinates.map((ring) => ring.map(lonLatHeight)),
perPositionHeight: true,
},
fill: [0, 1, 1, 0.35],
});
}
}
const sets = {};
for (const kind of ['points', 'lines', 'shapes'])
if (items[kind].length) sets[kind] = handle.draw(kind, items[kind]);
for (const feature of features)
handle.feature?.(
{ packId: pack.id, featureId: feature.id },
{
set: sets[kinds.get(feature.id)],
id: packItemId(pack.id, feature.id),
},
);
}