Skip To ContentArcGIS for DevelopersSign In Dashboard
Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample shows how to use hitTest to find all objects under the mouse pointer for each click-interaction. Starting at version 4.11, the hitTest in SceneView returns an array of all objects that intersect the mouse location from these layers:

For each object, the HitTestResult contains the graphic, distance from the camera to the object, and the corresponding map point. Information about where the ground surface (if at all) was hit is also provided.

To initiate the hitTest:

view.hitTest(event)
  view.on("immediate-click", function(event) {
  .then(function(hitTestResult) {
    console.log(hitTestResult)
  })
  .catch(function(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
  }
}

Sample search results

TitleSample
Loading...