Skip to content

TextMeasurer

Defined in: labels/measure.ts:100

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:108

string

number = MEASURE_CACHE_LIMIT

TextMeasurer

readonly height: number

Defined in: labels/measure.ts:102

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

trim(text, maxWidth): string

Defined in: labels/measure.ts:131

text trimmed to maxWidth px with an ellipsis (#496), memoized like width: each distinct text is trimmed once (O(log length) measurements), every later frame is a Map lookup. A text that fits is returned as is. Changing maxWidth drops the memo. The prefix probes are measured directly, not cached in width’s map, so they cannot evict the working set.

string

number

string


width(text): number

Defined in: labels/measure.ts:116

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

string

number