2D viewer changes in 3.0
Every change an application built on the 2.x 2D viewer meets in 3.0 — the swapped mouse buttons, several models in one plan, fitting, the client getter, labels and annotations, the declared types and the viewercommon changes a 2D application feels — with what to do for each.
@bimworks/viewer2d keeps its package name, its entry point and its type definitions, and the constructor is unchanged. This page lists everything else an application built on the 2.x 2D viewer sees change in 3.0, and what to do about it. The 2D viewer is being phased out: for new work, show plans in the 3D viewer (Show a floor plan), whose own changes are on 3D viewer changes in 3.0.
Every change has a class:
- Breaking: 2.x code fails or gives a wrong result.
- Behaviour: the same code runs, but the result or what the user sees differs.
- Requirement: how the viewer is installed or served.
Overview#
| Change | 2.x | 3.0 | Class | What to do |
|---|---|---|---|---|
| Mouse buttons | a left drag panned, a middle drag rotated | a left drag rotates, a middle drag pans, as in the 3D viewer | Behaviour | tell your users (below) |
Version export |
Version |
BuildVersion |
Breaking | rename |
viewer2d.client |
a field | a getter without a setter | Breaking if used | set the client on the ModelManager |
| Several models in one plan | each in its own frame, up to tens of metres apart | placed together; the camera follows the 3D viewer correctly | Behaviour | drop your own offset correction |
| Fit on load | per model, as each arrived | once, to all the models of the first batch | Behaviour | — |
viewFit, viewFitModels |
— | return a Promise; a fit can turn the plan (rotation) |
Behaviour | await them where order matters |
| Labels | applied to the objects loaded at that moment | also applied to objects loaded later | Behaviour | — |
| Annotation overlay | — | a .bwa-annotation-overlay element in the container |
Behaviour | check your own elements in the container |
| Versions in the ModelManager | any version object | a version without uuid or its metadata is refused (IncompleteVersionError) |
Breaking for some | load full versions (below) |
| Dependencies | — | all @bimworks/* and @sascom/* packages of one version |
Requirement | upgrade the packages together |
Mouse buttons#
Left drag rotates (Behaviour). A drag with the left button turns the plan, and a drag with the middle button pans it, the same as in the 3D viewer; 2.x did the opposite. There is no setting for the mapping. With rotation switched off, a left drag does nothing (in 2.x it panned). The viewer also stops the browser's autoscroll on a middle click in its container. Your users notice at once, so tell them.
Packages#
BuildVersion (Breaking). The export Version, the viewer's build string, is now BuildVersion, as in jssdk, viewercommon and the 3D viewer; import {Version} from "@bimworks/viewer2d" fails when the module links.
One version for every package (Requirement). Upgrade @bimworks/viewer2d, @bimworks/viewercommon, @bimworks/jssdk, @sascom/commonjs and @sascom/jsclient together, to the version of the instance: packages of two versions install two copies of jssdk, and its Qid and QidSet objects then fail instanceof across them (JavaScript and TypeScript). The single-file build is still viewer2d.bimworks.js (Downloads).
The npm package. It ships www/ and viewer2d.d.ts only, and its JavaScript without comments; entry point and paths are unchanged.
The viewer#
viewer2d.client is a getter (Breaking, rare). 2.x copied the ModelManager's client into a field when the viewer was created. 3.0 reads it from the ModelManager each time it needs it, through a getter without a setter, so viewer2d.client = x throws a TypeError in a module. Set the client on the ModelManager (setClient) instead.
Several models in one plan (Behaviour). 2.x drew every model in its own frame, so models that belong together could lie tens of metres apart. 3.0 places every model relative to the first one, so they line up, and a camera position from the 3D viewer is converted with that viewer's offset, which 2.x left out, so it lands where it should. When no storey matches the camera's height, the storeys shown stay as they are. Remove any offset your application applied itself.
Fit on load (Behaviour). 2.x fitted the view to each model's box as it arrived. 3.0 fits once, to the union of the models of the first batch.
Fitting (Behaviour). viewFit and viewFitModels return a Promise that resolves once the fit is applied. ViewFitOptions.rotation is new: KEEP, the default, keeps the 2.x behaviour; ORIGINAL, WIDEST_HORIZONTAL, MODEL_AXIS and OBJECT_AXIS turn the plan, the last one by rotationObject or the one fitted object. animationTimeMs is honoured, next to the older duration, and the scale is right for a turned view.
Labels (Behaviour). Labels set with ObjectStateManager.setLabels also reach objects that load later. Text placement was rewritten.
Annotations (Behaviour). The viewer always adds an element .bwa-annotation-overlay to its container: absolutely positioned, z-index: 12, and transparent to the pointer. It draws the template annotation layers; annotations added with addAnnotation are still not drawn in 2D. Check elements of your own that you position in the viewer's container.
Declarations. These change no behaviour, but TypeScript written against the 2.x declarations may stop compiling:
addModels(newVersions, allVersions)andremoveModels(versions)take versions; 2.x declaredModelandunknown.primarySelectionChanged, a declared method that did nothing, is gone; the ObjectStateManager calls it only on listeners that have it.isTextShown,getFontScale,setFontScale,getActiveStorey,hasModels,toggleFullScreenandisFullScreenare declared. New aresetCameraPoseViewer,cameraPoseToWorld,worldToCameraPoseandControl.getWorldCoordinatesFromScreenCoordinates, theannotationsoption ofscreenshot,debugging.renderStatistics, and the declaration of the existingshowLoadersetting.
Changes in viewercommon that a 2D application meets#
Incomplete versions are refused (Breaking for some). ModelManager.addModels and setModels reject with IncompleteVersionError for a version without a uuid, or without its metadata (im_metadata) unless it is a point cloud, a PDF or a GLB. The 2.x ModelManager and 2D viewer never read the metadata, so a 2D-only application could pass the version summaries of a node listing; those have no metadata. Load each version in full with client.fs.getNodeVersion(uuid), and wait until its processing has finished.
Labels are {qid, labels} (Breaking, TypeScript only). The Label type is {qid, labels}; 2.x declared {qid, lines}, which the viewers ignored. setLabels returns a Promise.
highlightQuery(query, highlightColor, backgroundColor) (Breaking, TypeScript only). 2.x declared a first argument origin that the code never had, so TypeScript that followed the declaration passed its listener as the query.
inverseOf (Behaviour, a fix). ModelManager.inverseOf() returns every loaded object not in the argument; in 2.x it always returned an empty set.