Select to view content in your preferred language

LayerList Widget - Turn on Sublayers

3148
4
Jump to solution
08-05-2013 05:08 PM
denverweston
New Contributor III
Is there a way to turn on and off all sublayers within a group within the Layer List Widget when the group is checked or unchecked?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor
In one version of mine i did add code to TOC.itemrender - in the createchildern function i think.

But in another version I setup a listener on the Show of a layer.  This might work best for you since you want to take action when a layer is checked (made visible).  You can set the listener for just the layers you want.

The code for this is
layerlist.addEventListener(FlexEvent.SHOW, mapLayerAddHandler2, false, 0, true); 
where mapLayerAddHandler2 is your function.

I wanted my procedure to run whenever any layer, except basemaps, were made visible. 

That code looks like this.

for (var j:int = 0; j < layerlist.length; j++)
{
      if (toc.basemapLayers.getItemIndex(layerlist.id) == -1)
    {
  layerlist.addEventListener(FlexEvent.SHOW, mapLayerAddHandler2, false, 0, true);
    }
}

Hope that helps.

View solution in original post

0 Kudos
4 Replies
denverweston
New Contributor III
This code turns on all the items at the parent level.  I was curious how to turn on all the layers at the child level?

var item:TocItem = TocItem(data);
   item.visible = _checkbox.selected;
   if(_checkbox.selected)
   {
    while(item.isTopLevel() == false)
    {
     item = item.parent;
     item.visible = true;
    }
   }
0 Kudos
DougBrowning
MVP Esteemed Contributor
I did something similar to expand children.  If you have one child then ask it for the parent.  Then ask the parent what other children it has. 

Like this  toc.dataProvider.source.children.layerInfo.name
0 Kudos
denverweston
New Contributor III
Did you do this in the TOC.itemrenderer?



I did something similar to expand children.  If you have one child then ask it for the parent.  Then ask the parent what other children it has. 

Like this  toc.dataProvider.source.children.layerInfo.name
0 Kudos
DougBrowning
MVP Esteemed Contributor
In one version of mine i did add code to TOC.itemrender - in the createchildern function i think.

But in another version I setup a listener on the Show of a layer.  This might work best for you since you want to take action when a layer is checked (made visible).  You can set the listener for just the layers you want.

The code for this is
layerlist.addEventListener(FlexEvent.SHOW, mapLayerAddHandler2, false, 0, true); 
where mapLayerAddHandler2 is your function.

I wanted my procedure to run whenever any layer, except basemaps, were made visible. 

That code looks like this.

for (var j:int = 0; j < layerlist.length; j++)
{
      if (toc.basemapLayers.getItemIndex(layerlist.id) == -1)
    {
  layerlist.addEventListener(FlexEvent.SHOW, mapLayerAddHandler2, false, 0, true);
    }
}

Hope that helps.
0 Kudos