Use viewElement.hitTest() to get all graphics or features under the pointer at the moment of interaction. The method returns an ordered array (nearest first) of intersections from these sources: GraphicsLayer, FeatureLayer, SceneLayer, BuildingSceneLayer, PointCloudLayer, CSVLayer, StreamLayer, GeoJSONLayer, viewElement.graphics

What you get back (HitTestResult)

Each hit returns:

  • graphic – the matched graphic or feature (with attributes, if present)
  • mapPoint – the 3D point on the object
  • distance – camera-to-hit distance (in view units)

If the ground is intersected, ground.mapPoint and ground.distance are also provided.

To initiate the hitTest:

viewElement.addEventListener("arcgisViewImmediateClick", (event) => {
viewElement.hitTest(event.detail)
.then((hitTestResult) => {
console.log(hitTestResult)
})
.catch((error) => {
console.error(error);
});
};

Example of a HitTestResult:

{
"screenPoint": {
"x": 1110.666748046875,
"y": 704.6666870117188
},
"results": [
{
"graphic": {
"geometry": null,
"symbol": null,
"attributes": {
"OBJECTID": 23259,
"CNSTRCT_YR": 1950
}
},
"mapPoint": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"x": -8237578.175357298,
"y": 4972677.452421391,
"z": 29.343255893327296
},
"distance": 6033.217135564263
}
],
"ground": {
"mapPoint": {
"spatialReference": {
"latestWkid": 3857,
"wkid": 102100
},
"x": -8237575.894557083,
"y": 4972679.5403643185,
"z": 6.689946555570758
},
"distance": 6055.99127013477
}
}