Select to view content in your preferred language

LabelLayer name inside LayerList widget

3815
3
Jump to solution
11-12-2015 11:51 AM
SteveCole
Honored Contributor

I'm using the LayerList for a small project. It basically meets my needs despite its limited functionality. Anyways, I added a labelLayer to my project to label the features of another feature layer in the project and I wanted to have the ability to turn the labels on/off. I added the labelLayer as one of the layers to the LayerList widget but I cannot figure out where it's getting the label text for the checkbox in the LayerList.

My simple code for the labelLayer:

        var renderer = new SimpleRenderer(symbol);  
        var labelLayer = new LabelLayer("label1", {
            id: "Milepost Labels",
            mode: "dynamic",
            visible:true
        });  
        labelLayer.addFeatureLayer(fsMpLayer, renderer, "M.P. {milepost}", { pointPriorities: "AboveRight" });
        labelLayer.setAlgorithmType("DYNAMIC");
        labelLayer.setMinScale(24000);

and for the LayerList...

        layerWidget = new LayerList({
           map: app.map,
           subLayers: false,
           layers: [
                // {layer: ortho2013Layer,
                // visibility: false
                // },
                {layer: geolMapLayer,
                subLayers: false,
                visbility: false
                },
                {layer:memoSegmentLayer,
                visibility:false
                },
                {layer: soilsLayer,
                visibility:false
                },
                {layer: streamLayer,
                visibility:false
                },
                {layer:roadsLayer,
                visbility:true
                },
                {layer:mlhLayer,
                visibility:true
                },
                {layer:fsMpLayer,
                visibility:true
                },
                {layer:streamCrossingLayer,
                visibility:true
                },
                {layer:maintConcernLayer,
                visibility:true
                },
                {layer:labelLayer,
                visibility:true
                }
           ]},"layerList");
        layerWidget.startup();

And inside the app, it just states "labels" as the text for the labelLayer checkbox:

labelLayer_in_LayerList.jpg

Is there anyway to change that??

Steve

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Steve,

   Have you tried to set the id for the layer object:

{layer:labelLayer, 

  visibility:true,

  id: "Milepost Labels"

}

View solution in original post

3 Replies
SteveCole
Honored Contributor

This is an extremely hack-ish way to do it but this will work:

        window.onload = function() {
            document.getElementById('layerList_checkbox_9').labels[0].innerText = "Milepost Labels";
        }

First, you need to examine the HTML to find the ID of the checkbox in the layerList widget. Once you know that, you can modify it but it has to be done AFTER the page loads and all scripts run. That's why I have it in a window.onload event.

Reference 1

Reference 2

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Steve,

   Have you tried to set the id for the layer object:

{layer:labelLayer, 

  visibility:true,

  id: "Milepost Labels"

}

SteveCole
Honored Contributor

Well I'll be damned. That works too. Ugh. ESRI will never have enough (clear) documentation.

Thanks, Robert!

0 Kudos