Select to view content in your preferred language

Getting Attributes from feature layer into a Variable?

565
1
09-19-2013 04:37 AM
DamienButler1
New Contributor
I have a JSON which comprises of lat long coordinates,  hash id values, file name etc etc. I created a feature layer from this json via   feature collection

{ LayerDef: {}, FeatureSet:};

I display this feature layer as a set of points on the map

var pointdata = new esri.layers.FeatureLayer(featureCollection, {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND});

What I want to do is, when I click one of these points I want to be able to grab the hash_id from the attributes and dump it into a js var for further processing, Sounds simple but I have been racking my brain on this for some time. Any input at all would be really appreciated! If you need any further info to help me solve this problem just let me know.
0 Kudos
1 Reply
JasonZou
Regular Contributor
If the feature layer, pointdata, is created correctly, the below code sample should meet your need.

pointdata.on("click", function(evt) {
    var hashId = evt.graphic.attributes["hash_id"];
});


In addition, based on the ESRI API description, the structure of the feature collection should be
{ layerDefinition: {
          geometryType": "esriGeometryPoint",
          objectIdField": "ObjectID",
          drawingInfo": {
          },
          "fields": [{
            "name": "ObjectID",
            "alias": "ObjectID",
            "type": "esriFieldTypeOID"
          }, ...]
   }, 
   featureSet: {
     features: [],
     geometryType: "esriGeometryPoint"
   }
};


Here is a sample of creating a feature layer from a feature collection.
0 Kudos