UNPKG

@inweb/viewer-visualize

Version:

JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS

42 lines (41 loc) 1.49 kB
import { IComponentsRegistry } from "@inweb/viewer-core"; /** * Viewer components registry. Use this registry to register custom components. * * To implement custom component: * * 1. Define a component class implements {@link IComponent}. * 2. Define a constructor with a `viewer` parameter and add mouse event listeners for the specified viewer. * 3. Define the component logic in the event listeners. For example, listen for the `geometryend` event and * implement post-processing logic for the model. * 4. Override {@link IComponent.dispose} and remove mouse event listeners from the viewer. * 5. Register component provider in the components registry by calling the * {@link components.registerComponent}. * * @example Implementing a custom component. * * ```javascript * import { IComponent, components, Viewer } from "@inweb/viewer-visualize"; * * class MyComponent implements IComponent { * protected viewer: Viewer; * * constructor(viewer: Viewer) { * this.viewer = viewer; * this.viewer.addEventListener("geometryend", this.onGeometryEnd); * } * * override dispose() { * this.viewer.removeEventListener("geometryend", this.onGeometryEnd); * } * * onGeometryEnd = (event: MouseEvent) => { * this.viewer.executeCommand("zoomToExtents"); * }; * * } * * components.registerComponent( "MyComponent", (viewer): IComponent => new MyComponent(viewer)); * ``` */ export declare const components: IComponentsRegistry;