I'm trying to change the visibility of one of the sublayers in a dynamic map service layer. This is basically set up as a way to override the DefaultVisibility for specific sublayers. The sublayer in question is a couple of layers down in the hierarchy. Even though it's not in the agsDynamicMapServiceLayer.VisibleLayers list, it's still being drawn.
Using the 2.1.0.446 build of the ArcGIS Silverlight API
Dynamic Map Service hierarchy looks something like this:
Layer Name/Hierarchy
[0] A
[1] A.1
[2] A.2
[3] A.3
[4] B
[5] B.1
[6] B.1.a
[7] B.2
[8] B.2.a
Want to make sublayer ???B.1.a??? hidden in initial display (DefaultVisibility is true for that layer)
All of the following work is done in the Initialized event handler for the ArcGISDynamicMapServiceLayer.
agsDynamicMapServiceLayer.VisibleLayers is null initially
Build list of id???s that want to make visible:
List<int> visibleLayers: 0,1,2,3,4,7,8
Set into VisibleLayers property:
agsDynamicMapServiceLayer.VisibleLayers = visibleLayers.ToArray();
The "B.1.a" layer (6) that is *NOT* present in the agsDynamicMapServiceLayer.VisibleLayers list is still being displayed!?
QUESTION NUMBER 1: ANY IDEA WHY IT'S STILL BEING DRAWN ON THE MAP???
So I tried using SetVisibility() to turn on/off each layer as appropriate:
// now turn on only those that we're interested in seeing...
for ( int i = 0; i < agsDynamicMapServiceLayer.Layers.Count(); i++ )
{
if ( visibleLayers.Contains( agsDynamicMapServiceLayer.Layers.ID ) )
agsDynamicMapServiceLayer.SetLayerVisibility( agsDynamicMapServiceLayer.Layers.ID, true );
else
agsDynamicMapServiceLayer.SetLayerVisibility( agsDynamicMapServiceLayer.Layers.ID, false );
}
The map layers are now properly displayed - layer "B.1.a" is NOT rendered on the map.
HOWEVER, if I look at the VisibleLayers, it only includes the feature layers. None of the group layers are included. This breaks some of our other code downstream that looks at the VisibleLayers property to determine if a specific sublayer is actually visible or not.
QUESTION NUMBER 2: ANY IDEA WHY THE GROUP LAYERS ARE BEING OMITTED???
QUESTION NUMBER 3: ANY SUGGESTIONS FOR MORE THINGS TO TRY???
Thanks,
Gary