ToolsController
The Tools controller allows you to let users draw elements on the map.
Extended by
Methods
setTool()
setTool(
tool
:null
|ToolType
):void
Sets the tool to use for drawing elements on the map.
Use this method to programmatically activate drawing tools for users. When a tool is set, users can draw elements on the map using that tool. Set to null
to deactivate all drawing tools.
Parameters
Returns
void
Example
// Set the tool to "marker"
await felt.setTool("marker");
// put down the tool
await felt.setTool(null);
getTool()
getTool():
Promise
<null
|ToolType
>
Gets the current tool, if any is in use.
Use this method to check which drawing tool is currently active, if any.
Returns
Promise
<null
| ToolType
>
A promise that resolves to the current tool, or null
if no tool is in use.
Example
const tool = await felt.getTool(); // "marker", "polygon", etc.
onToolChange()
onToolChange(
args
: {handler
: (tool
:null
|ToolType
) =>void
; }):VoidFunction
Listens for changes to the current tool.
Use this to react to tool changes, such as updating your UI to reflect the currently active drawing tool.
Parameters
Returns
VoidFunction
Example
const unsubscribe = felt.onToolChange({
handler: tool => console.log(tool),
});
// later on...
unsubscribe();
setToolSettings()
setToolSettings(
settings
:InputToolSettings
):void
Sets the settings for the current tool.
Use this method to configure how drawing tools behave, such as setting colors, stroke widths, or other tool-specific properties.
Parameters
Returns
void
Example
// Set the settings for the marker tool
await felt.setToolSettings({
tool: "marker",
color: "#FE17",
});
getToolSettings()
getToolSettings<
T
>(tool
:T
):Promise
<ToolSettingsMap
[T
]>
Gets the settings for the chosen tool.
Use this method to retrieve the current configuration of a drawing tool.
Type Parameters
T
extends ConfigurableToolType
Parameters
tool
T
The tool to get settings for.
Returns
Promise
<ToolSettingsMap
[T
]>
A promise that resolves to the settings for the chosen tool.
Example
const settings = await felt.getToolSettings("marker");
onToolSettingsChange()
onToolSettingsChange(
args
: {handler
: (settings
:ToolSettingsChangeEvent
) =>void
; }):VoidFunction
Listens for changes to the settings on all tools.
Use this to react to tool setting changes, such as updating your UI to reflect the current tool configuration.
Parameters
args
{ handler
: (settings
: ToolSettingsChangeEvent
) => void
; }
args.handler
(settings
: ToolSettingsChangeEvent
) => void
Returns
VoidFunction
A function to unsubscribe from the listener.
Example
const unsubscribe = felt.onToolSettingsChange({
handler: settings => console.log(settings),
});
// later on...
unsubscribe();
Last updated
Was this helpful?