Coded Domains in InfoTemplate

3311
2
09-01-2016 11:24 AM

Coded Domains in InfoTemplate

When working on a recent project, I ran across the need to use Coded Domain Values in an InfoTemplate. This is my solution, derived fromSearch Widget and InfoTemplate, Domains, Subtypes

varsubTypeVal;getSubtypeDomain=function(fieldVal,fieldName){if(featureLayer.typeIdField!=null){//console.log("Have Subtypes");if(fieldName==featureLayer.typeIdField){array.forEach(featureLayer.types,lang.hitch(this,function(lsf){if(fieldVal==lsf.id){fieldVal=lsf.name;subTypeVal=lsf.id;}}));}else{array.forEach(featureLayer.types,lang.hitch(this,function(lsf){if(lsf.id==subTypeVal){array.forEach(lsf.domains[fieldName].codedValues,lang.hitch(this,function(domain){if(fieldVal==domain.code){fieldVal=domain.name;}}));}}));}}else{//console.log("No Subtypes");subTypeVal=null;array.forEach(featureLayer.fields,lang.hitch(this,function(ldf){if(ldf.name==fieldName){if(ldf.domain){array.forEach(ldf.domain.codedValues,lang.hitch(this,function(domain){if(fieldVal==domain.code){fieldVal=domain.name;}}));}}}));}returnfieldVal;};varinfoContent="Attribute: ${Attribute:getSubtypeDomain}";varinfoTemplate=newInfoTemplate("Title",infoContent);varfeatureLayer=newFeatureLayer("//you/services/url",{infoTemplate:infoTemplate,outFields:["*"]});
Comments

Would this code work if I use it on map image layer instead of feature layer?

To be honest, I'm not sure. Sorry I'm not much help.

Version history
Last update:
‎12-12-202103:43 AM
Updated by: