Visual Basic (Declaration) | |
---|---|
Public Property VisibleLayers As Integer() |
C# | |
---|---|
public int[] VisibleLayers {get; set;} |
To set visiblility of an ArcGISDynamicMapServiceLayer when the client application first loads, define the VisibleLayers Property during the code-behind Initialized Event or any time after the Initialization occurs.
Do not use the VisibleLayers Property to try and determine which sub-layers are visible for the ArcGISDynamicMapServiceLayer web service. The VisibleLayers Property will always return null/Nothing for the web service. Once the VisibleLayers Property has been set you can then you can use the get/Read operations of the VisibleLayer Property to obtain valid results. Use the ArcGISDynamicMapServiceLayer.GetLayerVisibility Method to return a boolean for a specific sub-layer ID of an ArcGISDynamicMapServiceLayer telling whether it is visible (true) or not (false) in the web service.
Another option for determining if the sub-layer of an ArcGISDynamicMapServiceLayer is visible or not is to enter the Url for the sub-layer in the address bar of an internet browser and look for the Default Visibility section in the ArcGIS REST Services Directory. Remember the sub-layer has the same Url as the main ArcGISDynamicMapServiceLayer but with a forward slash and the sub-layer ID value appended to the Url (ex: http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_BoundariesPlaces_World_2D/MapServer/0). See the following screen shot:
NOTE: Obtaining information (i.e. get/Read) for the various Properties of an ArcGISDynamicMapServiceLayer should occur in the Initialized Event or any time after the Initialized Event occurs. This ensures that information retrieved about the ArcGISDynamicMapServiceLayer has been obtained after a complete round trip from ArcGIS Server. Do not be tempted to try and access ArcGISDynamicMapServiceLayer Property information from generic application Events like: MainWindow.Loaded or the Constructor, etc. as the ArcGISDynamicMapServiceLayer has not been Initialized and erroneous information will be returned. Likewise, ArcGISDynamicMapServiceLayer Methods should not be invoked until after the ArcGISDynamicMapServiceLayer Initialized Event has fired or from within the Initialized Event to avoid erroneous results.
Property Value
Integer array containing sub-layer ids.How to use:
In this example the there are three sub-layers (IDs: 0, 1, and 2) in the ArcGISDynamicMapServiceLayer. They are all visible (i.e. turned on) by default in the ArcGIS Server web service. We are going to override the default and only show the second and third sub layers (i.e. 1 and 2) by using the ArcGISDynamicMapServiceLayer.VisibleLayers Property in the Initialized Event.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | Copy Code |
---|---|
<Grid x:Name="LayoutRoot"> <!-- Add a Map Control and zoom into an area of interest that shows useful information. --> <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,168,0,0" Name="Map1" VerticalAlignment="Top" Height="300" Width="616" Extent="-89.4581767708459,30.1713047548993,-79.646568737671,36.0582695748043"> <!-- Add an ArcGISDynamicMapServiceLayer. Wire up an Initialized Event to set the visibility for the individual sub-layers to a custom setting. --> <esri:ArcGISDynamicMapServiceLayer ID="ESRI_StateCityHighway_USA" Url="http://sampleserver1.arcgisonline.com/arcgis/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" Initialized="ArcGISDynamicMapServiceLayer_Initialized"/> </esri:Map> <!-- Provide some GUI instructions. --> <sdk:Label Height="28" HorizontalAlignment="Left" Margin="12,142,0,0" Name="Label1" VerticalAlignment="Top" Width="616" Content="Only the 2nd and 3rd sub-layers are visible because we used the VisibleLayers Property."/> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="81" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="640" TextWrapping="Wrap" Text="In this example the there are three sub-layers (IDs: 0, 1, and 2) in the ArcGISDynamicMapServiceLayer. They are all visible (i.e. turned on) by default in the ArcGIS Server web service. We are going to override the default and only show the second and third sub layers (i.e. 1 and 2) by using the ArcGISDynamicMapServiceLayer.VisibleLayers Property in the Initialized Event." /> </Grid> |
C# | Copy Code |
---|---|
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e) { // This function will draw specific sub-layers using the ArcGISDynamicMapServiceLayer.VisibleLayers Property. // Get the ArcGISDynamicMapServiceLayer from the Map Control based upon its position in the Control. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers[0]); // In this example the there are three sub-layers (IDs: 0, 1, and 2) and they are all visible (i.e. turned on) // by default in the ArcGIS Server web service. We are going to override the default and only show the second // and third sub layers (i.e. 1 and 2). int[] myVisibleLayers = {1, 2}; // Use the VisibleLayers Property to control which sub-layers are drawn. myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers; } |
VB.NET | Copy Code |
---|---|
Private Sub ArcGISDynamicMapServiceLayer_Initialized(sender As System.Object, e As System.EventArgs) ' This function will draw specific sub-layers using the ArcGISDynamicMapServiceLayer.VisibleLayers Property. ' Get the ArcGISDynamicMapServiceLayer from the Map Control based upon its position in the Control. Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = CType(Map1.Layers.Item(0), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) ' In this example the there are three sub-layers (IDs: 0, 1, and 2) and they are all visible (i.e. turned on) ' by default in the ArcGIS Server web service. We are going to override the default and only show the second ' and third sub layers (i.e. 1 and 2). Dim myVisibleLayers() As Integer = {1, 2} ' Use the VisibleLayers Property to control which sub-layers are drawn. myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers End Sub |
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8