Skip to main content

alphaThis is a new frontend component. Help us improve it and give your feedback on Slack.

Symbol Registry

The symbol registry is a service that manages reusable named symbols for map markers. It is available to plugin authors via services.symbolRegistry. Each map has its own registry, so symbols registered and symbolDefaults set on one map don't affect another on the same page.

Application code that needs a one-off custom marker should pass svgContent directly to addMarker() via MarkerOptions instead — no registration required.

Built-in symbols

Six symbols are registered by default:

IDAnchored atDescription
'pin'TipTeardrop pin
'circle'CentreFilled circle
'square'CentreRounded square
'hexagon'CentrePointy-top hexagon
'triangle'CentroidPoint-up triangle
'diamond'CentreSquare rotated 45°

Each can be shown at any size and takes a custom graphic. They use the same token resolution order as any other symbol.

Methods

Available on services.symbolRegistry inside a plugin.


setDefaults(defaults)

Set constructor-level defaults. Called automatically during app initialisation with the symbolDefaults constructor config. Plugin authors do not normally need to call this.

ArgumentTypeDescription
defaultsObjectThe constructor's symbolDefaults config

getDefaults()

Returns the map's merged defaults (hardcoded symbolDefaults.js + constructor overrides), including both structural properties (symbol, viewBox, anchor) and token values.

Returns:
Object. The merged defaults.
const defaults = services.symbolRegistry.getDefaults()
// { symbol: 'pin', backgroundColor: '#ca3535', foregroundColor: '#ffffff', ... }

register(symbolDef)

Register a custom SVG-template symbol, such as one with several colours. Once registered it can be referenced by ID via MarkerOptions.symbol or a dataset style.symbol. Throws if id, svg or viewBox is missing, or anchor is invalid.

Any other property of symbolDef is a default token value for this symbol, e.g. backgroundColor: '#1d70b8'. selectedColor and activeColor are ignored here — they are always derived from the active map style.

ArgumentTypeDescription
symbolDef.idstringUnique symbol identifier
symbolDef.svgstringInner SVG path content with {{token}} placeholders — see SVG structure
symbolDef.viewBoxstringSVG viewBox, e.g. '0 0 44 44'. Anything drawn outside it is cut off
symbolDef.anchor[number, number]Optional. Normalised [x, y] anchor point within the viewBox. Default: [0.5, 0.5]
services.symbolRegistry.register({
id: 'star',
viewBox: '0 0 44 44',
anchor: [0.5, 0.5],
backgroundColor: '#1d70b8',
svg: `
<path d="..." fill="{{selectedColor}}" stroke="{{activeColor}}" stroke-width="6" paint-order="stroke fill"/>
<path d="..." fill="{{backgroundColor}}" stroke="{{haloColor}}" stroke-width="2" paint-order="stroke fill"/>
<path d="..." fill="{{foregroundColor}}"/>
`
})

See Symbol Config for the full list of token properties and the SVG structure convention.


getSymbolDef(style)

Returns the symbol definition for a dataset or draw style, sized for its symbolSize — with the viewBox and anchor for that size. Pass the result to the resolve methods.

Reads the style's symbol or symbolSvgContent, symbolSize, symbolViewBox and symbolAnchor. Marker options drop the symbol prefix (svgContent, size, viewBox, anchor); for those, use getMarkerSymbolDef.

Returns:
Object | undefined. The sized symbol definition, or undefined when the style has no known symbol.
ArgumentTypeDescription
styleObjectA dataset or draw style

getMarkerSymbolDef(options)

Returns the symbol definition for marker options, sized for their size — with the viewBox and anchor for that size. Reads svgContent or symbol, size, viewBox and anchor, each falling back to the map's defaults.

Returns:
Object | undefined. The sized symbol definition, or undefined when neither svgContent nor symbol names a known symbol.
ArgumentTypeDescription
optionsMarkerOptionsThe marker's options

getKeySymbol(style, mapStyle)

Returns { svg, viewBox } for a dataset style's symbol as drawn in the map key: always at 'medium' size, and in the page's colour scheme (mapStyle.appColorScheme) rather than the map's.

