Query client-side 3D extents

This sample shows how to query a mesh SceneLayerView to get more information about features visible in the view. The SceneLayerView query methods only execute queries against features that are visible in the view at the moment of the query.

The use case for this sample is to display more information about a building and to zoom to it when the user clicks on that building.

We can get the objectid of the feature the user clicked using the hitTest() method of the view. We use the result to create a query object:

1
2
3
4
5
6
7
8
9
10
11
view.hitTest(event).then((response) => {

  // check if a graphic is returned from the hitTest
  if (response.results[0].graphic) {

    // create query
    const query = new Query();
    // the query will return results only for the feature with the graphic's objectid
    query.objectIds = [response.results[0].graphic.attributes.OBJECTID];
    // the query should return all attributes
    query.outFields = ["*"];

The query object is then passed to queryExtent() method, which returns the 3D extent of the feature, and to the queryFeatures() method, which returns the feature with all the attributes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sceneLayerView.queryExtent(query).then((result) => {
  view.goTo(
    {
      target: result.extent,
      tilt: 60
    },
    {
      duration: 1000,
      easing: "out-expo"
    }
  );
});

sceneLayerView.queryFeatures(query).then((result) => {
  showInfo(result.features[0].attributes);
});

Additional scene layer query samples

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close