ArcGIS Javascript API how do I access the attributes for a feature that is selected (client-side) and do a calculation on the attribute table values for that feature?

441
1
12-18-2019 08:30 AM
EdFratto
New Contributor

LINK TO MY CODE: https://gist.github.com/saraneh/e2d1b1e8ebe049f947148f92d0b64f18

This program is a map which shows two layers: a flood layer and a county layer.

You can select which county you are interested in with the drop down, and when you select it it returns the geometry for that feature.There are also 3 other dropdowns (numeric arrays).

What I can't figure out is how to also access the attributes for the county selected. I want to be able to (depending on the county selected) access the values for the fields in the attribute table and then do a calculation with those values

0 Kudos
1 Reply
AnneFitz
Esri Contributor

Hi Ed, 

You can access the attributes of a feature in a similar way to how you access the geometry of the feature after querying for it using queryFeatures. From your code: 

return wellsLayer.queryFeatures(wellsQuery).then(function(response) {
   wellsGeometries = response.features.map(function(feature) {
      console.log(feature.attributes);
      return feature.geometry;
   });
   return wellsGeometries;
});

Inside the response.features.map... you can access the attributes of the feature using the feature.attributes property. Hope this helps!

Thanks,

Anne

0 Kudos