Skip to main content
Version: Version 5 beta

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.

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');


addEventListener()

addEventListener: (eventName, callback) => void

Adds an event listener for plugin events.

Parameters

eventName: "activated" | "registered" | "deregistered" | "deactivated"

The name of the event to listen for.

callback: (pluginId) => void | (pluginId) => void | (pluginId) => void | (pluginId) => void

The callback function to execute when the event is triggered.

Returns

void


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');


emitActivated()

emitActivated: (pluginId) => void

Emits the ‘activated’ event for a plugin.

Parameters

pluginId: string

The unique ID of the activated plugin.

Returns

void


emitDeactivated()

emitDeactivated: (pluginId) => void

Emits the ‘deactivated’ event for a plugin.

Parameters

pluginId: string

The unique ID of the deactivated plugin.

Returns

void


emitDeregistered()

emitDeregistered: (pluginId) => void

Emits the ‘deregistered’ event for a plugin.

Parameters

pluginId: string

The unique ID of the deregistered plugin.

Returns

void


emitRegistered()

emitRegistered: (pluginId) => void

Emits the ‘registered’ event for a plugin.

Parameters

pluginId: string

The unique ID of the registered plugin.

Returns

void


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.


removeEventListener()

removeEventListener: (eventName, callback) => void

Removes an event listener for plugin events.

Parameters

eventName: "activated" | "registered" | "deregistered" | "deactivated"

The name of the event to stop listening for.

callback: (pluginId) => void | (pluginId) => void | (pluginId) => void | (pluginId) => void

The callback function to be removed.

Returns

void