Class: MeasurementTool
Enables 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.
Examples
const measurementTool = new MeasurementTool(viewer);
measurementTool.enterMeasurementMode();
// ...
measurementTool.exitMeasurementMode();
// detach the tool from the viewer
measurementTool.dispose();
const measurementTool = new MeasurementTool(viewer, {distanceToLabelCallback: (distanceInMeters) => {
// 1 meters = 3.281 feet
const distancesInFeet = distanceInMeters * 3.281;
return { distanceInMeters: distancesInFeet, units: 'ft'};
}});
measurementTool.enterMeasurementMode();
Extends
Constructors
new MeasurementTool()
new MeasurementTool(
viewer
,options
?):MeasurementTool
Parameters
• viewer: Cognite3DViewer
• options?: MeasurementOptions
Returns
Overrides
Cognite3DViewerToolBase
. constructor
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:93
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:56
Methods
addMeasurement()
addMeasurement(
startPoint
,endPoint
):Measurement
Adds a measurement directly. E.g. to restore a previous state programatically
Parameters
• startPoint: Vector3
• endPoint: Vector3
Returns
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:288
dispose()
dispose():
void
Dispose Measurement Tool.
Returns
void
Overrides
Cognite3DViewerToolBase
. dispose
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:396
enterMeasurementMode()
enterMeasurementMode():
void
Enter into point to point measurement mode.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:237
exitMeasurementMode()
exitMeasurementMode():
void
Exit measurement mode.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:255
getAllMeasurements()
getAllMeasurements():
Measurement
[]
Get all measurements from Cognite3DViewer.
Returns
Array of Measurements containing Id, start point, end point & measured distance.
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:375
off()
Unsubscribe to the Measurement event
Param
MeasurementEvents
event
Param
Callback to measurements events
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "disposed"
• callback: DisposedDelegate
Returns
void
Overrides
Example
measurementTool.off('disposed', onMeasurementDispose);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:181
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "added"
• callback: MeasurementAddedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.off
Example
measurementTool.off('added', onMeasurementAdded);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:189
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "started"
• callback: MeasurementStartedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.off
Example
measurementTool.off('started', onMeasurementStarted);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:197
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "ended"
• callback: MeasurementEndedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.off
Example
measurementTool.off('ended', onMeasurementEnded);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:205
on()
Subscribe to the Measurement events
Param
MeasurementEvents
event
Param
Callback to measurements events
on(event, callback)
on(
event
,callback
):void
Triggered when the tool is disposed. Listeners should clean up any resources held and remove the reference to the tool.
Parameters
• event: "disposed"
• callback: DisposedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.on
Example
measurementTool.on('disposed', onMeasurementDispose);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:119
on(event, callback)
on(
event
,callback
):void
Triggered when a measurement is added into the Cognite3DViewer.
Parameters
• event: "added"
• callback: MeasurementAddedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.on
Example
measurementTool.on('added', onMeasurementAdded);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:128
on(event, callback)
on(
event
,callback
):void
Triggered when a measurement mode is started.
Parameters
• event: "started"
• callback: MeasurementStartedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.on
Example
measurementTool.on('started', onMeasurementStarted);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:137
on(event, callback)
on(
event
,callback
):void
Triggered when measurement mode is ended.
Parameters
• event: "ended"
• callback: MeasurementEndedDelegate
Returns
void
Overrides
Cognite3DViewerToolBase.on
Example
measurementTool.on('ended', onMeasurementEnded);
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:146
removeAllMeasurements()
removeAllMeasurements():
void
Removes all measurements from the Cognite3DViewer.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:308
removeMeasurement()
removeMeasurement(
measurement
):void
Removes a measurement from the Cognite3DViewer.
Parameters
• measurement: Measurement
Measurement to be removed from Cognite3DViewer.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:273
setLineOptions()
setLineOptions(
options
):void
Sets Measurement line width, color and label units value for the next measurment.