LabelLayer class: how to display domain description, not code value?

2832
1
04-23-2015 01:03 PM
AndyMorgan1
New Contributor III

My goal:  Allow users to dynamically add labels.  They would select a field to be labeled along with their preferred font size and color.

LabelLayer appears to be the closest solution.  My code below is working without error, however it shows the domain Coded Values instead of the readable Description values.   Is there any workaround to get the description text whenever the field is associated with a domain?

Here is an example of converting a domain value's code to description  Using Domain values in your App

But this doesn't help because LabelLayer's ".addFeatureLayer" method doesn't appear to allow anything more than the field name itself.

  function addLabelLayer() {

        var labelField = "SOURCE";
        var colorLabel = new Color("#0000FF");
        var labelTextSymbol = new TextSymbol().setColor(colorLabel);
        labelTextSymbol.font.setSize("12pt");
        labelTextSymbol.font.setFamily("arial");
        var labelRenderer = new SimpleRenderer(labelTextSymbol);

        var wlFeatLayer = new FeatureLayer(
            mapServerURL + "/15",
            {
                id: "wlFeatureLayer",
                outFields: ["*"]
            });

        
        wlFeatLayer.on('load', function () {

            var labels = new LabelLayer({ id: "wlLabels" });
            labels.addFeatureLayer(wlFeatLayer, labelRenderer, "${" + labelField + "}");
            app.map.addLayer(labels);
            labels.visible = true;

        });

        app.map.addLayer(wlFeatLayer);

    }
0 Kudos
1 Reply
AndyMorgan1
New Contributor III

Apparently all I needed to do was remove the "$" in the text expression "${" + labelField + "}".  It now shows the Description value if the field is associated with a domain, or else the value if it is plain text, number, date, etc.

labels.addFeatureLayer(wlFeatLayer, labelRenderer, "{" + labelField + "}");

You might say removing the dollar sign was right on the money!  hah