Returns:
{ svg: string, viewBox: string } | null. The symbol, or null when the style has no known symbol.
ArgumentTypeDescription
styleObjectA dataset style
mapStyleMapStyleConfigThe current map style, which provides selectedColor, activeColor and haloColor

getSizedSymbolDef(symbolDef, options?)

Sizes a definition from get() (or { svg } for inline content) directly. Built-in symbols are drawn at the size's scale with fixed-width rings; SVG-template symbols are scaled as a whole.

Returns:
Object. The sized definition, with the viewBox and anchor for that size.
ArgumentTypeDescription
symbolDefObjectA registered definition, or { svg } for inline content
options.viewBoxstringOptional. viewBox override. SVG-template symbols only
options.size'small' | 'medium' | 'large'Optional. The size. Defaults to the map's default size
options.anchor[number, number]Optional. Anchor override, as described in Symbol Config: anchor

get(id)

Returns the symbol definition for the given ID, or undefined if not registered.

Returns:
Object | undefined. The symbol definition.
ArgumentTypeDescription
idstringThe symbol's ID
const symbolDef = services.symbolRegistry.get('pin')

list()

Returns an array of all registered symbol definitions.

Returns:
Object[]. The symbol definitions.
const symbols = services.symbolRegistry.list()

resolve(symbolDef, styleColors, mapStyle)

Resolves a symbol's SVG for normal (unselected, inactive) rendering. Both {{selectedColor}} and {{activeColor}} are replaced with 'none', so neither ring is visible.

Returns:
string. The resolved SVG.
ArgumentTypeDescription
symbolDefObjectThe symbol definition, e.g. from getSymbolDef
styleColorsObjectToken values, overriding the symbol's and the map's defaults
mapStyleMapStyleConfigThe current map style, which provides selectedColor, activeColor and haloColor
const svg = services.symbolRegistry.resolve(
services.symbolRegistry.getSymbolDef({ symbol: 'pin', symbolSize: 'large' }),
{ backgroundColor: '#d4351c' },
mapStyle
)

resolveActive(symbolDef, styleColors, mapStyle)

Resolves a symbol's SVG for active (keyboard cursor) rendering. Both {{selectedColor}} and {{activeColor}} are live — the committed ring and the focus ring are both visible simultaneously, so an active item always shows both rings regardless of whether it is also selected.

Returns:
string. The resolved SVG.
ArgumentTypeDescription
symbolDefObjectThe symbol definition, e.g. from getSymbolDef
styleColorsObjectToken values, overriding the symbol's and the map's defaults
mapStyleMapStyleConfigThe current map style, which provides selectedColor, activeColor and haloColor
const svg = services.symbolRegistry.resolveActive(
services.symbolRegistry.get('pin'),
{ backgroundColor: '#d4351c' },
mapStyle
)

resolveSelected(symbolDef, styleColors, mapStyle)

Resolves a symbol's SVG for committed-selection rendering. {{selectedColor}} is live (the black committed ring is visible) but {{activeColor}} is forced to 'none' — use this when an item is selected but not the current keyboard cursor.

Returns:
string. The resolved SVG.
ArgumentTypeDescription
symbolDefObjectThe symbol definition, e.g. from getSymbolDef
styleColorsObjectToken values, overriding the symbol's and the map's defaults
mapStyleMapStyleConfigThe current map style, which provides selectedColor, activeColor and haloColor
const svg = services.symbolRegistry.resolveSelected(
services.symbolRegistry.get('pin'),
{ backgroundColor: '#d4351c' },
mapStyle
)

resolveVariant(symbolDef, styleColors, mapStyle, variant)

Resolves a symbol's SVG for the named variant: 'normal' (resolve), 'active' (resolveActive) or 'selected' (resolveSelected).

Returns:
string. The resolved SVG.
ArgumentTypeDescription
symbolDefObjectThe symbol definition, e.g. from getSymbolDef
styleColorsObjectToken values, overriding the symbol's and the map's defaults
mapStyleMapStyleConfigThe current map style, which provides selectedColor, activeColor and haloColor
variant'normal' | 'active' | 'selected'Which variant to resolve