Skip to main content

Module symbol

Module symbol 

Source
Expand description

Point text labels: a port of MapLibre GL JS’s symbol pipeline.

  • Glyph PBFs (style/parse_glyph_pbf.ts): SDF bitmaps with a 3 px border.

  • Shaping (symbol/shaping.ts, symbol/tagged_string.ts): line breaking by least badness, justification, anchor alignment, letter spacing.

  • Quads (symbol/quads.ts) with corner offsets stored at 1/32 precision (symbol_bucket.ts addVertex).

  • Anchors (symbol/symbol_layout.ts addFeature): points, the first vertex of lines, and the pole of inaccessibility of polygons; anchors outside the tile are dropped.

  • Placement (symbol/placement.ts, symbol/collision_index.ts): layers top-down, tiles by (x, y), features by sort key; boxes in a viewport grid padded by 100 px.

  • Drawing (webgl/draw/draw_symbol.ts, symbol_sdf.*.glsl): bilinear SDF sampling, EDGE_GAMMA, one- or two-pass halos.

  • Icons (render/image_atlas.ts, getIconQuads, symbol_icon.*.glsl): premultiplied sprite images with 1 px padding, NEAREST/LINEAR per draw_symbol.ts, SDF icons through the text shader; text/icon placement combined through text-optional / icon-optional.

  • Line placement (symbol_line.rs): merged, clipped lines; anchors by spacing and max angle; collision circles; glyphs placed along the projected line with keep-upright flipping.

  • Vertical text (vertical.rs): point labels with text-writing-mode vertical (upright glyphs, the label turned 90°, tried in the layer’s writing-mode order) and line labels whose line runs vertically (updateLineLabels switches to the vertical shaping).

Structs§

Glyph
A glyph as laid out in MapLibre’s atlas: the SDF bitmap (glyph + 3 px border) surrounded by 1 px of zero padding.
GlyphMap
Glyphs by font stack (comma-joined, as in the glyph URL) and code point.
Placement
Placed symbols per style layer index.
Shaping
Sprite
SpriteImage
A sprite image as MapLibre stores it in its icon atlas: premultiplied RGBA (premultiplyAlpha, Math.round(c * a / 255)) with 1 px of zero padding.
SymbolAssets
Everything symbol layers need besides the tiles.
SymbolTile
A tile placed on the canvas, as the renderer sees it.

Functions§

draw_layer
Draw the placed symbols of one layer: icons for all tiles, then text. Draw one symbol layer. Placement is in CSS pixels (css is the CSS viewport size); quads are drawn dpr times larger.
feature_fontstack
The comma-joined font stack of a symbol layer for a feature.
feature_icon
The icon image name a symbol layer shows for a feature, or None.
feature_text
The label text a symbol layer shows for a feature (text-field + tokens + format + text-transform), or None.
layer_visible
place
Run MapLibre’s placement for every visible symbol layer.
required_glyph_ranges
Glyph ranges (font stack, range start) the visible symbol layers need.
svg_layer
Write one symbol layer as SVG in draw_layer’s order: icons, then text, each per tile with the shader’s halo passes. Glyphs and SDF icons are outlines traced from their SDFs at the shader’s thresholds, one path per quad (MapLibre blends each quad separately); other icons are embedded sprite images.