ArcGIS API for Silverlight - Library Reference
CreateDynamicLayerInfosFromLayerInfos Method
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > ArcGISDynamicMapServiceLayer Class : CreateDynamicLayerInfosFromLayerInfos Method

For an ArcGISDynamicMapServiceLayer that is published as a service on ArcGIS Server, this Method generates a DynamicLayerInfoCollection. The DynamicLayerInfo objects in the DynamicLayerInfoCollection can then be modified for input to the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property for constructing Dynamic Layers.

Syntax

Visual Basic (Declaration) 
Public Function CreateDynamicLayerInfosFromLayerInfos() As DynamicLayerInfoCollection
C# 
public DynamicLayerInfoCollection CreateDynamicLayerInfosFromLayerInfos()

Remarks

Dynamic Layers allow the execution of various ArcGIS Server requests from a client application. An in-depth discussion about Dynamic Layers is in the ArcGISDynamicMapServiceLayer Class documentation. The client side requests that can be issued to ArcGIS Server include the ability to:

Dynamic Layers are new in ArcGIS Server v10.1 and require the ArcGIS API 3.0 for Silverlight and higher.

The key to creating a Dynamic Layer is to set the DynamicLayerInfo.Source Property to the appropriate LayerSource object. The LayerSource is an Abstract Class and has two inherited Classes that should be used in setting the DynamicLayerInfo.Source, they are: LayerDataSource and LayerMapSource. One DynamicLayerInfo object is used per Dynamic Layer and is added to a DynamicLayerInfoCollection which is set to the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property. By default, an ArcGISDynamicMapServiceLayer that was created in ArcMap and served up via ArcGIS Server has its DynamicLayerInfos collection being empty (meaning Nothing/null). Developers can use the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method to populate the DynamicLayerInfoCollection to serve as a starting point for creating a Dynamic Layer or they can create individual DynamicLayerInfo objects from scratch and add them to the DynamicLayerInfoCollection.

Example

How to use:

When the application code initially executes a Dynamic Layer is generated based upon an existing sub-layer of an ArcGISDynamicMapServiceLayer (specifically the 'cities' or [0] sub-layer) using custom Rendering. Select one of RadioButtons and click the Button change the appearance of the ArcGISDynamicMapServiceLayer. You will need to re-run the application each time to test the different radio button options to see the difference. The default radio button (i.e. 'Add all additonal sub-layers except cities from the ArcGISDynamicMapServiceLayer') will preserve the Rendering of the custom Dynamic Layer and add the default Rendering of the others sub-layers defined in the map service (except the cities layer). The other radio button (i.e. 'Revert back to original ArcGISDynamicMapServiceLayer') will override the Dynamic Layer and display the Rendering of the map service as defined by ArcMap and ArcGIS Server.

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.

