mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Show drone airspace, OSM places, sea marks and ski pistes on Navara, and keep them across engine switches
This commit is contained in:
1 parent
43b4e9348b
commit
843c4a111d
25 files changed
+838
-295
No files matched your search
@@ -1,72 +1,20 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { containmentAccent } from '../cards.js';
|
||||
import { createZonesCesiumRenderer } from '../../shared/render/cesiumZones.js';
|
||||
/** Fill/line color for a perimeter by containment progress (same ramp as the card accent). */
|
||||
export function containmentColor(containedPct) {
|
||||
return Cesium.Color.fromCssColorString(containmentAccent(containedPct));
|
||||
}
|
||||
|
||||
const ringPositions = (ring) =>
|
||||
ring.map(([lon, lat]) => Cesium.Cartesian3.fromDegrees(lon, lat));
|
||||
|
||||
export function createPerimetersCesiumRenderer({
|
||||
viewer,
|
||||
screenSpaceEventHandlerFactory,
|
||||
}) {
|
||||
const dataSource = new Cesium.CustomDataSource('fire-perimeters');
|
||||
dataSource.show = false;
|
||||
viewer.dataSources.add(dataSource);
|
||||
return {
|
||||
setVisible(show) {
|
||||
dataSource.show = show;
|
||||
},
|
||||
pick(click) {
|
||||
return viewer.scene.pick(click.position);
|
||||
},
|
||||
onClick(callback) {
|
||||
const handler = screenSpaceEventHandlerFactory(viewer);
|
||||
handler.setInputAction(callback, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
return () => handler.destroy();
|
||||
},
|
||||
replace(rows) {
|
||||
const nextEntities = [];
|
||||
for (const row of rows) {
|
||||
const color = containmentColor(row.containedPct);
|
||||
for (const [index, rings] of row.polygons.entries()) {
|
||||
const [outer, ...holes] = rings;
|
||||
const outerPositions = ringPositions(outer);
|
||||
nextEntities.push(
|
||||
new Cesium.Entity({
|
||||
id: `fire-perimeter:${row.stableId}:${index}`,
|
||||
polygon: {
|
||||
hierarchy: new Cesium.PolygonHierarchy(
|
||||
outerPositions,
|
||||
holes.map(
|
||||
(hole) => new Cesium.PolygonHierarchy(ringPositions(hole)),
|
||||
),
|
||||
),
|
||||
material: new Cesium.ColorMaterialProperty(
|
||||
color.withAlpha(0.25),
|
||||
),
|
||||
},
|
||||
// The fire line: ground-clamped outline (entity polygons cannot
|
||||
// outline clamped geometry themselves).
|
||||
polyline: {
|
||||
positions: outerPositions,
|
||||
clampToGround: true,
|
||||
width: 2,
|
||||
material: new Cesium.ColorMaterialProperty(
|
||||
color.withAlpha(0.9),
|
||||
),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
dataSource.entities.removeAll();
|
||||
for (const entity of nextEntities) dataSource.entities.add(entity);
|
||||
},
|
||||
destroy() {
|
||||
viewer.dataSources.remove(dataSource, true);
|
||||
},
|
||||
};
|
||||
return createZonesCesiumRenderer({
|
||||
viewer,
|
||||
screenSpaceEventHandlerFactory,
|
||||
name: 'fire-perimeters',
|
||||
idPrefix: 'fire-perimeter',
|
||||
colorOf: (row) => containmentAccent(row.containedPct),
|
||||
});
|
||||
}
|
||||
@@ -1,85 +1,13 @@
|
||||
import * as geo from '../../../geo/index.js';
|
||||
import { createNavaraPolygonDisplay } from '../../shared/render/navaraPolygons.js';
|
||||
import { containmentAccent } from '../cards.js';
|
||||
|
||||
import { containsGroundPoint } from '../../shared/render/groundRing.js';
|
||||
import { createZonesNavaraRenderer } from '../../shared/render/navaraZones.js';
|
||||
|
||||
export function createPerimetersNavaraRenderer(engine, { view }) {
|
||||
let polygons = [];
|
||||
const display = createNavaraPolygonDisplay(engine, view, (color, show) => ({
|
||||
polygon: {
|
||||
color,
|
||||
show,
|
||||
clampToGround: true,
|
||||
transparent: true,
|
||||
opacity: 0.25,
|
||||
return createZonesNavaraRenderer(
|
||||
engine,
|
||||
{ view },
|
||||
{
|
||||
idPrefix: 'fire-perimeter',
|
||||
colorOf: (row) => containmentAccent(row.containedPct),
|
||||
},
|
||||
polyline: {
|
||||
color,
|
||||
show,
|
||||
clampToGround: true,
|
||||
width: 2,
|
||||
transparent: true,
|
||||
opacity: 0.9,
|
||||
},
|
||||
}));
|
||||
return {
|
||||
setVisible: display.setVisible,
|
||||
replace(rows) {
|
||||
const groups = new Map(),
|
||||
next = [];
|
||||
for (const row of rows) {
|
||||
const color = containmentAccent(row.containedPct);
|
||||
if (!groups.has(color)) groups.set(color, []);
|
||||
for (const [index, rings] of row.polygons.entries()) {
|
||||
const id = `fire-perimeter:${row.stableId}:${index}`;
|
||||
const properties = { incident: row.stableId };
|
||||
const group = groups.get(color);
|
||||
group.push(
|
||||
{
|
||||
type: 'Feature',
|
||||
id,
|
||||
properties,
|
||||
geometry: { type: 'Polygon', coordinates: rings },
|
||||
},
|
||||
{
|
||||
type: 'Feature',
|
||||
id: id + '-outline',
|
||||
properties,
|
||||
geometry: { type: 'LineString', coordinates: rings[0] },
|
||||
},
|
||||
);
|
||||
next.push({ id, rings });
|
||||
}
|
||||
}
|
||||
display.replace(groups);
|
||||
polygons = next;
|
||||
},
|
||||
onClick(callback) {
|
||||
// Perimeters never claim a sibling pick. The input port shares the
|
||||
// native click result with other consumers of the same gesture.
|
||||
return engine.input.on('click', callback, { pick: true });
|
||||
},
|
||||
pick(event) {
|
||||
if (event.picked) return event.picked;
|
||||
const point = engine.picker.pickGlobe(event.position);
|
||||
if (!point) return null;
|
||||
const pos = geo.cartographic.fromCartesian(point);
|
||||
const lon = geo.math.toDegrees(pos.longitude),
|
||||
lat = geo.math.toDegrees(pos.latitude);
|
||||
for (let i = polygons.length - 1; i >= 0; i--) {
|
||||
const { id, rings } = polygons[i];
|
||||
if (
|
||||
containsGroundPoint(rings[0], lon, lat) &&
|
||||
!rings.slice(1).some((ring) => containsGroundPoint(ring, lon, lat))
|
||||
)
|
||||
return { id };
|
||||
}
|
||||
return null;
|
||||
},
|
||||
destroy() {
|
||||
polygons = [];
|
||||
display.destroy();
|
||||
},
|
||||
};
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user