Select to view content in your preferred language

Getting Field Values of Specific Layer

486
1
06-27-2014 11:43 AM
LisCollins
Deactivated User
I've been trying to read through the ArcGIS JavaScript API but can't find what I want.

I have a web map on my page that is based on my my map stored on ArcGIS online.
I want to create an if/else statement that does different things based on the value of a field in the layer. But I'm having a hard time accessing the field of the layer I want. Here is part of the JavaScript in my HTML code.


    var exLayer = actualmap.getLayer(actualmap.layerIds[6]).layerInfos[0];
     console.log(exLayer);


With the code above, I am able to access the layer I want in my web map. The web service I want is number 6 on the AGOL map, and the layer I want on this web service is number 0.

I'm trying to access the field in layer 0 called "TID", and I want to get the rows with "TID" > 0 and rows "TID" = 0 for my if/else statement. I tried the below to access field names, but it didn't work. It just gave me the layer name.

    var test1 = Field(exLayer).name;
     console.log(test1);


Any suggestions?
0 Kudos
1 Reply
OwenEarley
Frequent Contributor
Your code accesses the map layer. To access field values you need to query features - not the layer properties.

The first thing you will need to do is query the layer for the features that you want, check out:

Set the where clause on the Query to select your features ("TID" > 0 or "TID" = 0) then process your features in the response handling function.
0 Kudos