After setting DynamicLayerInfos layer visibilities are not obeyed properly

Discussion created by rcoodey on Jun 5, 2014
Latest reply on Jun 11, 2014 by rcoodey
In the layer's Initialized event we are setting the DynamicLayerInfos and then setting the min/maxScale. This is to get around the issue that dynamic layers do not allow you to extend outside the bounds of the published scale (http://forums.arcgis.com/threads/100223-DynamicLayerInfos-Changing-MinScale-Not-Working). So we have special services published with no scale and we are trying to initialize the default scales we want.

This has caused a few additional issues though. When DynamicLayerInfos is set, layer visibilities are no longer obeyed. Though the TOC does not show them checked, the layers render (might just be the group layers, cant tell easily). Toggling one item in the TOC fixes the problem though and then things render fine.

To get around this issue, I thought we could just set the VisibleLayers since it starts off null. Tried this one of two ways with issues:
1) Added the IDs for all the layers with layerInfo.DefaultVisibility == true. But this does not work where there are group layers that are disabled and the sub layers enabled. The parent group layer automatically gets checked even though its ID is not in the list.
2) Added the IDs for just the layers that are truly visible, so not the layers under a disabled group. But this of course does not check those sub layers in the TOC so when the outer group is enabled, the sub layers have to be enabled too.

Any ideas to get around this issue and enable the default visible layers properly?

Thanks a lot!