Skip to main content
Version: Version 5

Interface: Plugins

Groups all the API actions related to plugins in the Viewer. Plugins allow users to extend the viewer’s functionality with their own interactive layers and behaviors.

Extends

Properties

activate()

activate: (pluginId) => void

Activates a plugin by its ID. This deactivates all other plugins and calls the plugin’s activate() method.

Parameters

pluginId

string

The unique ID of the plugin to activate.

Returns

void

Throws

If the plugin with the given ID does not exist.

Example

viewer.plugins.activate('my-custom-plugin');

deactivate()

deactivate: (pluginId) => void

Deactivates a plugin by its ID. This calls the plugin’s deactivate() method.

Parameters

pluginId

string

The unique ID of the plugin to deactivate.

Returns

void

Throws

If the plugin with the given ID does not exist.

Example

viewer.plugins.deactivate('my-custom-plugin');

deregister()

deregister: (pluginId) => void

Deregisters a plugin from the viewer. This deactivates the plugin if it’s currently active and removes it from the plugin manager.

Parameters

pluginId

string

The unique ID of the plugin to deregister.

Returns

void

Throws

If the plugin with the given ID does not exist.

Example

viewer.plugins.deregister('my-custom-plugin');

get()

get: (pluginId) => Plugin

Gets a plugin by its ID.

Parameters

pluginId

string

The unique ID of the plugin to retrieve.

Returns

Plugin

  • The plugin instance, or undefined if not found.

Example

const plugin = viewer.plugins.get('my-custom-plugin');

getActive()

getActive: () => string

Gets the ID of the currently active plugin.

Returns

string

The unique ID of the active plugin, or null if no plugin is active.

Example

const activePluginId = viewer.plugins.getActive();

isActive()

isActive: (pluginId) => boolean

Checks if a plugin is currently active.

Parameters

pluginId

string

The unique ID of the plugin to check.

Returns

boolean

The value is true if the plugin is active, false otherwise.

Example

const isActive = viewer.plugins.isActive('my-custom-plugin');

register()

register: (plugin) => void

Registers a plugin with the viewer. The plugin must implement the Plugin interface with a unique ID, documentView reference, and activate or deactivate methods.

Parameters

plugin

Plugin

The plugin to register. Must implement the Plugin interface.

Returns

void

Throws

If a plugin with the same ID is already registered.

Example

viewer.plugins.register({
id: 'my-custom-plugin',
documentView: myDocumentViewInstance,
activate: () => { console.log('Plugin activated'); },
deactivate: () => { console.log('Plugin deactivated'); }
});

Methods

addEventListener()

addEventListener<K>(eventName, callback): void

Adds an event listener for a specified event.

Type Parameters

K

K extends keyof PluginsEventMap

Parameters

eventName

K

The name of the event to listen for.

callback

PluginsEventMap[K]

The callback function to execute when the event is triggered.

Returns

void

Inherited from

EventHandler.addEventListener


removeEventListener()

removeEventListener<K>(eventName, callback): void

Removes an event listener for a specified event.

Type Parameters

K

K extends keyof PluginsEventMap

Parameters

eventName

K

The name of the event to stop listening for.

callback

PluginsEventMap[K]

The callback function to remove.

Returns

void

Inherited from

EventHandler.removeEventListener