Coded Domains in InfoTemplate

Document created by randybonds on Sep 1, 2016Last modified by randybonds on Sep 1, 2016
Version 2Show Document
  • View in full screen mode

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: ["*"]
        });

Attachments

    Outcomes