After setting DynamicLayerInfos layer visibilities are not obeyed properly

1566
3
06-05-2014 07:43 PM
Labels (1)
RyanCoodey
Occasional Contributor III
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!
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
At first glance, you need to use SetLayerVisibility which reflects the sublayer status in the legend.
See also the GetLayerVisibility documentation.
0 Kudos
RyanCoodey
Occasional Contributor III
Thanks a lot for the info Dominique, but maybe I am still doing something wrong. Tried setting the layer visibility using these methods a few ways:

foreach (LayerInfo layerInfo in Layers)
     SetLayerVisibility(layerInfo.ID, layerInfo.DefaultVisibility);


foreach (LayerInfo layerInfo in Layers)
     SetLayerVisibility(layerInfo.ID, GetLayerVisibility(layerInfo.ID));


But I still have the problem mentioned in number 1, and the disabled group layers are rendering. Am I doing something wrong? Maybe you could elaborate more on how I should be using those methods?

Thanks again!
0 Kudos
RyanCoodey
Occasional Contributor III
Should have waited to reply earlier... got it working now.

The catch is that VisibleLayers cannot be null before using SetLayerVisibility. If it is null, SetLayerVisibility leaves it null and the problem still exists, but if it is initialized to anything, then the SetLayerVisibility loop resets it properly without the issue.

So I just had to do:

VisibleLayers = new[] { 0 }; //Must initialize to anything but null, will be reset below.
foreach (LayerInfo layerInfo in Layers)
     SetLayerVisibility(layerInfo.ID, layerInfo.DefaultVisibility);


Thanks much Dominique for leading us to a fix!
0 Kudos