Lots of labels

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.

Rendering mode

  • 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.

    Set: sdf raster

  • 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.

    Set: low standard high ultra

Typography

  • labelFontSize – base font size in screen pixels.

    Set: 12px 16px 20px 24px

  • labelFontFamily – font family used to draw the labels.

    Set: sans-serif serif system-ui monospace

  • labelFontWeight – font weight used to draw the labels.

    Set: normal bold 300

  • labelFontVariant – font variant used to draw the labels.

    Set: normal small-caps

  • labelFontStyle – font style used to draw the labels.

    Set: normal italic

Fill color

  • labelColor – fill color used for every label. (The dark/light theme switch also drives this, so switching themes overrides your choice.)

    Set: dark blue red

Size & visibility

  • labelMinSizeScale – smallest per-point size multiplier. Points with a smaller labelSize are bumped up to this.

    Set: 0.5 0.75 1.0

  • labelMaxSizeScale – largest per-point size multiplier. Raise it to let the most important labels grow larger – where SDF's crisp scaling shows.

    Set: 1.0 1.25 1.5 2.0

  • 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.

    Set: 0.5 1 1.5 2

  • 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

Outline & edges (SDF rendering only)

  • labelOutlineWidth – (SDF rendering only) width of the halo around each glyph, in pixels. 0 removes the halo.

    Set: 0 1 2 4

  • labelOutlineColor – (SDF rendering only) color of the halo around each glyph.

    Set: white black yellow

  • labelEdgeSharpness – (SDF rendering only) how crisp the label edges are. Higher values sharpen them; 1.0 leaves edges at their natural softness.

    Set: 1 2 4 6

  • labelEdgeThinning – (SDF rendering only) softens the outer edge of each stroke so text reads a little thinner. 0 leaves edges as-is.

    Set: 0 0.5 0.75 1

  • 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.

    Set: 0 1 2 3

Shadow

  • labelShadowSize – strength of the drop-shadow under labels. 0 disables it; larger values produce a wider, more opaque shadow.

    Set: 0 2 4 8

  • labelShadowColor – color of the drop-shadow under labels.

    Set: black blue red


All code that builds this visualization is included directly in this HTML page. View the page source to examine the code.