Change Layer Label to a field that holds subtype code

505
2
08-24-2022 01:21 AM
ZaidOdeh
New Contributor II

I have a map with feature layers, I am trying to set the label for the layer using a field ["ASSETGROUP"], its real value comes from the the Feature Layer TYPES property. This property holds subtypes defined in the feature service which are exposed by ArcGIS REST API. Usually I get the actual value by processing the subtypes to get the actual value using the code stored in the feature layer field.
Is it possible to do this when setting the label to feature layer ? 

I tried to set the label expression property to the field name, and set the useCodedValues property to true, but this only works on regular domain fields.
I am still getting the Code when I use the field that require some processing from the Types property on the feature layer. 

 

  if (isDomain) {
        expr = "DomainName($feature, '" + displayFieldName + "')";
      } else {
        expr = `$feature["${displayFieldName}"]`;
      }

      const statesLabelClass = new LabelClass({
        useCodedValues: true,
        labelExpressionInfo: { useCodedValues: true,
                                               expression: expr },
        symbol: {
          type: "text", // autocasts as new TextSymbol()
          color: "black",
          haloSize: 1,
          haloColor: "white",
        },
      });
      props.layer.labelingInfo = [statesLabelClass];

EDIT
So I am using ARCADE to get domain values now using the function DomainName($feature,FIELD_NAME) to get the fields that hold domain values, I tried using subtypes($feature) to get the  the value but I always get empty string. I used Arcpro to see what it does when I choose the ASSETGROUP as the label, it automatically write DomainName($feature,'ASSETGROUP') and it shows the correct label value, when I tried it in the Javascript Api code, I did not get the value, but got the code instead. Any ideas ?

 

0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor

Hi @ZaidOdeh, can you share a codepen of this? Or access to the service you are trying to label? You can send it as a private message if you don't want to share here.

0 Kudos
ZaidOdeh
New Contributor II

I just sent you a private message of the feature service