Skip to main content
Version: 3.x

Class: MeasurementTool

@cognite/reveal/tools.MeasurementTool

Enables @see {@link Cognite3DViewer} to perform a point to point measurement. This can be achieved by selecting a point on the 3D Object and drag the pointer to required point to get measurement of the distance. The tools default measurement is in "Meters" as supported in Reveal, but it also provides user to customise the measuring units based on their convinience with the callback.

example

const measurementTool = new MeasurementTool(viewer);
measurementTool.enterMeasurementMode();
// ...
measurementTool.exitMeasurementMode();

// detach the tool from the viewer
measurementTool.dispose();

example

Live Editor

Hierarchy

Constructors

constructor

new MeasurementTool(viewer, options?)

Parameters

NameType
viewerCognite3DViewer
options?MeasurementOptions

Overrides

Cognite3DViewerToolBase.constructor

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:87

Accessors

isInMeasurementMode

get isInMeasurementMode(): boolean

Returns measurement mode state, is measurement mode started or ended.

Returns

boolean

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:53

Methods

dispose

dispose(): void

Dispose Measurement Tool.

Returns

void

Overrides

Cognite3DViewerToolBase.dispose

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:340


enterMeasurementMode

enterMeasurementMode(): void

Enter into point to point measurement mode.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:228


exitMeasurementMode

exitMeasurementMode(): void

Exit measurement mode.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:240


getAllMeasurements

getAllMeasurements(): Measurement[]

Get all measurements from Cognite3DViewer.

Returns

Measurement[]

Array of Measurements containing Id, start point, end point & measured distance.

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:333


off

off(event, callback): void

Unsubscribe to the Measurement event

example

measurementTool.off('disposed', onMeasurementDispose);

Parameters

NameTypeDescription
event"disposed"MeasurementEvents event
callbackDisposedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.off

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:172

off(event, callback): void

Unsubscribe to the Measurement event

example

measurementTool.off('added', onMeasurementAdded);

Parameters

NameTypeDescription
event"added"MeasurementEvents event
callbackMeasurementAddedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.off

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:180

off(event, callback): void

Unsubscribe to the Measurement event

example

measurementTool.off('started', onMeasurementStarted);

Parameters

NameTypeDescription
event"started"MeasurementEvents event
callbackMeasurementStartedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.off

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:188

off(event, callback): void

Unsubscribe to the Measurement event

example

measurementTool.off('ended', onMeasurementEnded);

Parameters

NameTypeDescription
event"ended"MeasurementEvents event
callbackMeasurementEndedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.off

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:196


on

on(event, callback): void

Triggered when the tool is disposed. Listeners should clean up any resources held and remove the reference to the tool.

example

measurementTool.on('disposed', onMeasurementDispose);

Parameters

NameTypeDescription
event"disposed"MeasurementEvents event
callbackDisposedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.on

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:110

on(event, callback): void

Triggered when a measurement is added into the Cognite3DViewer.

example

measurementTool.on('added', onMeasurementAdded);

Parameters

NameTypeDescription
event"added"MeasurementEvents event
callbackMeasurementAddedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.on

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:119

on(event, callback): void

Triggered when a measurement mode is started.

example

measurementTool.on('started', onMeasurementStarted);

Parameters

NameTypeDescription
event"started"MeasurementEvents event
callbackMeasurementStartedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.on

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:128

on(event, callback): void

Triggered when measurement mode is ended.

example

measurementTool.on('ended', onMeasurementEnded);

Parameters

NameTypeDescription
event"ended"MeasurementEvents event
callbackMeasurementEndedDelegateCallback to measurements events

Returns

void

Overrides

Cognite3DViewerToolBase.on

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:137


removeAllMeasurements

removeAllMeasurements(): void

Removes all measurements from the Cognite3DViewer.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:269


removeMeasurement

removeMeasurement(measurement): void

Removes a measurement from the Cognite3DViewer.

Parameters

NameTypeDescription
measurementMeasurementMeasurement to be removed from Cognite3DViewer.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:254


setLineOptions

setLineOptions(options): void

Sets Measurement line width, color and label units value for the next measurment.

Parameters

NameTypeDescription
optionsMeasurementOptionsMeasurementOptions to set line width, color and callback for custom operation on measurement labels.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:290


setMeasurementLabelsVisible

setMeasurementLabelsVisible(enable): void

Sets the visiblity of labels in the Measurement.

Parameters

NameType
enableboolean

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:282


updateLineColor

updateLineColor(measurement, color): void

Update selected line color.

Parameters

NameTypeDescription
measurementMeasurementMeasurement to be updated.
colorColorColor of the measuring line.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:318


updateLineWidth

updateLineWidth(measurement, lineWidth): void

Update selected line width.

Parameters

NameTypeDescription
measurementMeasurementMeasurement to be updated.
lineWidthnumberWidth of the measuring line.

Returns

void

Defined in

packages/tools/src/Measurement/MeasurementTool.ts:302