I'm trying to read domain values on a map, how to achieve this objective in arcgis javascript api? any help?
2 Answers
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(...);
map.addLayer(fl);
// when layer is ready
fl.on("load", ()=>{
for (var i = 0; i < fl.fields.length; i++) {
console.debug(fl.fields[i].domain);
}
});
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– Omar Taha2014-10-29 09:10:36 +00:00Commented Oct 29, 2014 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– janechii2014-10-29 17:49:00 +00:00Commented Oct 29, 2014 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– Omar Taha2014-10-30 08:13:20 +00:00Commented Oct 30, 2014 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– janechii2014-10-30 14:53:59 +00:00Commented Oct 30, 2014 at 14:53
at v3.12, try to use getDomain, fl.getDomain("fieldName") https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#getdomain