Geoman Options API
The GmOptions instance manages the configuration and state of Geoman controls and modes. It handles settings, controls, and layer styles, and provides methods to manage mode states.
Accessing GmOptions
The GmOptions instance is available through the options
property on the Geoman instance:
const options: GmOptionsPartial = {
// configuration options
// see Configuring Geoman section for more details
};
const gm = new Geoman(map,options);
const options = gm.options;
Methods
Mode Management
enableMode
Enables a specific mode for an action type.
options.enableMode(actionType: ActionType, modeName: ModeName): void;
Example:
options.enableMode('draw', 'polygon');
options.enableMode('edit', 'rotate');
disableMode
Disables a specific mode for an action type.
options.disableMode(actionType: ActionType, modeName: ModeName): void;
Example:
options.disableMode('draw', 'polygon');
options.disableMode('edit', 'rotate');
toggleMode
Toggles a specific mode for an action type.
options.toggleMode(actionType: ActionType, modeName: ModeName): void;
Example:
options.toggleMode('draw', 'polygon');
options.toggleMode('edit', 'rotate');
Mode State Queries
isModeEnabled
Checks if a specific mode is currently enabled.
options.isModeEnabled(actionType: ActionType, modeName: ModeName): boolean;
Example:
const isDrawing = options.isModeEnabled('draw', 'polygon');
const isEditing = options.isModeEnabled('edit', 'rotate');
isModeAvailable
Checks if a specific mode is available for use.
options.isModeAvailable(actionType: ActionType, modeName: ModeName): boolean;
Example:
const canDraw = options.isModeAvailable('draw', 'polygon');
const canEdit = options.isModeAvailable('edit', 'rotate');
Control Options
getControlOptions
Gets the options for a specific control.
options.getControlOptions({
actionType: ActionType,
modeName: ModeName
}): ControlOptions | null;
Example:
const polygonOptions = options.getControlOptions({
actionType: 'draw',
modeName: 'polygon'
});
Dynamic Configuration Example
// Get current control options
const polygonControl = gm.options.getControlOptions({
actionType: 'draw',
modeName: 'polygon'
});
// Check mode states
const isPolygonEnabled = gm.options.isModeEnabled('draw', 'polygon');
const isRotateAvailable = gm.options.isModeAvailable('edit', 'rotate');
// Toggle modes
if (isPolygonEnabled) {
gm.options.disableMode('draw', 'polygon');
} else {
gm.options.enableMode('draw', 'polygon');
}