Select to view content in your preferred language

Attributes not included in HitTestResult

3560
5
Jump to solution
08-22-2019 12:34 PM
ShaneBuscher1
Regular Contributor

I'm performing a MapView.hitTest() against a feature layer in a webmap and running across inconsistencies with attributes being returned. I get a reference to the feature layer and set the outFields I want returned. However, sometimes the graphic that is 'hit' only returns the ObjectId. Other times it returns all attributes specified in outFields. 

view.on("click", function (event) {

  view.hitTest(event).then(function (response) {

    if (response.results.length) {

      var graphic = response.results.filter(function (result) {

        return result.graphic.layer === myLayer;

      })[0].graphic;
         

      // graphic.attributes only contains objectid
      // OR
      // graphic.attributes contains objectid, att1, att2, att3, etc...

     }

  });

});

What is the expected behavior? For instance, should you assume that you may only get back an ObjectId and not additional attributes set through FeatureLayer.outFields? Does hitTest ignore outFields? 

1 Solution

Accepted Solutions
ShaneBuscher1
Regular Contributor

After some deeper digging the answer lies in the Loadable pattern. Below is the solution where each feature layer in the web map has its outFields property set to 'all' with the splat. The 'load' function initializes the feature layers the way I need BEFORE adding to the mapView. The issue I had earlier dealt with a lazy-loaded component that was setting the outFields AFTER the webMap and mapView instances had loaded and rendered. 

let mapView = new MapView({ 
  container: 'mapEl',
});

let webMap = new WebMap(props);

webMap.load()
 .then(() => {
   webMap.layers
     .filter(layer => { return layer.type === 'feature' })
     .map(layer => {
       let featLayer = <esri.FeatureLayer>layer; 
       featLayer.outFields = ['*'];
       return featLayer; 
     });
 });
 
mapView.map = webMap;

View solution in original post

5 Replies
ShaneBuscher1
Regular Contributor

After some deeper digging the answer lies in the Loadable pattern. Below is the solution where each feature layer in the web map has its outFields property set to 'all' with the splat. The 'load' function initializes the feature layers the way I need BEFORE adding to the mapView. The issue I had earlier dealt with a lazy-loaded component that was setting the outFields AFTER the webMap and mapView instances had loaded and rendered. 

let mapView = new MapView({ 
  container: 'mapEl',
});

let webMap = new WebMap(props);

webMap.load()
 .then(() => {
   webMap.layers
     .filter(layer => { return layer.type === 'feature' })
     .map(layer => {
       let featLayer = <esri.FeatureLayer>layer; 
       featLayer.outFields = ['*'];
       return featLayer; 
     });
 });
 
mapView.map = webMap;
rogenjh
Occasional Contributor

😎  saved my butt late on a Friday!

TimDietz
Occasional Contributor

Thank you.  This worked for me.  And, I will add that it was some change that occurred from version 4.13 to 4.14.

LorenzoMara
New Contributor

Thanks, it really worked for me. Only ObjectID was shown to me

0 Kudos
hoogw
by
Regular Contributor

Thanks I had same problem. 

hitTest result only out put object id field, missing all other additional fields. 

My feature layer is created from client side array of graphic as source. 

 

If your feature layer created by using URL ( server-side source ) you don't have this kind of issue. 

OutFields by default will be "*", 

 

 

I solve my problem is by adding 

 

  outFields: ["*"],
or 
backgroundFeatureLayer.outFields = ["*"];
 
hp_31.png

 

 

 

 

0 Kudos