Coded Domains in InfoTemplate

3535
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 from Search Widget and InfoTemplate, Domains, Subtypes 

var subTypeVal;  
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;  
                      }  
                  }));  
              }  
          }  
        
      }));  
  }  
  return fieldVal;  
};

var infoContent = "<strong>Attribute</strong>: ${Attribute:getSubtypeDomain}";
var infoTemplate = new InfoTemplate("Title", infoContent);

var featureLayer = new FeatureLayer("//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-2021 03:43 AM
Updated by: