This sample demonstrates how to measure the volumes of ground surface features both programmatically and interactively, using a real-world–style example: planning a track and field facility. You will learn how to create a volume measurement analysis, configure it for cut-and-fill and stockpile calculations, draw measurement areas interactively, and retrieve results for display or further processing.
To configure the analysis, create a VolumeMeasurementAnalysis instance and choose the measurement method by setting the measureType property. When using the "cut-fill" measure type, you can further customize the analysis with VolumeMeasurementCutFillOptions. If you already have a polygon defining the measurement area, set it using the geometry property. If not, leave it undefined and refer to the later code snippet that demonstrates how to create the polygon interactively. Finally, add the analysis to the scene.
// Configure the analysis
const volumeMeasurementAnalysis = new VolumeMeasurementAnalysis({
measureType: "cut-fill", // the default value
cutFillOptions: {
targetElevation: 659 // defaults to meters
},
});
// Add the analysis to the scene
viewElement.analyses.add(volumeMeasurementAnalysis);
To obtain the measurement results, retrieve the VolumeMeasurementAnalysisView3D using the Scene component's whenAnalysisView.
// Retrieve measured results from analysis view once available
const analysisView = await viewElement.whenAnalysisView(volumeMeasurementAnalysis);
await reactiveUtils.whenOnce(() => analysisView.result);
const result = analysisView.result;
To draw an area interactively, use the VolumeMeasurementAnalysisView3D.place() method after retrieving the VolumeMeasurementAnalysisView3D.
// Cancel the placement operation at some later point
// by calling abortController.abort()
const abortController = new AbortController();
try {
await analysisView.place({ signal: abortController.signal });
} catch (error) {
if (error.name === "AbortError") {
console.log("Placement operation was cancelled.");
}
}
Finally, VolumeMeasurementAnalysis allows you to fully customize both the input units and display units to suit your specific use case.
const volumeMeasurementAnalysis = new VolumeMeasurementAnalysis({
// Units to display in the UI and in the results
displayUnits: {
volume: "square-meters",
elevation: "meters"
},
// Units for input values
inputUnits: {
elevation: "feet"
}
});