I'm trying to read domain values on a map, how to achieve this objective in arcgis javascript api? any help?


You can get this from the FeatureLayer class. There is an attribute called fields, which is an array of Field objects. The Field class has domain attribute.

The following will output the domains in the console (if any):

var map = new Map(...);
var fl = new FeatureLayer(...);

// when layer is ready
fl.on("load", ()=>{
   for (var i = 0; i < fl.fields.length; i++) {

Good luck!

  • Thanks janechii, I tried your code before, and it keeps telling me f1.fields is undefined? what might be the problem? I'm new to arcgis api :( this is my code: var f1= new esri.layers.FeatureLayer("sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/…", { mode: FeatureLayer.MODE_ONDEMAND, outFields:["*"] }); for (var i = 0; i < f1.fields.length; i++) { alert(f1.fields[i].domain); } – Omar Taha Oct 29 '14 at 9:10
  • Cool! what was the issue? And a little tip, you should try to use the AMD style as much as possible. Not sure when they'll phase out the old style. – janechii Oct 29 '14 at 17:49
  • I'm not sure what was the issue, but what I did was that I moved the line alert(f1.fields[i].domain); after I added the layer to the map, after this line map.addlayers[{f1}]; Ok, I'll take your advice and start using the AMD style, Thnks a lot. – Omar Taha Oct 30 '14 at 8:13
  • You're right! I forgot to add the layer to the map. Also, it is asynchronously loading the layer's details, so you have to make sure that the layer info is ready before you find its domains. – janechii Oct 30 '14 at 14:53

at v3.12, try to use getDomain, fl.getDomain("fieldName") https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#getdomain

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.