Class: MeasurementTool
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:53
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
Constructor
new MeasurementTool(
viewer
,options?
):MeasurementTool
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:94
Parameters
viewer
Cognite3DViewer
<DataSourceType
>
options?
Returns
MeasurementTool
Overrides
Cognite3DViewerToolBase
.constructor
Accessors
isInMeasurementMode
Get Signature
get isInMeasurementMode():
boolean
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:57
Returns measurement mode state, is measurement mode started or ended.
Returns
boolean
Methods
addMeasurement()
addMeasurement(
startPoint
,endPoint
):Measurement
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:289
Adds a measurement directly. E.g. to restore a previous state programatically
Parameters
startPoint
Vector3
endPoint
Vector3
Returns
dispose()
dispose():
void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:397
Dispose Measurement Tool.
Returns
void
Overrides
Cognite3DViewerToolBase
.dispose
enterMeasurementMode()
enterMeasurementMode():
void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:238
Enter into point to point measurement mode.
Returns
void
exitMeasurementMode()
exitMeasurementMode():
void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:256
Exit measurement mode.
Returns
void
getAllMeasurements()
getAllMeasurements():
Measurement
[]
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:376
Get all measurements from Cognite3DViewer.
Returns
Array of Measurements containing Id, start point, end point & measured distance.
off()
Unsubscribe to the Measurement event
Param
MeasurementEvents
event
Param
Callback to measurements events
Call Signature
off(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:182
Parameters
event
"disposed"
callback
Returns
void
Example
measurementTool.off('disposed', onMeasurementDispose);
Overrides
Call Signature
off(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:190
Parameters
event
"added"
callback
Returns
void
Example
measurementTool.off('added', onMeasurementAdded);
Overrides
Cognite3DViewerToolBase.off
Call Signature
off(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:198
Parameters
event
"started"
callback
Returns
void
Example
measurementTool.off('started', onMeasurementStarted);
Overrides
Cognite3DViewerToolBase.off
Call Signature
off(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:206
Parameters
event
"ended"
callback
Returns
void
Example
measurementTool.off('ended', onMeasurementEnded);
Overrides
Cognite3DViewerToolBase.off
on()
Subscribe to the Measurement events
Param
MeasurementEvents
event
Param
Callback to measurements events
Call Signature
on(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:120
Triggered when the tool is disposed. Listeners should clean up any resources held and remove the reference to the tool.
Parameters
event
"disposed"
callback
Returns
void
Example
measurementTool.on('disposed', onMeasurementDispose);
Overrides
Cognite3DViewerToolBase.on
Call Signature
on(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:129
Triggered when a measurement is added into the Cognite3DViewer.
Parameters
event
"added"
callback
Returns
void
Example
measurementTool.on('added', onMeasurementAdded);
Overrides
Cognite3DViewerToolBase.on
Call Signature
on(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:138
Triggered when a measurement mode is started.
Parameters
event
"started"
callback
Returns
void
Example
measurementTool.on('started', onMeasurementStarted);
Overrides
Cognite3DViewerToolBase.on
Call Signature
on(
event
,callback
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:147
Triggered when measurement mode is ended.
Parameters
event
"ended"
callback
Returns
void
Example
measurementTool.on('ended', onMeasurementEnded);
Overrides
Cognite3DViewerToolBase.on
removeAllMeasurements()
removeAllMeasurements():
void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:309
Removes all measurements from the Cognite3DViewer.
Returns
void
removeMeasurement()
removeMeasurement(
measurement
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:274
Removes a measurement from the Cognite3DViewer.
Parameters
measurement
Measurement to be removed from Cognite3DViewer.
Returns
void
setLineOptions()
setLineOptions(
options
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:333
Sets Measurement line width, color and label units value for the next measurment.
Parameters
options
MeasurementOptions to set line width, color and callback for custom operation on measurement labels.
Returns
void
setMeasurementLabelsVisible()
setMeasurementLabelsVisible(
enable
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:322
Sets the visiblity of labels in the Measurement.
Parameters
enable
boolean
Returns
void
updateLineColor()
updateLineColor(
measurement
,color
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:361
Update selected line color.
Parameters
measurement
Measurement to be updated.
color
Color
Color of the measuring line.
Returns
void
updateLineWidth()
updateLineWidth(
measurement
,lineWidth
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:345
Update selected line width.
Parameters
measurement
Measurement to be updated.
lineWidth
number
Width of the measuring line.
Returns
void
visible()
visible(
enable
):void
Defined in: packages/tools/src/Measurement/MeasurementTool.ts:384
Hide/unhide all measurements
Parameters
enable
boolean
Returns
void