Select to view content in your preferred language

Controlling layer visibility of a map service from code

986
2
06-10-2011 05:12 AM
PaulHuppé
Deactivated User
Hi,

I am trying to control the layer visibility of a map service in code behind.  I thought this would be simple, but I am having a hard time getting this done. I can get a hold of the service from my Map Control, called map, using map.Layers[0] for example.  This contains an array of LayerInfo.  If I loop on this array, for any of the LayerInfo, there is no settable visibility property.  The LayerInfo only has a DefaultVisibility property which is a boolean indicating the layer's default visibility.  I also tried looking in the MapLegend control without success.  Is there an easy way to do this that I have not found yet?

Thanks,
Paul
0 Kudos
2 Replies
TerryGiles
Frequent Contributor
Assuming the layer you're after is of type ArcGISDynamicMapServiceLayer, use the VisibleLayers property to control which sublayers are displayed.  It's an array of Int so just add/remove the sublayer index from that.


 int[] myVisibleLayers = { 1, 2, 4 };  //sublayers 0 & 3 will not display 
 myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers;
0 Kudos
PaulHuppé
Deactivated User
Thanks Terry, this is what I was looking for.
Paul
0 Kudos