Creating a Dynamic Layer in XAML and modifying in code-behind.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Create a SimpleMarkerSymbol in the Resources for use in the custom Dynamic Layer. -->
  <Grid.Resources>
    <esri:SimpleRenderer x:Key="myRenderer">
      <esri:SimpleRenderer.Symbol>
        <esri:SimpleMarkerSymbol Color="Red" Style="Cross" Size="10"/>
      </esri:SimpleRenderer.Symbol>
    </esri:SimpleRenderer>
   </Grid.Resources>
  
  <!-- Add a Map Control. Zoom to the South-Western United States. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="0,238,0,0" Name="Map1" 
          VerticalAlignment="Top" Height="350" Width="500" Extent="-13468458,3546553,-12238506,4578324">
  
    <!--Add a backdrop ArcGISTiledMapServiceLayer. -->
    <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" 
      Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
  
    <!-- 
    Add a Dynamic Layer based on an existing ArcMap and ArcGIS Server map service ArcGISDynamicMapServiceLayer 
    sub-layer (specifically the 'cities' or [0] sub-layer). A Dynamic Layer is a web request where the client 
    application issues an ArcGIS Server command to generate an on-the-fly layer for display in the Map Control. 
    Note: the DisableClientCaching is set to true so that what ever is returned from the server will be displayed.
        
    The following high-level things are occuring to create the Dynamic Layer: 
    (1) create a DynamicLayerInfo object and set the .ID and .Source Properties
    (2) add that DynamicLayerInfo object to the ArcGISDynamicMapServiceLayer .DynamicLayerInfos collection
    (3) create a LayerDrawingOptions object and set the .LayerID and .Renderer Properties
    (4) add that LayerDrawingOptions object to the ArcGISDynamicMapServiceLayer .LayerDrawingOptions collection
    -->
     <esri:ArcGISDynamicMapServiceLayer ID="myArcGISDynamicMapServiceLayer" 
         Url="http://servicesbeta4.esri.com/arcgis/rest/services/USA/MapServer" DisableClientCaching="True">
      <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
        <esri:DynamicLayerInfoCollection>
          <esri:DynamicLayerInfo ID="5">
            <esri:DynamicLayerInfo.Source>
              <esri:LayerMapSource MapLayerID="0"/>
            </esri:DynamicLayerInfo.Source>
          </esri:DynamicLayerInfo>
        </esri:DynamicLayerInfoCollection>
      </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
      <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
        <esri:LayerDrawingOptionsCollection>
          <esri:LayerDrawingOptions LayerID="5" Renderer="{StaticResource myRenderer}"/>
        </esri:LayerDrawingOptionsCollection>
      </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
    </esri:ArcGISDynamicMapServiceLayer>
  
  </esri:Map>
  
  <!-- Add a Button and two Radio Buttons to change what is displayed in the Map. -->
  <RadioButton Content="Add all additonal sub-layers except cities from the ArcGISDynamicMapServiceLayer" 
               Height="16" HorizontalAlignment="Left" Margin="12,165,0,0" VerticalAlignment="Top" 
               Name="RadioButton_AllSubLayersExceptCities" IsChecked="True"/>
  <RadioButton Content="Revert back to original ArcGISDynamicMapServiceLayer (i.e. all sub-layers)" Height="16" 
               HorizontalAlignment="Left" Margin="12,187,0,0" Name="RadioButton_AllSubLayers" VerticalAlignment="Top" />
  <Button Content="Modify the ArcGISDynamicMapServiceLayer" Height="23" 
          HorizontalAlignment="Left" Margin="0,209,0,0" Name="Button1" VerticalAlignment="Top" Width="500" 
          Click="Button1_Click"/>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="160" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="759" 
       TextWrapping="Wrap" Text="When the application code initially executes a Dynamic Layer is generated based upon an 
       existing sub-layer of an ArcGISDynamicMapServiceLayer (specifically the 'cities' or [0] sub-layer) using custom 
       Rendering. Select one of RadioButtons and click the Button change the appearance of the ArcGISDynamicMapServiceLayer. 
       You will need to re-run the application each time to test the different radio button options to see the difference. 
       The default radio button (i.e. 'Add all additonal sub-layers except cities from the ArcGISDynamicMapServiceLayer') 
       will preserve the Rendering of the custom Dynamic Layer and add the default Rendering of the others sub-layers
       defined in the map service (except the cities layer). The other radio button (i.e. 'Revert back to original 
       ArcGISDynamicMapServiceLayer') will override the Dynamic Layer and display the Rendering of the map service as 
       defined by ArcMap and ArcGIS Server." />
  
</Grid>
C#Copy Code
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // NOTE: You will need to re-run the application each time to test the different radio button options to see the difference.
  
  // Get the ArcGISDynamicMapServiceLayer defined in XAML.
  ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = null;
  myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers["myArcGISDynamicMapServiceLayer"]);
  
  // Get the DynamicLayerInfoCollection which contains information about all of the sub-layers of the 
  // ArcGISDynamicMapServiceLayer that was defined when the map service was initially created using
  // ArcMap and ArcGIS Server.
  ESRI.ArcGIS.Client.DynamicLayerInfoCollection myDynamicLayerInfoCollection = myArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos();
  
  if (RadioButton_AllSubLayers.IsChecked == true)
  {
   // Set the original ArcGISDynamicMapServiceLayer .DynamicLayerInfoCollection that was defined by ArcMap and the 
   // ArcGIS Server map service to the current .DynamicLayerInfos. This will in effect override the Dynamic Layer 
   // and use the Rendering that was originally defined in the ArcMap and ArcGIS Server ArcGISDynamicmapServiceLayer 
   // map service.
   myArcGISDynamicMapServiceLayer.DynamicLayerInfos = myDynamicLayerInfoCollection;
  }
  else if (RadioButton_AllSubLayersExceptCities.IsChecked == true)
  {
   // This option will preserve the XAML defined Dynamic Layer and just add the originally defined ArcMap and ArcGIS 
   // Server map service sub-layers that are specified. Note that the 'cities' or [0] sub-layer will not be added 
   // using its default server side rendering because we want to preserve the custom symbology of the Dynamic Layer.
   myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection[1]);
   myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection[2]);
   myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection[3]);
  }
  
  // Refresh the ArcGISDynamicMapServiceLayer in order to issue the changes to ArcGIS Server.
  myArcGISDynamicMapServiceLayer.Refresh();
}
VB.NETCopy Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  
  ' NOTE: You will need to re-run the application each time to test the different radio button options to see the difference.
  
  ' Get the ArcGISDynamicMapServiceLayer defined in XAML.
  Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
  myArcGISDynamicMapServiceLayer = CType(Map1.Layers("myArcGISDynamicMapServiceLayer"), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)
  
  ' Get the DynamicLayerInfoCollection which contains information about all of the sub-layers of the 
  ' ArcGISDynamicMapServiceLayer that was defined when the map service was initially created using
  ' ArcMap and ArcGIS Server.
  Dim myDynamicLayerInfoCollection As ESRI.ArcGIS.Client.DynamicLayerInfoCollection = myArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos
  
  If RadioButton_AllSubLayers.IsChecked = True Then
    
    ' Set the original ArcGISDynamicMapServiceLayer .DynamicLayerInfoCollection that was defined by ArcMap and the 
    ' ArcGIS Server map service to the current .DynamicLayerInfos. This will in effect override the Dynamic Layer 
    ' and use the Rendering that was originally defined in the ArcMap and ArcGIS Server ArcGISDynamicmapServiceLayer 
    ' map service.
    myArcGISDynamicMapServiceLayer.DynamicLayerInfos = myDynamicLayerInfoCollection
    
  ElseIf RadioButton_AllSubLayersExceptCities.IsChecked = True Then
    
    ' This option will preserve the XAML defined Dynamic Layer and just add the originally defined ArcMap and ArcGIS 
    ' Server map service sub-layers that are specified. Note that the 'cities' or [0] sub-layer will not be added 
    ' using its default server side rendering because we want to preserve the custom symbology of the Dynamic Layer.
    myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection(1))
    myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection(2))
    myArcGISDynamicMapServiceLayer.DynamicLayerInfos.Add(myDynamicLayerInfoCollection(3))
    
  End If
  
  ' Refresh the ArcGISDynamicMapServiceLayer in order to issue the changes to ArcGIS Server.
  myArcGISDynamicMapServiceLayer.Refresh()
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.