Dynamic values for labelExpression (MapImageLayer)

348
0
08-02-2021 07:19 AM
Andy_Morgan
New Contributor III

My application allows for multiple labels (multi-line) for a single sublayer in a MapImageLayer. The only problem is that I need to set the labelClass "useCodedValues" property to false for only certain fields, not an all-or-nothing (domain code vs description) for all fields in the labelClass. It needs to be false (show codes rather than descriptions) for a field named "PipeMaterial" in two different sublayers. Domain description values need to be showing for all other label fields.

So my thought was to either:

1) Try to apply multiple label classes to the sublayer if PipeMaterial field is to be labeled, but this doesn't seem possible with a multi-line label setup for MapImageLayers. Maybe I'm wrong?

2) Apply a function to dynamically produce domain code values for those few fields that need to use the code rather than description. Let's assume I've pulled all the codes from a REST query and have them available. (PipeMaterial codes such as "AC" = "Asbestos Cement", "CAST" = "Cast Iron", etc...)

So is the #2 option possible? Let's take this ESRI example below. How could I apply a function to get the actual value of the COUNTY_NAME field and replace it on-the-fly while labeling?

 

// For Spokane County, WA, label will display: "Spokane County, Washington"
labelClass.labelExpression = '[COUNTY_NAME] CONCAT " County, " CONCAT [STATE_NAME]';

 

My goal using pseudo code:

...if [COUNTY_NAME]  value is "Spokane County" then return "SPOK" for the actual label output value

Tags (1)
0 Kudos
0 Replies