Hide Sublayer in Layer List TOC

Jump to solution
10-13-2016 02:20 PM
Occasional Contributor II

I have a group layer from a dynamic map service. Right now I have it set to showsubLayers: true under the layerlist function. I want to exclude one of the sublayers from this. It's a mask that I want to always be on and not be visible in the list. Is this possible? 

0 Kudos
11 Replies
New Contributor III

Is there no better solution now, in 2018, perhaps using DynamicLayerInfos?

I'm trying this with no luck(attempting to remove layer 0 from the sublayers in the LayerList):

dynamicLayerInfos = [
new DynamicLayerInfo({ id: -1, subLayerIds: [1,2,3,4,5]}),
new DynamicLayerInfo({ id: 1 }),
new DynamicLayerInfo({ id: 2 }),
new DynamicLayerInfo({ id: 3 }),
new DynamicLayerInfo({ id: 4 }),
new DynamicLayerInfo({ id: 5 })

Having to resort to DOM manipulation is really kind of awful.

0 Kudos
Occasional Contributor II

I was trying to remove a graphic layer from the layer list in 4.8 and found this, in particular the comment from Kristian Ekenes. I slightly modified her code to my needs and it worked. Hopefully this is still relevant to you almost two months after your post.

//Hide graphic layer from layerList
        var graphicCurrentLayer = view.map.layers.flatten(function(item){
          return item.layers;
          return layer.title === "Graphics Layer";
        graphicCurrentLayer.listMode = "hide";
0 Kudos