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:
| ID | Anchored at | Description |
|---|---|---|
'pin' | Tip | Teardrop pin |
'circle' | Centre | Filled circle |
'square' | Centre | Rounded square |
'hexagon' | Centre | Pointy-top hexagon |
'triangle' | Centroid | Point-up triangle |
'diamond' | Centre | Square 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.
| Argument | Type | Description |
|---|---|---|
defaults | Object | The 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.
| Argument | Type | Description |
|---|---|---|
symbolDef.id | string | Unique symbol identifier |
symbolDef.svg | string | Inner SVG path content with {{token}} placeholders — see SVG structure |
symbolDef.viewBox | string | SVG 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, orundefinedwhen the style has no known symbol.
| Argument | Type | Description |
|---|---|---|
style | Object | A 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, orundefinedwhen neithersvgContentnorsymbolnames a known symbol.
| Argument | Type | Description |
|---|---|---|
options | MarkerOptions | The 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, ornullwhen the style has no known symbol.
| Argument | Type | Description |
|---|---|---|
style | Object | A dataset style |
mapStyle | MapStyleConfig | The 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 theviewBoxandanchorfor that size.
| Argument | Type | Description |
|---|---|---|
symbolDef | Object | A registered definition, or { svg } for inline content |
options.viewBox | string | Optional. 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.
| Argument | Type | Description |
|---|---|---|
id | string | The 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.
| Argument | Type | Description |
|---|---|---|
symbolDef | Object | The symbol definition, e.g. from getSymbolDef |
styleColors | Object | Token values, overriding the symbol's and the map's defaults |
mapStyle | MapStyleConfig | The 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.
| Argument | Type | Description |
|---|---|---|
symbolDef | Object | The symbol definition, e.g. from getSymbolDef |
styleColors | Object | Token values, overriding the symbol's and the map's defaults |
mapStyle | MapStyleConfig | The 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.
| Argument | Type | Description |
|---|---|---|
symbolDef | Object | The symbol definition, e.g. from getSymbolDef |
styleColors | Object | Token values, overriding the symbol's and the map's defaults |
mapStyle | MapStyleConfig | The 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.
| Argument | Type | Description |
|---|---|---|
symbolDef | Object | The symbol definition, e.g. from getSymbolDef |
styleColors | Object | Token values, overriding the symbol's and the map's defaults |
mapStyle | MapStyleConfig | The current map style, which provides selectedColor, activeColor and haloColor |
variant | 'normal' | 'active' | 'selected' | Which variant to resolve |