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
<DataSourceType
>
• options?: MeasurementOptions
Returns
Overrides
Cognite3DViewerToolBase
.constructor
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:94
Accessors
isInMeasurementMode
Get Signature
get isInMeasurementMode():
boolean
Returns measurement mode state, is measurement mode started or ended.
Returns
boolean
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:57
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:289
dispose()
dispose():
void
Dispose Measurement Tool.
Returns
void
Overrides
Cognite3DViewerToolBase
.dispose
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:397
enterMeasurementMode()
enterMeasurementMode():
void
Enter into point to point measurement mode.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:238
exitMeasurementMode()
exitMeasurementMode():
void
Exit measurement mode.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:256
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:376
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
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.off('disposed', onMeasurementDispose);
Overrides
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:182
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "added"
• callback: MeasurementAddedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.off('added', onMeasurementAdded);
Overrides
Cognite3DViewerToolBase.off
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:190
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "started"
• callback: MeasurementStartedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.off('started', onMeasurementStarted);
Overrides
Cognite3DViewerToolBase.off
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:198
off(event, callback)
off(
event
,callback
):void
Parameters
• event: "ended"
• callback: MeasurementEndedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.off('ended', onMeasurementEnded);
Overrides
Cognite3DViewerToolBase.off
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:206
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
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.on('disposed', onMeasurementDispose);
Overrides
Cognite3DViewerToolBase.on
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:120
on(event, callback)
on(
event
,callback
):void
Triggered when a measurement is added into the Cognite3DViewer.
Parameters
• event: "added"
• callback: MeasurementAddedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.on('added', onMeasurementAdded);
Overrides
Cognite3DViewerToolBase.on
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:129
on(event, callback)
on(
event
,callback
):void
Triggered when a measurement mode is started.
Parameters
• event: "started"
• callback: MeasurementStartedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.on('started', onMeasurementStarted);
Overrides
Cognite3DViewerToolBase.on
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:138
on(event, callback)
on(
event
,callback
):void
Triggered when measurement mode is ended.
Parameters
• event: "ended"
• callback: MeasurementEndedDelegate
Returns
void
Param
MeasurementEvents
event
Param
Callback to measurements events
Example
measurementTool.on('ended', onMeasurementEnded);
Overrides
Cognite3DViewerToolBase.on
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:147
removeAllMeasurements()
removeAllMeasurements():
void
Removes all measurements from the Cognite3DViewer.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:309
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:274
setLineOptions()
setLineOptions(
options
):void
Sets Measurement line width, color and label units value for the next measurment.
Parameters
• options: MeasurementOptions
MeasurementOptions to set line width, color and callback for custom operation on measurement labels.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:333
setMeasurementLabelsVisible()
setMeasurementLabelsVisible(
enable
):void
Sets the visiblity of labels in the Measurement.
Parameters
• enable: boolean
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:322
updateLineColor()
updateLineColor(
measurement
,color
):void
Update selected line color.
Parameters
• measurement: Measurement
Measurement to be updated.
• color: Color
Color of the measuring line.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:361
updateLineWidth()
updateLineWidth(
measurement
,lineWidth
):void
Update selected line width.
Parameters
• measurement: Measurement
Measurement to be updated.
• lineWidth: number
Width of the measuring line.
Returns
void
Defined in
packages/tools/src/Measurement/MeasurementTool.ts:345
visible()
visible(
enable
):void
Hide/unhide all measurements
Parameters
• enable: boolean
Returns
void