Skip to content

Commit

Permalink
feat: add type guard for DefaultCameraManager (#4680)
Browse files Browse the repository at this point in the history
* docs: make note of necessary cast in camera manager settings

* chore: add type guard for DefaultCameraManager

* docs: add to docs

* chore: add tsdoc

* chore: bump reveal version to 4.16.0
  • Loading branch information
haakonflatval-cognite authored Jul 26, 2024
1 parent dd0890d commit a35389e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion documentation/docs/examples/controlsmodes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ Default value is `false`.
Example of setting different camera controls options:

```jsx runnable
// import { isDefaultCameraManager } from '@cognite/reveal';

const newControlsOptions = {
mouseWheelAction: 'zoomToCursor',
changeCameraTargetOnClick: true,
};

viewer.cameraManager.setCameraControlsOptions(newControlsOptions);
if (isDefaultCameraManager(viewer.cameraManager)) {
viewer.cameraManager.setCameraControlsOptions(newControlsOptions);
}
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions viewer/api-entry-points/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export {
CameraControlsOptions,
DebouncedCameraStopEventTrigger,
DefaultCameraManager,
isDefaultCameraManager,
CameraManagerEventType,
CameraManagerHelper,
CameraManager,
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal",
"version": "4.15.2",
"version": "4.16.0",
"description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.",
"homepage": "https://github.com/cognitedata/reveal/tree/master/viewer",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion viewer/packages/camera-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Copyright 2021 Cognite AS
*/
export { DefaultCameraManager } from './src/DefaultCameraManager';
export { DefaultCameraManager, isDefaultCameraManager } from './src/DefaultCameraManager';
export { ProxyCameraManager } from './src/ProxyCameraManager';
export { StationaryCameraManager } from './src/StationaryCameraManager';
export { CameraManagerHelper } from './src/CameraManagerHelper';
Expand Down
7 changes: 7 additions & 0 deletions viewer/packages/camera-manager/src/DefaultCameraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,10 @@ export class DefaultCameraManager implements CameraManager {
return clamp(duration, DefaultCameraManager.MinAnimationDuration, DefaultCameraManager.MaxAnimationDuration);
}
}

/**
* type guard which determines if the provided camera manager is a @see { DefaultCameraManager }
*/
export function isDefaultCameraManager(cameraManager: CameraManager): cameraManager is DefaultCameraManager {
return cameraManager instanceof DefaultCameraManager;
}
3 changes: 3 additions & 0 deletions viewer/reveal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,9 @@ export class InvertedNodeCollection extends NodeCollection {
serialize(): SerializedNodeCollection;
}

// @public
export function isDefaultCameraManager(cameraManager: CameraManager): cameraManager is DefaultCameraManager;

// @beta
export function isFlexibleCameraManager(manager: CameraManager): manager is IFlexibleCameraManager;

Expand Down

0 comments on commit a35389e

Please sign in to comment.