Query a SceneLayer's linked FeatureLayer

This device does not support 3D.

View the system requirements for more information.

This sample shows how to query a FeatureLayer to display its attributes for a linked SceneLayer. This can be useful when a field in a SceneLayer does not support PopupTemplate or query capabilities.

In this example, we published a Scene Layer which doesn't support query capabilities. To still be able to query it, we also publish a Feature Service of building footprints with the same ObjectIDs as in the Scene Service plus additional attributes (e.g number of floors, building name, year built, etc.). When the user clicks a feature, a query executes against the FeatureLayer for the given SceneLayer ObjectID and passes the results to the popup to display the attributes of interest.

Notice that since the FeatureLayer is not added to the map, you must call load() on the FeatureLayer to access its resources.

featureLayer.load().then(function(){
  // extecute the query on the feature layer
  // and display results in the view's popup
});

To get the FeatureLayer's attributes, set up a click event handler on the view and pass the screen x, y coordinates to the view's hitTest() method. This will return all features, including their attributes, intersecting the view click.

// capture click events on the view
view.on("click", function(event) {

 // get the returned screen x, y coordinates and use it
 // with hitTest to find if any graphics were clicked

 view.hitTest(event).then(function(response) {
    // if a graphic is clicked, the view's hitTest() method
    // returns a graphic in the results array
    var result = response.results[0];
    if (result && result.graphic) {
      return result.graphic;
    }
  }).then( ... );
});

Other helpful resources

Sample search results

TitleSample

There were no match results from your search criteria.