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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TextMeasurer(
font,limit?):TextMeasurer
Defined in: labels/measure.ts:108
Parameters
Section titled “Parameters”string
limit?
Section titled “limit?”number = MEASURE_CACHE_LIMIT
Returns
Section titled “Returns”TextMeasurer
Properties
Section titled “Properties”height
Section titled “height”
readonlyheight:number
Defined in: labels/measure.ts:102
The row-box height for this font, in px (constant — text width is what varies).
Methods
Section titled “Methods”trim()
Section titled “trim()”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.
Parameters
Section titled “Parameters”string
maxWidth
Section titled “maxWidth”number
Returns
Section titled “Returns”string
width()
Section titled “width()”width(
text):number
Defined in: labels/measure.ts:116
The label box width for text, measured once and cached.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”number