class
CallbackRenderer
implements IRenderer
Per-feature dynamic symbol via a callback function. Maximum flexibility — use when other renderers are insufficient.
Constructor
new CallbackRenderer(fn: (feature: Feature, context?: SymbolRenderContext) => Symbol | null) | Parameter | Type | Description | |
|---|---|---|---|
fn | (feature: Feature, context?: SymbolRenderContext) => Symbol | null | required | Callback that returns a symbol (or null to skip) |
Properties
| Name | Type | Access | Description |
|---|---|---|---|
type | 'callback' | readonly | Renderer type discriminant |
Methods
getSymbol()
getSymbol(feature: Feature, context?: SymbolRenderContext): Symbol | null Invoke user callback to get symbol.
Returns
Symbol | null Example
const renderer = new CallbackRenderer((feature) => {
const pop = feature.attributes.population as number;
const size = Math.sqrt(pop / 10000) * 2;
return {
type: 'simple-marker',
color: pop > 1000000 ? [255,0,0,255] : [0,128,255,255],
size: Math.max(4, Math.min(size, 20)),
};
});