Hit testing identifies features displayed at a location in a 3D scene. This sample passes a ScreenRect to hitTest() to identify all rendered points within that rectangle. A ScreenRect is a plain object that describes an area of the screen in pixels. Its x and y properties locate the rectangle’s upper-left corner relative to the scene, while width and height define its size.

To demonstrate this workflow, the scene displays a PointCloudLayer. Click Draw screen rectangle, then drag over an area of the scene. Rendered points inside the drawn rectangle populate a chart that summarizes the classifications defined by the layer’s renderer. Click Clear to remove the selection and chart results.

The following code passes the ScreenRect to the scene component’s hitTest() method and uses HitTestOptions3D. The include property limits results to the point cloud layer, while excludeLabels excludes labels from the hit test.

const hitTestResponse = await viewElement.hitTest(screenRectangle, {
include: pointCloudLayer,
excludeLabels: true,
});

The point results returned by hitTest() are grouped by their CLASS_CODE attribute and used to populate an arcgis-chart pie chart. The chart uses the classification labels and colors defined by the layer’s renderer.

The same screen-space hit-testing approach supports point, rectangle, and lasso selection tools in the Sketch and Editor components in 3D.

3D5.2PointCloudLayerhitTestHitTestOptions3DscreenRectanglearcgisViewDragarcgis-chartpie-chartviewOnReadyarcgis-compassarcgis-navigation-togglearcgis-scenearcgis-zoommap-componentscalcite-panelcalcite-shellcalcite-components