Reference·JavaScript · @bimworks/viewer2dJavaScript

Viewer2d

Class in @bimworks/viewer2d.

API catalogue · @bimworks/viewer2d · Class

TypeScript#
class Viewer2d

2D viewer based on WebGL.

Inheritance and interfaces#

Members#

Member Kind Description
constructor Method Create a new Viewer2d
canvas Property The canvas the 2D viewer draws on (inside container)
container Property
modelManager Property
objectStateManager Property
addedToSelectionSet Method Objects were added to the selection implementationOf: ObjectStateListener.addedToSelectionSet
addedToVisibleSet Method Objects were made visible implementationOf: ObjectStateListener.addedToVisibleSet
addModels Method Models were loaded: their object data is in the ModelManager already implementationOf: ModelListener.addModels
cameraPoseToWorld Method A camera pose position (mm, frame of the 3D viewer) in 2D world coordinates; z is passed through
cameraPoseUpdated Method The pose (eye, pivot, target) of a camera has been updated (ObjectStateManager.setCameraPose) implementationOf: ObjectStateListener.cameraPoseUpdated
colorChanged Method
colorReset Method The colour of the given objects has been reset to their own implementationOf: ObjectStateListener.colorReset
destroy Method Destroys the viewer and any (heavy) resources associated with it. As long as there is a reference to the Viewer2d instance it won't be completely destroyed.
getActiveStorey Method The storey the plan shows: the current one while visible, else the first visible storey with a level; null for none. minZ is the storey's lowest point in mod…
getControl Method Get access to the Control object for programmatic viewer manipulation
getFontScale Method The size of the text labels in pixels (15 by default)
getHeight Method Get the height of the viewer in pixels
getModelManager Method
getWidth Method Get the width of the viewer in pixels
hasModels Method Whether any model is loaded in the plan
hoverOff Method Called when the given object is not being hovered on anymore implementationOf: ObjectStateListener.hoverOff
hoverOn Method Called when the given object is being hovered on implementationOf: ObjectStateListener.hoverOn
init Method This method must be called before loading any of the models. Keep in mind that this method is async, and models can only be loaded after the returned Promise…
isDoorOpeningRendering Method
isFaceRendering Method
isFullScreen Method
isIfcLineRendering Method
isTextShown Method Whether the text labels are shown (toggleShowText); false before init
isWireframeRendering Method
removedFromSelectionSet Method Objects were removed from the selection implementationOf: ObjectStateListener.removedFromSelectionSet
removedFromVisibleSet Method Objects were hidden. Any of them that were selected have been deselected first implementationOf: ObjectStateListener.removedFromVisibleSet
removeModels Method Models were unloaded implementationOf: ModelListener.removeModels
resize Method
screenshot Method Will take a screenshot of the contents of the Viewer2d.
setBuildingStoreysVisibleExclusive Method Show only the objects of these building storeys, without their openings when hideOpenings implementationOf: ObjectStateListener.setBuildingStoreysVisibleExcl…
setBuildingStoreyVisibleExclusive Method Show only the objects of one building storey (ObjectStateManager.setBuildingStoreyVisibleExclusive with one storey) implementationOf: ObjectStateListener.set…
setCameraConeDepth Method Set the depth of the camera cone, default is 250px
setCameraConeVisible Method Toggle whether the cone indicating where the 3D camera is (in a Viewer3d) should be visible, default is visible
setCameraPoseViewer Method The viewer whose camera poses this viewer shows as the camera cone. Only needed when that viewer is not registered on this viewer's ObjectStateManager; the 2…
setCameraTrackingMode Method Switch how the synced 3D camera indicator behaves inside the 2D viewer. "MAP" keeps the map fixed and lets the cone move through it. "FOLLOW" keeps the cone …
setDirty Method To be called whenever the rendering state has changed and updates need to become visible
setFontScale Method
setToSelectionSet Method The selection was replaced (also by a click in single-select mode) implementationOf: ObjectStateListener.setToSelectionSet
setVisibleSet Method The set of visible objects was replaced implementationOf: ObjectStateListener.setVisibleSet
start Method Starts the viewer. The viewer will only redraw when needed.
stop Method Stops the viewer. When the viewer is stopped, the view is not updated anymore. Any changes to the viewer will be accumulated and become visible as soon as th…
toggleDoorOpeningRendering Method Toggle whether (generated) door openings are rendered. This only works for models that have been processed when the repository setting `features.generate_doo…
toggleFaceRendering Method Toggle whether faces are rendered.
toggleFullScreen Method Toggles full screen (the container fills the window); returns whether it is now full screen
toggleIfcLineRendering Method Toggle whether ifc lines are rendered. IFC Lines are all lines that have been defined in the original IFC file, such as Axis and FootPrint representations.
toggleShowText Method Toggles whether the text labels are shown
toggleUserPanning Method Toggle whether user panning (by mouse or touch device) is enabled or disabled. It is enabled by default
toggleUserRotate Method Toggle whether user rotate (by mouse or touch device) is enabled or disabled. It is enabled by default
toggleUserSelection Method Toggle whether user selection (by mouse or touch device) is enabled or disabled. It is enabled by default
toggleUserZoom Method Toggle whether user zooming (by mouse wheel or touch device) is enabled or disabled. It is enabled by default. Changing this settings also enabled/disabled z…
toggleWireframeRendering Method Toggle whether wireframes are rendered. Wireframes are usually drawn to emphesize the edges and generally make the model look better
viewFit Method Fits the given objects into view: the viewport is updated so that it shows the bounding box of all of them, and the building storey most of them are on is ma…
viewFitModels Method Fits the given models into view as a whole, using the bounds of each model as loaded. Models not loaded in this viewer are skipped. Rotation as for viewFit; …
worldToCameraPose Method The inverse of cameraPoseToWorld for a 2D world position: [x, y] in mm in the frame of the 3D viewer

constructor#

TypeScript#
constructor(objectStateManager: ObjectStateManager, settings?: Viewer2dSettings)

Create a new Viewer2d

Parameters#

Name Type Description
objectStateManager ObjectStateManager The ObjectStateManager manages all object related state such as visibility, color and selection
settings Viewer2dSettings Optional settings, will use default settings when not provided

canvas#

TypeScript#
readonly canvas: HTMLCanvasElement

The canvas the 2D viewer draws on (inside container)

container#

TypeScript#
readonly container: HTMLElement

modelManager#

TypeScript#
readonly modelManager: ModelManager

objectStateManager#

TypeScript#
readonly objectStateManager: ObjectStateManager

addedToSelectionSet#

TypeScript#
public addedToSelectionSet(qids: Iterable<Qid>): void | Promise<void>

Objects were added to the selection

implementationOf: ObjectStateListener.addedToSelectionSet

Parameters#

Name Type Description
qids Iterable<Qid> The objects added

addedToVisibleSet#

TypeScript#
public addedToVisibleSet(qids: Iterable<Qid>): Promise<void>

Objects were made visible

implementationOf: ObjectStateListener.addedToVisibleSet

Parameters#

Name Type Description
qids Iterable<Qid>

addModels#

TypeScript#
public addModels(newVersions: Iterable<Version>, allVersions: Iterable<Version>): Promise<void>

Models were loaded: their object data is in the ModelManager already

implementationOf: ModelListener.addModels

Parameters#

Name Type Description
newVersions Iterable<Version> The versions that were added
allVersions Iterable<Version> Every loaded version, the new ones included

cameraPoseToWorld#

TypeScript#
public cameraPoseToWorld(position: ArrayLike<number>): Float32Array

A camera pose position (mm, frame of the 3D viewer) in 2D world coordinates; z is passed through

Parameters#

Name Type Description
position ArrayLike<number>

cameraPoseUpdated#

TypeScript#
public cameraPoseUpdated(sourceViewer: unknown, pose: Pose): void

The pose (eye, pivot, target) of a camera has been updated (ObjectStateManager.setCameraPose)

implementationOf: ObjectStateListener.cameraPoseUpdated

Parameters#

Name Type Description
sourceViewer unknown The tag the pose was set with, to recognise one's own updates: "viewer3d" from the Viewer3d, null from the application; compare it, do not use it as an object
pose Pose The new camera pose, in the 3D viewer's render frame

colorChanged#

TypeScript#
public colorChanged(qids: Iterable<Qid>, color: TinyColor): void | Promise<void>

Parameters#

Name Type Description
qids Iterable<Qid>
color TinyColor

colorReset#

TypeScript#
public colorReset(qids: Iterable<Qid>): void | Promise<void>

The colour of the given objects has been reset to their own

implementationOf: ObjectStateListener.colorReset

Parameters#

Name Type Description
qids Iterable<Qid> The objects whose colour was reset

destroy#

TypeScript#
public destroy(): void

Destroys the viewer and any (heavy) resources associated with it. As long as there is a reference to the Viewer2d instance it won't be completely destroyed.

getActiveStorey#

TypeScript#
public getActiveStorey(): { minZ: number; qid: string } | null

The storey the plan shows: the current one while visible, else the first visible storey with a level; null for none. minZ is the storey's lowest point in model mm

getControl#

TypeScript#
public getControl(): Control

Get access to the Control object for programmatic viewer manipulation

getFontScale#

TypeScript#
public getFontScale(): number

The size of the text labels in pixels (15 by default)

getHeight#

TypeScript#
public getHeight(): number

Get the height of the viewer in pixels

getModelManager#

TypeScript#
public getModelManager(): ModelManager

Returns#

The ModelManager connected to this viewer

getWidth#

TypeScript#
public getWidth(): number

Get the width of the viewer in pixels

hasModels#

TypeScript#
public hasModels(): boolean

Whether any model is loaded in the plan

hoverOff#

TypeScript#
hoverOff(qid: Qid): void

Called when the given object is not being hovered on anymore

implementationOf: ObjectStateListener.hoverOff

Parameters#

Name Type Description
qid Qid The Qid of the object that is not being hovered over anymore

hoverOn#

TypeScript#
hoverOn(qid: Qid, previousQid: Qid, screenspaceLocation: vec2): void

Called when the given object is being hovered on

implementationOf: ObjectStateListener.hoverOn

Parameters#

Name Type Description
qid Qid The Qid of the object being hovered over
previousQid Qid The object hovered before, null or undefined for none
screenspaceLocation vec2 The screenspace location of the hover event, when the caller gave one. This can be useful to for example place a popup/tooltip at that location. Screenspace location is x, y coordinate between 0, 0 and canvas width,height

init#

TypeScript#
public init(): Promise<void>

This method must be called before loading any of the models. Keep in mind that this method is async, and models can only be loaded after the returned Promise has resolved.

isDoorOpeningRendering#

TypeScript#
public isDoorOpeningRendering(): boolean

Returns#

Whether rendering of generated door opening directions is currently enabled

isFaceRendering#

TypeScript#
public isFaceRendering(): boolean

Returns#

Whether face rendering is currently enabled

isFullScreen#

TypeScript#
public isFullScreen(): boolean

isIfcLineRendering#

TypeScript#
public isIfcLineRendering(): boolean

Returns#

Whether IFC line rendering is currently enabled

isTextShown#

TypeScript#
public isTextShown(): boolean

Whether the text labels are shown (toggleShowText); false before init

isWireframeRendering#

TypeScript#
public isWireframeRendering(): boolean

Returns#

Whether wireframe rendering is currently enabled

removedFromSelectionSet#

TypeScript#
public removedFromSelectionSet(qids: Iterable<Qid>): void | Promise<void>

Objects were removed from the selection

implementationOf: ObjectStateListener.removedFromSelectionSet

Parameters#

Name Type Description
qids Iterable<Qid> The objects that are no longer selected

removedFromVisibleSet#

TypeScript#
public removedFromVisibleSet(qids: Iterable<Qid>): Promise<void>

Objects were hidden. Any of them that were selected have been deselected first

implementationOf: ObjectStateListener.removedFromVisibleSet

Parameters#

Name Type Description
qids Iterable<Qid>

removeModels#

TypeScript#
public removeModels(versions: Iterable<Version>): Promise<void>

Models were unloaded

implementationOf: ModelListener.removeModels

Parameters#

Name Type Description
versions Iterable<Version> The versions that were removed

resize#

TypeScript#
public resize(width: number, height: number): void

Parameters#

Name Type Description
width number
height number

screenshot#

TypeScript#
public screenshot(options?: ScreenshotOptions): Promise<Blob>

Will take a screenshot of the contents of the Viewer2d.

Parameters#

Name Type Description
options ScreenshotOptions Optional options object

Returns#

A Blob

Example#

The returned Blob can for example be downloaded by the user, using the following example

JavaScript#
	const width = viewer2d.width;
	const height = viewer2d.height;
	const filename = `screencapture-${width}x${height}.png`;
	Utils.downloadBlob(blob, filename);

setBuildingStoreysVisibleExclusive#

TypeScript#
public setBuildingStoreysVisibleExclusive(buildingStoreyQids: Iterable<Qid>): void

Show only the objects of these building storeys, without their openings when hideOpenings

implementationOf: ObjectStateListener.setBuildingStoreysVisibleExclusive

Parameters#

Name Type Description
buildingStoreyQids Iterable<Qid>

setBuildingStoreyVisibleExclusive#

TypeScript#
public setBuildingStoreyVisibleExclusive(buildingStoreyQid: unknown): void

Show only the objects of one building storey (ObjectStateManager.setBuildingStoreyVisibleExclusive with one storey)

implementationOf: ObjectStateListener.setBuildingStoreyVisibleExclusive

Parameters#

Name Type Description
buildingStoreyQid unknown

setCameraConeDepth#

TypeScript#
public setCameraConeDepth(depth: number): void

Set the depth of the camera cone, default is 250px

Parameters#

Name Type Description
depth number The depth in pixels

setCameraConeVisible#

TypeScript#
public setCameraConeVisible(visible: boolean): void

Toggle whether the cone indicating where the 3D camera is (in a Viewer3d) should be visible, default is visible

Parameters#

Name Type Description
visible boolean Whether it should be visible

setCameraPoseViewer#

TypeScript#
public setCameraPoseViewer(viewer: any): void

The viewer whose camera poses this viewer shows as the camera cone. Only needed when that viewer is not registered on this viewer's ObjectStateManager; the 2D viewer uses its global base translation to bring poses into its own world frame

Parameters#

Name Type Description
viewer any

setCameraTrackingMode#

TypeScript#
public setCameraTrackingMode(mode: CameraTrackingMode): void

Switch how the synced 3D camera indicator behaves inside the 2D viewer. "MAP" keeps the map fixed and lets the cone move through it. "FOLLOW" keeps the cone centered while moving the map, clamping manual interaction so the cone stays inside the viewport.

Parameters#

Name Type Description
mode CameraTrackingMode The camera tracking mode

setDirty#

TypeScript#
public setDirty(): void

To be called whenever the rendering state has changed and updates need to become visible

setFontScale#

TypeScript#
public setFontScale(scale: number): void

Parameters#

Name Type Description
scale number

setToSelectionSet#

TypeScript#
public setToSelectionSet(qids: Iterable<Qid>, qidsToUnselect: Iterable<Qid>): void | Promise<void>

The selection was replaced (also by a click in single-select mode)

implementationOf: ObjectStateListener.setToSelectionSet

Parameters#

Name Type Description
qids Iterable<Qid> The objects selected now
qidsToUnselect Iterable<Qid> The objects no longer selected

setVisibleSet#

TypeScript#
public setVisibleSet(qids: Iterable<Qid>, qidsToHide: Iterable<Qid>): void | Promise<unknown>

The set of visible objects was replaced

implementationOf: ObjectStateListener.setVisibleSet

Parameters#

Name Type Description
qids Iterable<Qid> The objects that have been made visible
qidsToHide Iterable<Qid> The objects that have been made invisible

start#

TypeScript#
public start(): void

Starts the viewer. The viewer will only redraw when needed.

stop#

TypeScript#
public stop(): void

Stops the viewer. When the viewer is stopped, the view is not updated anymore. Any changes to the viewer will be accumulated and become visible as soon as the viewer is started again The main reason for stopping the viewer would be for performance, for example when the viewer is currently hidden

toggleDoorOpeningRendering#

TypeScript#
public toggleDoorOpeningRendering(enabled: boolean): void

Toggle whether (generated) door openings are rendered. This only works for models that have been processed when the repository setting features.generate_door_openings had been enabled. Some models contains door opening direction geometry as IFC lines, in those cases it's best to disabled rendering generated door openings.

Parameters#

Name Type Description
enabled boolean True when enabled

toggleFaceRendering#

TypeScript#
public toggleFaceRendering(enabled: boolean): void

Toggle whether faces are rendered.

Parameters#

Name Type Description
enabled boolean True when enabled

toggleFullScreen#

TypeScript#
public toggleFullScreen(enable?: boolean): boolean

Toggles full screen (the container fills the window); returns whether it is now full screen

Parameters#

Name Type Description
enable boolean

toggleIfcLineRendering#

TypeScript#
public toggleIfcLineRendering(enabled: boolean): void

Toggle whether ifc lines are rendered. IFC Lines are all lines that have been defined in the original IFC file, such as Axis and FootPrint representations.

Parameters#

Name Type Description
enabled boolean True when enabled

toggleShowText#

TypeScript#
public toggleShowText(): void

Toggles whether the text labels are shown

toggleUserPanning#

TypeScript#
public toggleUserPanning(enabled: boolean): void

Toggle whether user panning (by mouse or touch device) is enabled or disabled. It is enabled by default

Parameters#

Name Type Description
enabled boolean Whether it should be enabled

toggleUserRotate#

TypeScript#
public toggleUserRotate(enabled: boolean): void

Toggle whether user rotate (by mouse or touch device) is enabled or disabled. It is enabled by default

Parameters#

Name Type Description
enabled boolean Whether it should be enabled

toggleUserSelection#

TypeScript#
public toggleUserSelection(enabled: boolean): void

Toggle whether user selection (by mouse or touch device) is enabled or disabled. It is enabled by default

Parameters#

Name Type Description
enabled boolean Whether it should be enabled

toggleUserZoom#

TypeScript#
public toggleUserZoom(enabled: boolean): void

Toggle whether user zooming (by mouse wheel or touch device) is enabled or disabled. It is enabled by default. Changing this settings also enabled/disabled zoom on double-click

Parameters#

Name Type Description
enabled boolean Whether it should be enabled

toggleWireframeRendering#

TypeScript#
public toggleWireframeRendering(enabled: boolean): void

Toggle whether wireframes are rendered. Wireframes are usually drawn to emphesize the edges and generally make the model look better

Parameters#

Name Type Description
enabled boolean True when enabled

viewFit#

TypeScript#
public viewFit(qids: Iterable<Qid>, options?: ViewFitOptions): void | Promise<void>

Fits the given objects into view: the viewport is updated so that it shows the bounding box of all of them, and the building storey most of them are on is made visible. The plan's rotation is set by options.rotation (ViewFitRotation, default "KEEP"); with "OBJECT_AXIS" the object of options.rotationObject (or the one fitted object) orients the plan.

implementationOf: ObjectStateListener.viewFit

Parameters#

Name Type Description
qids Iterable<Qid> The Qids of the objects to fit
options ViewFitOptions Margin, animation and rotation, see ViewFitOptions

Returns#

Resolves once the fit has been applied; the "OBJECT_AXIS" rotation first queries the object's oriented bounding box

viewFitModels#

TypeScript#
public viewFitModels(versionUuids: Iterable<string>, options?: ViewFitOptions): void | Promise<void>

Fits the given models into view as a whole, using the bounds of each model as loaded. Models not loaded in this viewer are skipped. Rotation as for viewFit; "MODEL_AXIS" uses the oriented bounding boxes of exactly these models.

implementationOf: ObjectStateListener.viewFitModels

Parameters#

Name Type Description
versionUuids Iterable<string> The models to fit
options ViewFitOptions Margin, animation and rotation, see ViewFitOptions

worldToCameraPose#

TypeScript#
public worldToCameraPose(worldCoordinates: ArrayLike<number>): (number)[]

The inverse of cameraPoseToWorld for a 2D world position: [x, y] in mm in the frame of the 3D viewer

Parameters#

Name Type Description
worldCoordinates ArrayLike<number>