Keep GNSS history across globe changes and share the Navara ground cell pass

This commit is contained in:
German Khokhlov committed 2026-11-03 02:30:52 +04:00
1 parent 6fe5bda028
commit 1930ca247a
20 files changed
+629 -415

No files matched your search

+102
View File
@@ -0,0 +1,102 @@
import * as Cesium from 'cesium';
import { GNSS_LEVEL_COLORS } from '../records.js';
/**
* GroundPrimitive allowPicking:false suppresses ids but still submits stencil
* commands in Cesium's pick pass, erasing picks of overlapping ground geometry.
* This fill participates only in rendering, so sibling polygons remain pickable.
*/
class GnssGroundFill extends Cesium.GroundPrimitive {
update(frameState) {
if (!frameState.passes.pick) super.update(frameState);
}
}
/** Degrees at the centre of the current view, or null before the camera settles. */
export function defaultGnssViewAnchor(viewer) {
const canvas = viewer?.scene?.canvas;
const ellipsoid = viewer?.scene?.globe?.ellipsoid;
// At globe scale the visible rectangle can be the whole world, whose
// midpoint is unrelated to the place under the screen centre.
const centre =
canvas?.clientWidth > 0 &&
canvas.clientHeight > 0 &&
viewer.camera?.pickEllipsoid?.(
new Cesium.Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2),
ellipsoid,
);
const rectangle =
!centre && viewer?.camera?.computeViewRectangle?.(ellipsoid);
const carto = centre
? (ellipsoid || Cesium.Ellipsoid.WGS84).cartesianToCartographic(centre)
: rectangle
? Cesium.Rectangle.center(rectangle)
: viewer?.camera?.positionCartographic;
if (!carto) return null;
const latitude = Cesium.Math.toDegrees(carto.latitude);
const longitude = Cesium.Math.toDegrees(carto.longitude);
return Number.isFinite(latitude) && Number.isFinite(longitude)
? { latitude, longitude }
: null;
}
export function createGnssCesiumRenderer({
viewer,
viewAnchor = defaultGnssViewAnchor,
}) {
const primitives = new Cesium.PrimitiveCollection();
primitives.id = 'gnss-integrity';
primitives.show = false;
viewer.scene.groundPrimitives.add(primitives);
return {
camera: viewer.camera,
anchor: () => viewAnchor(viewer),
setVisible(show) {
primitives.show = show;
},
replace(cells, alpha) {
primitives.removeAll();
if (cells.length) {
primitives.add(
new GnssGroundFill({
geometryInstances: cells.map(
(cell) =>
new Cesium.GeometryInstance({
id: `gnss-integrity:${cell.id}`,
geometry: new Cesium.RectangleGeometry({
rectangle: Cesium.Rectangle.fromDegrees(
cell.west,
cell.south,
cell.east,
cell.north,
),
vertexFormat:
Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
}),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.fromCssColorString(
GNSS_LEVEL_COLORS[cell.level],
).withAlpha(alpha[cell.level]),
),
},
}),
),
appearance: new Cesium.PerInstanceColorAppearance({
flat: true,
translucent: true,
}),
classificationType: Cesium.ClassificationType.BOTH,
allowPicking: false,
// Retain the compact rectangle descriptors for inspection, not Entity visualizers.
releaseGeometryInstances: false,
}),
);
}
viewer?.scene?.requestRender?.();
},
destroy() {
viewer.scene.groundPrimitives.remove(primitives);
},
};
}
+47
View File
@@ -0,0 +1,47 @@
import * as geo from '../../../geo/index.js';
import { GNSS_LEVEL_COLORS } from '../records.js';
import { rgbaFromCss } from '../../shared/color.js';
import { createGroundCellDisplay } from '../../shared/render/navaraGroundCells.js';
export function createGnssNavaraRenderer(engine, options) {
const cells = createGroundCellDisplay(engine, options, 0);
const { camera } = engine;
function anchor() {
const { width, height } = engine.host.size();
const centre =
width && height && camera.pickEllipsoid({ x: width / 2, y: height / 2 });
let position = centre && geo.cartographic.fromCartesian(centre);
if (!position) {
const rect = camera.viewRectangle();
if (rect) {
const east =
rect.east < rect.west ? rect.east + 2 * Math.PI : rect.east;
const longitude = (rect.west + east) / 2;
position = {
latitude: (rect.south + rect.north) / 2,
longitude: longitude > Math.PI ? longitude - 2 * Math.PI : longitude,
};
} else position = camera.pose().cartographic;
}
return {
latitude: geo.math.toDegrees(position.latitude),
longitude: geo.math.toDegrees(position.longitude),
};
}
return {
camera,
anchor,
setVisible: cells.setVisible,
destroy: cells.destroy,
replace(rows, alpha) {
cells.replace(
rows.map((row) => ({
...row,
color: rgbaFromCss(GNSS_LEVEL_COLORS[row.level]).withAlpha(
alpha[row.level],
),
})),
);
},
};
}