Tools and Commands
As you have learned in Tools and Events
, tools are used to describe what operations will be executed when a specific event occurs. Commands
are used as a wrapper around tools, including properties which describe how the tools will behave, such as enabled
, active
, and options
.
The options
property is used to modify how a tool behaves so that you can handle an event in different ways without creating multiple tools. For example, the click
tool in the following command will no longer log the click position if we set options.logClickPosition
to false
:
var logClickWithOption = {
enabled: true,
active: true,
options: {
logClickPosition: true,
},
tool: {
click: function(ev) {
if (this.options.logClickPosition) {
console.log('Click occurred at', ev.clientX, ev.clientY);
}
},
},
};
api.commands.addCommand(logClickWithOption, 'logClickWithOption');
api.commands.setCommandOptions('logClickWithOption', {
logClickPosition: false,
};
When use setCommandOptions
, the change will merge into commands so you don't have to specify all options each time.
Take a look at our command module
docs, which describes the methods available through our api. Also before creating your own commands, take a look at the pre-built commands in this section, as they are designed to handle common use cases, such as scene navigation (orbit
, pan
, zoom
) and node manipulation (nodeMove
, nodeRotate
, nodeScale
).