Get the outFields of a selected polygon in a feature Layer

534
2
04-16-2014 01:13 AM
ChristianDebono
New Contributor II
I want to get the outfields of a selected polygon. Rather than using the infoTemplate; I want to store the outFields in a variable. How can I do this please?

I have done a query on the feature layer, but the result given is all the polygons next to the polygons selected.

localCouncilsLayer.on("click", function (evt) {
 var query = new Query();
 var queryTask = new QueryTask("feautre layer");
 query.geometry = evt.graphic.geometry;
 query.returnGeometry = true;
 query.outSpatialReference = map.spatialReference;
 query.outFields = ["*"];
 queryTask.execute(query, function (results) {  
  var selectionAreaCity = results.features[0].attributes["NAME"]
 });
});
0 Kudos
2 Replies
RobertBurke
Esri Contributor
Hi Christian,

I am not sure this will help, but the this Sandbox sample has a line of code at line 40:

var featureAttributes = results.features.attributes;

It appears to get the attributes, for the current feature . Then on the page lists the attributes by name and value.

Here is the Sandbox sample:
http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=query_nomap

Since it is in a sandbox you can play around with the code to get different displays. For example alter the push on line 42:

resultItems.push("<b>" + attr + ":</b>  " );

and it displays the field names only, the values are omitted.

Another option is to look at the Rest api to see what is really returned in the feature set, to see the features, attributes, attribute values, and geometry.

http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Feature/02r3000000pr000000/

{
  "feature" :
  {
    "attributes" : {
      "objectid" : 1,
      "fdate" : 932428800000,
      "resolution" : 3,
      "gnis_id" : null,
      "gnis_name" : null,
      "lengthkm" : 0.024,
      "reachcode" : "11070101001016",
      "flowdir" : 1,
      "wbareacomid" : null,
      "ftype" : 558,
      "fcode" : 55800,
      "enabled" : 1
    }
    ,
    "geometry" :
    {
      "paths" :
      [
        [
          [-95.9899452281111, 38.1345878074741],
          [-95.9898896947778, 38.1344644074744],
          [-95.9899164947778, 38.1343866074744]
        ]
      ]
    }
  }
}

Also you could just hit the Rest endpoint of the Layer to see its fields

http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0

Fields:

    objectid ( type: esriFieldTypeOID , alias: OBJECTID )
    areaname ( type: esriFieldTypeString , alias: AREANAME , length: 50 )
    class ( type: esriFieldTypeString , alias: CLASS , length: 30 )
    st ( type: esriFieldTypeString , alias: ST , length: 2 )
    capital ( type: esriFieldTypeString , alias: CAPITAL , length: 1 )
    pop2000 ( type: esriFieldTypeInteger , alias: POP2000 )
    shape ( type: esriFieldTypeGeometry , alias: Shape )



I hope this helps.  If not may be add to your post and describe more about how you want to use the fields.
0 Kudos
JohnGravois
Frequent Contributor
hi guys,

in addition to the features themselves, the FeatureSet returned by the query also returns a 'fields' property.  you can find the array of outFields you're looking for there too.

[ATTACH=CONFIG]33152[/ATTACH]