@@function: — Function Dispatch
Call registered functions from your JSON config to transform values at resolution time.
@@function:functionNameHow it works
When the converter encounters an object with an @@function key, it calls the named function with the rest of the object as arguments. The function's return value replaces the entire object.
This is resolved in Stage 2 by the JSONConverter, meaning you can combine it with @@#params references in the arguments (which resolve first in Stage 1).
Syntax
Function call pattern
{
"@@function": "setQueryParams",
"url": "https://api.example.com/tiles/{z}/{x}/{y}.png",
"query": {
"colormap": "viridis"
}
}Registered functions
setQueryParams
Builds a URL by appending query parameters. Takes url and query as arguments.
setQueryParams — dynamic tile URL
The function builds the full URL with query params from the param values.
Input
{
"source": {
"type": "raster",
"tiles": [
{
"@@function": "setQueryParams",
"url": "https://tiles.example.com/{z}/{x}/{y}.png",
"query": {
"colormap": "@@#params.colormap",
"rescale": "@@#params.rescale"
}
}
]
}
}Controls
Output
{
"source": {
"type": "raster",
"tiles": [
"https://tiles.example.com/{z}/{x}/{y}.png?colormap=viridis&rescale=0%2C3000"
]
}
}ifParam
Conditional value selection. Evaluates condition and returns then if truthy, otherwise else.
ifParam — conditional value
Toggle the switch to see the conditional resolve to different values.
Input
{
"paint": {
"fill-opacity": {
"@@function": "ifParam",
"condition": "@@#params.showLayer",
"then": 0.8,
"else": 0
}
}
}Controls
Output
{
"paint": {
"fill-opacity": 0.8
}
}Tips & Gotchas
- Functions must be registered in
converter-config.tsbefore they can be called. - The entire object containing
@@functionis replaced by the function's return value. - Arguments can use
@@#paramsreferences — params resolve first (Stage 1) before functions are called (Stage 2).