Skip to content

TextMeasurer

Defined in: labels/measure.ts:77

Text measurement for label sets whose text is derived per frame rather than registered once (#204): the network builds its label candidates from the current LOD frontier / viewport, so a width has to be available for every candidate on every placement pass. Measuring there directly would put a measureText on the per-frame path; this memoizes by text so each distinct string is measured exactly ONCE and every later frame is a Map lookup.

The height is a per-font constant (the row box), so only widths are cached, and the key is the text itself — so a changed labelOf or a rebuilt LOD tree invalidates itself, with no id-remap hook to forget. Memory is O(distinct texts shown): a Map slot + a number (~60 B) each, while the string is normally already retained by the caller’s data. MEASURE_CACHE_LIMIT caps that, clearing wholesale on overflow. One measurer per font — rebuild it when the font changes.

new TextMeasurer(font, limit?): TextMeasurer

Defined in: labels/measure.ts:82

string

number = MEASURE_CACHE_LIMIT

TextMeasurer

readonly height: number

Defined in: labels/measure.ts:79

The row-box height for this font, in px (constant — text width is what varies).

width(text): number

Defined in: labels/measure.ts:90

The label box width for text, measured once and cached.

string

number