Skip to main content

Interface: ICustomCameraControls

viewer.ICustomCameraControls

interface

description Interface for custom camera controls. This is a specification for implementers to model: it is not an exported method or class.

Custom camera controls allow the API user to freely move the viewer's camera and define the camera projection used. These camera properties are used to render the viewer 3D scene directly into the viewer's GL context.

Custom camera controls must implement the onActivate, onAnimationFrame, onAttach, onDeactivate, onDetach, onReference, and onResize methods.

Custom camera controls trigger rerendering automatically when the camera pose or projection is changed through the projectionMatrix and viewMatrix callbacks.

See the model view projection article on MDN for an introduction to view and projection matrices.

Custom camera controls can choose to make updates on each animation frame or only based on user input. Invoking updates on each camera frame is more resource intensive.

Only a single custom camera control instance can be attached to the viewer at any given time.

Methods#

onActivate#

â–¸ onActivate(viewer, viewMatrix, projectionMatrix, reference): void

Method called when the camera controls have been activated and is responsible for moving the viewer's camera and defining its projection. This method gives the camera controls a chance to initialize resources, perform any transitions, and determine initial state.

description Use the Viewer.getContainer method to get the container for determining the viewer size and aspect as well as for attaching event handlers.

Use the view matrix to determine initial properties such as camera position, forward vector, and up vector.

Use the projection matrix to determine the initial projection properties.

Store the reference coordiante translations during future reference reference changes.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom camera controls instance was just added to.
viewMatrixnumber[]The viewer's view matrix.
projectionMatrixnumber[]The viewers's projection matrix.
referenceLngLatAltThe viewer's reference.

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:67


onAnimationFrame#

â–¸ onAnimationFrame(viewer, frameId): void

Method called for each animation frame.

desdcription Custom camera controls can choose to make updates on each animation frame or only based on user input. Invoking updates on each animation frame is more resource intensive.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom camera controls instance is attached to.
frameIdnumberThe request animation frame's id.

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:86


onAttach#

â–¸ onAttach(viewer, viewMatrixCallback, projectionMatrixCallback): void

Method called when the camera controls have been attached to the viewer. This gives the camera controls a chance to initialize resources.

description Camera controls are attached to the viewer with the with Viewer.attachCustomCameraControls method.

Use the matrix callback functions to modify the camera pose and projection of the viewer's camera.

Invoking the matrix callbacks has no effect if the custom camera controls have not been activated.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom camera controls instance was just added to.
viewMatrixCallback(viewMatrix: number[]) => void-
projectionMatrixCallback(projectionMatrix: number[]) => void-

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:110


onDeactivate#

â–¸ onDeactivate(viewer): void

Method called when the camera controls have been deactivated. This gives the camera controls a chance to clean up resources and event listeners.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom camera controls instance is attached to.

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:124


onDetach#

â–¸ onDetach(viewer): void

Method called when the camera controls have been detached from the viewer. This gives the camera controls a chance to clean up resources and event listeners.

description Camera controls are attached to the viewer with the with Viewer.detachCustomCameraControls method.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom camera controls instance was just detached from.

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:138


onReference#

â–¸ onReference(viewer, reference): void

Method called when the viewer's reference position has changed. This gives the custom camera controls a chance to reposition the camera.

description Calculate the updated topocentric positions for scene objects using the previous reference, the new provided reference as well as the geodeticToEnu and enuToGeodetic functions.

Parameters#

NameTypeDescription
viewerIViewerThe viewer this custom renderer is added to.
referenceLngLatAltThe viewer's current reference position.

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:156


onResize#

â–¸ onResize(viewer): void

Method called when the viewer has been resized.

description Use this method to modify the projection.

Parameters#

NameType
viewerIViewer

Returns#

void

Defined in#

viewer/interfaces/ICustomCameraControls.ts:165