Files
gods-eye-view/src/layers/firms/cards.js
T
German Khokhlov 7f478e3815 Remove always-true layer availability and leftover viewer paths
Every layer draws on both engines, so the per-engine availability
machinery always answered yes. The renderer manifest is now the id to
display map plus the wind flow backend; the catalog filter, the voice and
QA-probe refusals and the engine-kind checks go with it. The Navara
notice lists the same layers in the same words.

Paths that read the Cesium viewer behind an engine that is always there
are gone: the Recent Imagery viewer fallbacks, the shell's imagery-host
service (one shared host module remains), the engineless map controller,
viewer gates in voice actions, world packets and camera verbs, the
orientation controls' tracked-entity fallback, and the Bhote Koshi and
FIRMS Cesium-shaped paths. setCameraInputs, which nothing called, leaves
the contract; suspensions remain.

Smaller duplicates go too: one tracker-release helper for navigation and
location, the no-op frame latch, missing-engine guards, one name for the
injected display, flat bikeshare and installations displays, one overlay
host and binder, one name per world-overlay method, and stub-viewer
guards in the Cesium engine. Layers that still read the viewer keep the
shared init(viewer, context) entry.

Behaviour is unchanged on both engines. Viewer lines fall from 849 to
750 and engine-name literals from 32 to 27.
2026-11-08 17:06:01 +04:00

136 lines
5.1 KiB
JavaScript

import { t } from '../../i18n/index.js';
import {
FIRMS_OVERLAY_SOURCE_ID,
FIRMS_AMBIENT_COHORT_LIMIT,
} from '../../data/firmsLabels.js';
import { MAX_AMBIENT_LABELS, LABEL_VIEW_MARGIN_PX } from './policy.js';
export function createCards({
layerState,
services,
components,
config,
feed,
}) {
const { overlayHost } = config;
/**
* Rebuild the card entries for the shared world-overlay host: the
* selected-fire detail card (if any) plus at most MAX_AMBIENT_LABELS
* ambient cards picked by a greedy screen-space declutter — walk the
* priority-ranked candidates, project each through the renderer
* (engine.projector.worldToWindow), and accept only candidates
* ≥ LABEL_MIN_SEP_PX from every already-accepted card. Candidates whose
* projection fails are dropped silently. SELECTION runs here, on LOD/
* viewport rebuilds and camera moveEnd — never per frame; RENDERING is
* the host, which re-projects the accepted entries every frame so
* cards track the camera smoothly.
*/
function rebuildAmbientLabels() {
if (!layerState._renderer) return;
const scene = layerState._view.scene;
const project = (position, result) =>
layerState._renderer.view.worldToWindow(position, result);
const now = Date.now();
const entries = [];
/** @type {Array<{x: number, y: number}>} Screen positions of accepted labels. */
const accepted = [];
// The window projection happily projects points on the FAR side of the
// planet, so without this the ≤18 ambient slots get spent on fires the
// overlay host will then horizon-cull at paint time (`horizonCull: true`
// in applyFirmsOverlayPolicy) — near-side fires silently lose their cards.
// Shared with the sprite pass (fireHorizonOccluder) so cards and sprites
// never disagree about which hemisphere a detection is on.
const occluder = components.rendering.fireHorizonOccluder();
const beyondHorizon = (position) =>
occluder ? occluder.isPointVisible(position) !== true : false;
layerState._fireByCardId.clear();
if (layerState._selectedFire) {
const selectedCard = components.model.buildSelectedFireCard(
layerState._selectedFire,
now,
);
layerState._fireByCardId.set(selectedCard.id, layerState._selectedFire);
entries.push(selectedCard);
const screen = project(
components.model.firePosition(layerState._selectedFire),
layerState.scratchWindowCoord,
);
// Seed the accepted list so ambient cards keep clear of the detail card.
// A selected fire behind the limb is not painted, so it must not reserve
// screen space either.
if (
screen &&
!beyondHorizon(
components.model.fireCullPosition(layerState._selectedFire),
)
) {
accepted.push({ x: screen.x, y: screen.y });
}
}
const width = scene.canvas.clientWidth;
const height = scene.canvas.clientHeight;
let ambientCount = 0;
for (const candidate of layerState._labelCandidates) {
if (ambientCount >= MAX_AMBIENT_LABELS) break;
if (candidate.fire && candidate.fire === layerState._selectedFire)
continue;
// Spend the bounded cohort only on the visible hemisphere. At global
// LOD, far-side cells can still project on-canvas; accepting those first
// starves front-side cards before the host applies its authoritative cull.
if (beyondHorizon(candidate.cullPosition || candidate.position)) continue;
const screen = project(candidate.position, layerState.scratchWindowCoord);
if (!screen) continue; // projection failed (e.g. behind camera) — drop silently
if (
screen.x < -LABEL_VIEW_MARGIN_PX ||
screen.x > width + LABEL_VIEW_MARGIN_PX ||
screen.y < -LABEL_VIEW_MARGIN_PX ||
screen.y > height + LABEL_VIEW_MARGIN_PX
)
continue;
if (!components.model.screenSeparated(accepted, screen)) continue;
accepted.push({ x: screen.x, y: screen.y });
ambientCount += 1;
const card = candidate.fire
? components.model.buildFireCard(candidate, now)
: components.model.buildCellCard(candidate, now);
if (candidate.fire) layerState._fireByCardId.set(card.id, candidate.fire);
entries.push(card);
}
overlayHost.setEntries(
FIRMS_OVERLAY_SOURCE_ID,
entries.map((entry) => {
const card = components.model.applyFirmsOverlayPolicy(
entry,
layerState._labelLodDistance,
);
if (!card.interactive) return card;
return {
...card,
accessibilityLabel: t('Focus fire detection {title}, {details}', {
title: card.title,
details: card.details.join(', '),
}),
activate: () => {
const fire = layerState._fireByCardId.get(card.id);
if (!fire) return false;
components.selection.selectAndFocusFire(fire);
return true;
},
};
}),
{
cohortLimit: FIRMS_AMBIENT_COHORT_LIMIT,
collisionCapacity: FIRMS_AMBIENT_COHORT_LIMIT,
moving: false,
},
);
}
return { rebuildAmbientLabels };
}