mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Traffic roads come from OpenFreeMap vector tiles, or TomTom flow tiles with a key (Hybrid by default). Military areas use OpenFreeMap polygons with a bundled worldwide name index; wide views show named points. ALPR reads an hourly OpenStreetMap extract. Cockpit place context and country, state and US county outlines use bundled Natural Earth and US Census data. Overpass is used only when an operator configures their own endpoint. Also: camera arrivals no longer land below ground, keyless terrain retries on 429, bounded relation geometry for configured Overpass, one shared OpenStreetMap credit, and separate tile and API transports for embedders. Co-authored-by: theGaryLarson <[email protected]> Co-authored-by: Milan Khanal <[email protected]>
This commit is contained in:
200 files changed
+26665
-1977
No files matched your search
@@ -32,12 +32,104 @@ export function createRendering({
|
||||
);
|
||||
}
|
||||
|
||||
let selectedFillKey = null;
|
||||
const selectedFillIds = [];
|
||||
|
||||
function clearSelectionFill() {
|
||||
for (const id of selectedFillIds)
|
||||
layerState.dataSource?.entities.removeById(id);
|
||||
selectedFillIds.length = 0;
|
||||
selectedFillKey = null;
|
||||
}
|
||||
|
||||
/** Ground geometry classifies the active surface; no height/extrusion plane. */
|
||||
function syncSelectionFill() {
|
||||
const record =
|
||||
layerState.enabled && layerState.recordById.get(layerState.selectedId);
|
||||
if (!record) {
|
||||
clearSelectionFill();
|
||||
return;
|
||||
}
|
||||
const classificationType =
|
||||
layerState.viewer.scene.globe?.show === false
|
||||
? Cesium.ClassificationType.CESIUM_3D_TILE
|
||||
: Cesium.ClassificationType.BOTH;
|
||||
const key = `${record.id}|${renderKey(record)}|${classificationType}`;
|
||||
if (key === selectedFillKey) return;
|
||||
clearSelectionFill();
|
||||
selectedFillKey = key;
|
||||
const footprints =
|
||||
record.footprints || (record.footprint ? [[record.footprint]] : []);
|
||||
const material = new Cesium.ColorMaterialProperty(
|
||||
parts.model.colorFor(record).withAlpha(0.22),
|
||||
);
|
||||
for (let i = 0; i < footprints.length; i++) {
|
||||
const rings = footprints[i];
|
||||
const positions = (ring) =>
|
||||
ring.map(([lon, lat]) => Cesium.Cartesian3.fromDegrees(lon, lat));
|
||||
const fill = layerState.dataSource.entities.add({
|
||||
id: `${record.id}:selected-fill:${i}`,
|
||||
polygon: {
|
||||
hierarchy: new Cesium.PolygonHierarchy(
|
||||
positions(rings[0]),
|
||||
rings
|
||||
.slice(1)
|
||||
.map((ring) => new Cesium.PolygonHierarchy(positions(ring))),
|
||||
),
|
||||
material,
|
||||
classificationType,
|
||||
},
|
||||
});
|
||||
fill.installationId = record.id;
|
||||
selectedFillIds.push(fill.id);
|
||||
}
|
||||
governorRequestRender('installation-selection-fill');
|
||||
}
|
||||
|
||||
function clearRendered() {
|
||||
clearSelectionFill();
|
||||
if (layerState.dataSource?.entities)
|
||||
layerState.dataSource.entities.removeAll();
|
||||
layerState.renderedKeys.clear();
|
||||
removeEntityContextsForLayer(LAYER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Geometry identity of one rendered record. Records whose key is unchanged
|
||||
* keep their Cesium entities across refreshes: ground-clamped outlines and
|
||||
* classification fills rebuild asynchronously, so recreating them on every
|
||||
* reload made unchanged sites blink.
|
||||
* @param {object} record Installation record.
|
||||
* @returns {string} Stable key for the record's drawn geometry.
|
||||
*/
|
||||
function renderKey(record) {
|
||||
const footprints =
|
||||
record.footprints || (record.footprint ? [[record.footprint]] : []);
|
||||
const outlines =
|
||||
record.outlineLines || (record.footprint ? [record.footprint] : []);
|
||||
let points = 0;
|
||||
for (const rings of footprints)
|
||||
for (const ring of rings) points += ring.length;
|
||||
for (const line of outlines) points += line.length;
|
||||
return [
|
||||
record.latitude.toFixed(6),
|
||||
record.longitude.toFixed(6),
|
||||
record.class,
|
||||
record.kind,
|
||||
record.name,
|
||||
footprints.length,
|
||||
outlines.length,
|
||||
points,
|
||||
].join('|');
|
||||
}
|
||||
|
||||
function removeRecordEntities(id) {
|
||||
const entities = layerState.dataSource.entities;
|
||||
for (const entityId of layerState.renderedKeys.get(id)?.entityIds || [])
|
||||
entities.removeById(entityId);
|
||||
layerState.renderedKeys.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The records that get entities this paint: the nearest `MAX_RENDERED`, plus
|
||||
* the selected one when it falls outside that window.
|
||||
@@ -52,7 +144,9 @@ export function createRendering({
|
||||
*/
|
||||
|
||||
function renderableRecords() {
|
||||
const rendered = layerState.records.slice(0, MAX_RENDERED);
|
||||
const rendered = layerState.records
|
||||
.filter((r) => !r.pointOnly)
|
||||
.slice(0, MAX_RENDERED);
|
||||
if (!layerState.selectedId) return rendered;
|
||||
if (rendered.some((record) => record.id === layerState.selectedId))
|
||||
return rendered;
|
||||
@@ -67,16 +161,48 @@ export function createRendering({
|
||||
if (
|
||||
!claimSelection &&
|
||||
layerState.selectedId &&
|
||||
selectedContext &&
|
||||
selectedContext.id !== layerState.selectedId
|
||||
(!selectedContext || selectedContext.id !== layerState.selectedId)
|
||||
) {
|
||||
layerState.selectedId = null;
|
||||
}
|
||||
let migratedSelection = false;
|
||||
if (
|
||||
layerState.selectedId &&
|
||||
!layerState.recordById.has(layerState.selectedId)
|
||||
) {
|
||||
const replacement = layerState.records.find((record) =>
|
||||
record.aliasIds?.includes(layerState.selectedId),
|
||||
);
|
||||
if (replacement) {
|
||||
layerState.selectedId = replacement.id;
|
||||
migratedSelection = true;
|
||||
}
|
||||
}
|
||||
// Post-moveEnd debounced fetches commit after the camera settles; the
|
||||
// rebuilt entities need one frame in idle mode. (perf wave 2 fix)
|
||||
governorRequestRender('installations-render');
|
||||
clearRendered();
|
||||
for (const record of renderableRecords()) {
|
||||
if (
|
||||
layerState.records.some((r) =>
|
||||
r.sources?.some((s) => s.name === 'OpenStreetMap'),
|
||||
)
|
||||
)
|
||||
services.credits?.showOsmCredit?.(layerState.viewer, LAYER_ID, {
|
||||
openMapTiles: layerState.records.some((r) =>
|
||||
r.sources?.some(
|
||||
(s) => s.name === 'OpenStreetMap' && s.id?.startsWith('tile:'),
|
||||
),
|
||||
),
|
||||
});
|
||||
else services.credits?.hideOsmCredit?.(layerState.viewer, LAYER_ID);
|
||||
const records = renderableRecords();
|
||||
const keys = new Map(
|
||||
records.map((record) => [record.id, renderKey(record)]),
|
||||
);
|
||||
const entities = layerState.dataSource.entities;
|
||||
entities.suspendEvents();
|
||||
for (const [id, rendered] of [...layerState.renderedKeys])
|
||||
if (keys.get(id) !== rendered.key) removeRecordEntities(id);
|
||||
for (const record of records) {
|
||||
const color = parts.model.colorFor(record);
|
||||
const surfaceHeightM = installationSurfaceHeightM(record);
|
||||
const displayPosition = Cesium.Cartesian3.fromDegrees(
|
||||
@@ -84,31 +210,63 @@ export function createRendering({
|
||||
record.latitude,
|
||||
surfaceHeightM,
|
||||
);
|
||||
const selectedRecord = record.id === layerState.selectedId;
|
||||
const retained = layerState.renderedKeys.has(record.id)
|
||||
? entities.getById(record.id)
|
||||
: null;
|
||||
if (retained) {
|
||||
// Same geometry: update the marker in place (selection, floor height).
|
||||
if (retained.gevInstallationHeightM !== surfaceHeightM) {
|
||||
retained.gevInstallationHeightM = surfaceHeightM;
|
||||
retained.position = displayPosition;
|
||||
retained.gevDisplayPosition = () => displayPosition;
|
||||
}
|
||||
if (retained.gevInstallationSelected !== selectedRecord) {
|
||||
retained.gevInstallationSelected = selectedRecord;
|
||||
retained.point.pixelSize = selectedRecord ? 13 : 9;
|
||||
retained.point.color = selectedRecord ? Cesium.Color.WHITE : color;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const entityIds = [record.id];
|
||||
layerState.renderedKeys.set(record.id, {
|
||||
key: keys.get(record.id),
|
||||
entityIds,
|
||||
});
|
||||
const entity = layerState.dataSource.entities.add({
|
||||
id: record.id,
|
||||
position: displayPosition,
|
||||
point: {
|
||||
show: !record.namedArea,
|
||||
pixelSize: record.id === layerState.selectedId ? 13 : 9,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
color:
|
||||
record.id === layerState.selectedId ? Cesium.Color.WHITE : color,
|
||||
outlineColor: Cesium.Color.BLACK.withAlpha(0.8),
|
||||
outlineWidth: 1,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
polygon: record.footprint
|
||||
? {
|
||||
hierarchy: new Cesium.PolygonHierarchy(
|
||||
record.footprint.map(([longitude, latitude]) =>
|
||||
Cesium.Cartesian3.fromDegrees(longitude, latitude),
|
||||
),
|
||||
),
|
||||
material: color.withAlpha(0.12),
|
||||
outline: true,
|
||||
outlineColor: color.withAlpha(0.65),
|
||||
height: surfaceHeightM,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
const outlines =
|
||||
record.outlineLines || (record.footprint ? [record.footprint] : []);
|
||||
for (let i = 0; i < outlines.length; i++) {
|
||||
const outline = layerState.dataSource.entities.add({
|
||||
id: `${record.id}:outline:${i}`,
|
||||
polyline: {
|
||||
positions: outlines[i].map(([lon, lat]) =>
|
||||
Cesium.Cartesian3.fromDegrees(lon, lat),
|
||||
),
|
||||
width: 2,
|
||||
material: color.withAlpha(0.85),
|
||||
clampToGround: true,
|
||||
classificationType: Cesium.ClassificationType.BOTH,
|
||||
},
|
||||
});
|
||||
outline.installationId = record.id;
|
||||
entityIds.push(outline.id);
|
||||
}
|
||||
entity.gevInstallationHeightM = surfaceHeightM;
|
||||
entity.gevInstallationSelected = selectedRecord;
|
||||
entity.gevTrackedId = `installations:${record.id}`;
|
||||
entity.gevDisplayPosition = () => displayPosition;
|
||||
entity.gevLabelModel = {
|
||||
@@ -117,6 +275,7 @@ export function createRendering({
|
||||
String(record.class || 'installation')
|
||||
.replaceAll('_', ' ')
|
||||
.toUpperCase(),
|
||||
...(record.memberNames || []).slice(0, 3),
|
||||
],
|
||||
accent: COLOR_BY_CLASS[record.class] || '#9ca6b0',
|
||||
};
|
||||
@@ -133,6 +292,7 @@ export function createRendering({
|
||||
longitude: record.longitude,
|
||||
properties: {
|
||||
class: record.class,
|
||||
memberNames: record.memberNames || [],
|
||||
primaryType: record.primaryType || null,
|
||||
placeTypes: Array.isArray(record.placeTypes) ? record.placeTypes : [],
|
||||
validation: record.validation,
|
||||
@@ -140,11 +300,17 @@ export function createRendering({
|
||||
},
|
||||
});
|
||||
}
|
||||
entities.resumeEvents();
|
||||
const selectedEntity = layerState.selectedId
|
||||
? layerState.dataSource.entities.getById(layerState.selectedId)
|
||||
: null;
|
||||
if (selectedEntity) selectEntityContext(selectedEntity);
|
||||
else layerState.selectedId = null;
|
||||
if (selectedEntity && (claimSelection || migratedSelection))
|
||||
selectEntityContext(selectedEntity);
|
||||
else if (!selectedEntity) layerState.selectedId = null;
|
||||
// Re-register rebuilt geometry and migrate aliases before pruning old context.
|
||||
removeEntityContextsForLayer(LAYER_ID, { retainIds: new Set(keys.keys()) });
|
||||
parts.namedMarkers?.sync(layerState.records);
|
||||
syncSelectionFill();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,6 +353,8 @@ export function createRendering({
|
||||
}
|
||||
return {
|
||||
installationSurfaceHeightM,
|
||||
clearSelectionFill,
|
||||
syncSelectionFill,
|
||||
clearRendered,
|
||||
renderableRecords,
|
||||
renderRecords,
|
||||
|
||||
Reference in new issue
Block a user