This demo shows the advanced side of the label layer: drawing a large number of labels – tens of thousands – and letting them vary in size without losing quality.
To draw that many labels, set labelAtlas: "glyph" when you create the
layer. The word atlas, which the default auto setting prefers, can run out
of room with this many distinct words.
The trade-off is slightly lowered letter spacing quality (no kerning or ligatures).
To keep labels looking good at different sizes, this demo also turns on the SDF (Signed
Distance Field) text renderer with labelRendering: "sdf". It keeps edges crisp
as labels grow, so the more important ones can scale up – to roughly twice their base size
– and still look sharp. The trade-off is a very slightly less sharp rendering of labels.
Toggle labelRendering to raster and back to see plain
rendering soften the larger text.
Click any value to apply it at runtime.
labelRendering – how labels are drawn. sdf stays
crisp at any size and allows outlines; raster is sharp at the base
size but softens as labels grow. Easiest to see with a large
labelMaxSizeScale.
labelAtlasQuality – (SDF rendering only) how finely letter shapes
are stored. Higher settings keep labels crisp when you zoom in close, but leave
room for fewer distinct characters.
labelFontSize – base font size in screen pixels.
labelFontFamily – font family used to draw the labels.
labelFontWeight – font weight used to draw the labels.
labelFontVariant – font variant used to draw the labels.
Set: normal small-caps
labelFontStyle – font style used to draw the labels.
labelColor – fill color used for every label. (The dark/light
theme switch also drives this, so switching themes overrides your choice.)
labelMinSizeScale – smallest per-point size multiplier. Points
with a smaller labelSize are bumped up to this.
labelMaxSizeScale – largest per-point size multiplier. Raise it
to let the most important labels grow larger – where SDF's crisp scaling
shows.
labelDensity – controls how tightly labels pack on the map.
Values above 1.0 shrink the collision halo so more labels fit; values
below 1.0 grow it so fewer labels show.
labelCollisionModel – how labels reserve space when deciding
which ones fit. per-label-box keeps each whole label together;
per-word reserves space word by word, packing labels more tightly.
Set: per-label-box per-word
labelOutlineWidth – (SDF rendering only) width of the halo
around each glyph, in pixels. 0 removes the halo.
labelOutlineColor – (SDF rendering only) color of the halo
around each glyph.
labelEdgeSharpness – (SDF rendering only) how crisp the label
edges are. Higher values sharpen them; 1.0 leaves edges at their
natural softness.
labelEdgeThinning – (SDF rendering only) softens the outer edge
of each stroke so text reads a little thinner. 0 leaves edges as-is.
labelMaskExpansion – (SDF rendering only) how far the clear space
around each label extends, in pixels, giving markers and contours more room to keep
clear of the text. 0 follows the label shape exactly.
labelShadowSize – strength of the drop-shadow under labels.
0 disables it; larger values produce a wider, more opaque shadow.
labelShadowColor – color of the drop-shadow under labels.
All code that builds this visualization is included directly in this HTML page. View the page source to examine the code.