Revert "Merge pull request #1757 from bilawalsidhu/perf/vessel-labels-merge"

This reverts commit 15d1855dd3, reversing
changes made to 663b56f620.
This commit is contained in:
Sameh Khamis committed 2026-11-15 18:18:42 -08:00
1 parent 50e3974217
commit 33c98118ba
8 files changed
+27 -374

No files matched your search

+14 -49
View File
@@ -31,12 +31,6 @@ import {
} from '../../data/fleetModels.js';
import { createFleetModelLayer } from '../../data/fleetModelInstances.js';
import { isAidToNavigation } from '../../data/vesselTypes.js';
import { createWindowProjector } from '../../data/windowProjection.js';
// Label grid cells are keyed by column * LABEL_CELL_ROW + row, unique while
// rows stay within half of it either side; a cell further off screen is keyed
// by its text.
const LABEL_CELL_ROW = 1 << 20;
/** A moving vessel's next frame is asked for once it would move this far on
* screen (pixels), so it glides when it moves visibly and the scene idles
@@ -76,7 +70,6 @@ export function createRendering({
}) {
const { state } = vesselState;
let visualRecords = new WeakMap();
const labelScreenScratch = new Cesium.Cartesian2();
// The fallback preserves helper calls with externally supplied render records.
function getVisual(record) {
@@ -1045,30 +1038,25 @@ export function createRendering({
return;
}
// Every vessel in view is projected, so the camera is read once and each
// is a few multiplications (see windowProjection.js) into one screen
// point; a cell gets a candidate only for the vessel that leads it.
const project = createWindowProjector(scene);
const cells = new Map();
for (const record of records) {
const visual = getVisual(record);
if (record === selected) continue;
const screen = project(getVisual(record).position, labelScreenScratch);
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
scene,
visual.position,
);
if (!screen) continue;
const column = Math.floor(screen.x / LABEL_GRID_PX);
const row = Math.floor(screen.y / LABEL_GRID_PX);
const key =
Math.abs(row) < LABEL_CELL_ROW / 2 && Math.abs(column) < LABEL_CELL_ROW
? column * LABEL_CELL_ROW + row
: `${column}:${row}`;
const score = labelPriority(record, selected);
const key = `${Math.floor(screen.x / LABEL_GRID_PX)}:${Math.floor(screen.y / LABEL_GRID_PX)}`;
const candidate = {
record,
score: labelPriority(record, selected),
x: screen.x,
y: screen.y,
};
const existing = cells.get(key);
if (!existing) {
cells.set(key, { record, score, x: screen.x, y: screen.y });
} else if (score > existing.score) {
existing.record = record;
existing.score = score;
existing.x = screen.x;
existing.y = screen.y;
if (!existing || candidate.score > existing.score) {
cells.set(key, candidate);
}
}
@@ -1160,30 +1148,7 @@ export function createRendering({
return score;
}
// Whether a vessel's name is worth a card, kept per vessel until what it
// is judged from changes: the label pass asks for every vessel in view.
const usefulNames = new WeakMap();
function hasUsefulName(record) {
const known = usefulNames.get(record);
if (
known &&
known.name === record.name &&
known.mmsi === record.mmsi &&
known.id === record.id
)
return known.useful;
const useful = nameIsUseful(record);
usefulNames.set(record, {
name: record.name,
mmsi: record.mmsi,
id: record.id,
useful,
});
return useful;
}
function nameIsUseful(record) {
const text = String(record.name || '').trim();
return Boolean(
text &&