Check for visibility on Group Layers?

2655
1
01-22-2014 05:23 AM
SteveClark
New Contributor III
I have a prototype viewer application in which there are a number of our map services added. In many of those map services, there are group layers (e.g., under Electric, we have Electric 12.5, Electric 34.5, etc.). What I can't figure out to do is to check for the visibility of those group layers. I can loop through the LayerCollection and check for DynamicMapServices or FeatureLayers but I can't find an object for group layers. I also know you can check the Rest endpoint to determine if a GroupLayer but not its visibility. Can someone tell me how to loop through what is in the table of contents and check for the visibility of group layers?
0 Kudos
1 Reply
SteveClark
New Contributor III
I got the answer at the Developer's Summit. The key was to cast the Layer to an ArcGISDynamicMapServiceLayer and there you can loop through the layers in the service, checking its visibility as well as getting the id:

LayerCollection layers = MapApplication.Current.Map.Layers;
foreach (Layer layer in layers)
{
     if (layer is ArcGISDynamicMapServiceLayer && layer.Visible)
     {
          var dyn = layer as ArcGISDynamicMapServiceLayer;

          foreach (var lyr in dyn.Layers)
          {
              if (dyn.GetLayerVisibility(lyr.ID))
              {
              }
          }
       }
}
0 Kudos