Visual Basic (Declaration) | |
---|---|
Public Class ArcGISDynamicMapServiceLayer Inherits DynamicMapServiceLayer Implements IAttribution, ILegendSupport, ISublayerVisibilitySupport |
C# | |
---|---|
public class ArcGISDynamicMapServiceLayer : DynamicMapServiceLayer, IAttribution, ILegendSupport, ISublayerVisibilitySupport |
An ArcGISDynamicMapServiceLayer is a dynamic map service published by ArcGIS Server (version 9.3 and higher) using REST. An ArcGISDynamicMapServiceLayer has the following characteristics:
- It is composed of one or more sub-layers that display some geographic phenomena in a map image.
- Map images are generated on-the-fly from ArcGIS Server when requested by a Silverlight client application.
- The background color for the map image will always be transparent when the ArcGISDynamicMapServiceLayer.ImageFormat is set to use a lossless data compression such as PNG.
- The drawing performance is not as fast as cached map images using the ArcGISTiledMapServiceLayer but may be more appropriate for highly focused intranet applications and applications that are based on real-time or frequently updated data.
- Client applications can restrict what sub-layer geographic information is returned in the map image that is generated on-the-fly by setting the ArcGISDynamicMapServiceLayer.LayerDefinitions, ArcGISDynamicMapServiceLayer.TimeExtent, ArcGISDynamicMapServiceLayer.LayerTimeOptions, and ArcGISDynamicMapServiceLayer.VisibleLayers Properties.
For even more control over what is returned in the map image of an ArcGISDynamicMapServiceLayer, consider using client application requests using the new Dynamic Layer options available with ArcGIS Server v10.1 and the ArcGIS API 3.0 for Silverlight. Dynamic Layers add the ability for the client application to request ArcGIS Server to change the rendering of an existing ArcGISDynamicMapServiceLayer or create a layer on-the-fly for various Workspace Types. See the Dynamic Layers section later in this document for more information.
When an ArcMap author publishes an ArcGISDynamicMapServiceLayer on ArcGIS Server, each sub-layer can be accessed individually as a FeatureLayer. A FeatureLayer is a specialized type of GraphicsLayer that has several unique capabilities that are outlined in the conceptual document entitled creating a feature layer.
Note: Both FeatureLayers and client side generated Dynamic Layers there is a default 1000 return feature limit imposed by ArcGIS Sever to maintain performance. This maximum number of records returned by ArcGIS Server 1000 (aka. feature limit) can be increased when publishing the ArcGISDynamicMapServiceLayer. The 1000 feature return limit does not apply to a regular ArcGISDynamicMapServiceLayer.
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: MainPage.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.
For most ArcGISDynamicMapServiceLayer Properties that have both get/set (C#) or Read/Write (VB.NET) Properties, accessing the get/Read for a particular Property will return null/Nothing from ArcGIS Server. The exceptions are DisableClientCaching which returns false and ImageFormat which returns ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32; these are the default values. For all other get/set (C#) or Read/Write (VB.NET) Property values, in order to obtain get/Read information the application developer must first set/Write the values. Use the various ArcGISDynamicMapServiceLayer Methods to serve as a starting point to obtain ArcGIS Server metadata information for the set/Write Properties. The following list some example of using ArcGISDynamicMapServiceLayer Methods to obtain information for doing set/Write Property values:
-
Use the GetLayerVisibility Method to determine which sub-layers in the ArcGISDynamicMapServiceLayer are visible in the web service. Then use that information to set/Write the VisibleLayers Property if you want to dynamically adjust which sub-layers are displayed.
-
Use the CreateDynamicLayerInfosFromLayerInfos Method to generate a ESRI.ArcGIS.Client.DynamicLayerInfoCollection. The ESRI.ArcGIS.Client.DynamicLayerInfo objects in the DynamicLayerInfoCollection can then be modified for input to the DynamicLayerInfos Property for constructing Dynamic Layers.
-
Use the GetAllDetails Methods to generate a Dictionary of ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo objects. The FeatureLayerInfo object has a ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.DefinitionExpression Property that can then modified for input to set/Write the LayerDefinitions Property.
Specifying ArcGISDynamicMapServiceLayer Property information (i.e. set/Write) can be done both in XAML and the code-behind. Using Binding syntax in XAML on ArcGISDynamicMapServiceLayer Properties to obtain Property information (i.e. get/Read) returns valid results as the ArcGISDynamicMapServiceLayer Initialized Event fires before any FrameworkElement Rendering occurs.
Wiring up the stub for the ArcGISDynamicMapServiceLayer Initialized and Event (as well as all other Events) is done by the application developer in XAML or code-behind. Creating the Event stubs is not done automatically just because an ArcGISDynamicMapServiceLayer is used in an application.
It is highly recommended to use the ArcGISDynamicMapServiceLayer InitializationFailed Event to test for valid data being returned from ArcGIS Server. Some common reasons for an ArcGISDynamicMapServiceLayer failing to Initialize include the ArcGIS Server being down or an incorrect REST Url was specified. If proper error handling is not done in the ArcGISDynamicMapServiceLayer InitializationFailed Event, an Unhandled Exception error message will be thrown by Visual Studio causing undesirable application termination.
Using the ArcGIS Services Directory:
A very useful tool for developers to understand the capabilities of an ArcGISDynamaicMapServiceLayer published on ArcGIS Sever is the ArcGIS REST Services Directory. Simply enter the Home Url for an ArcGIS Server in the address bar of your web browser and you can begin exploring the all the ArcGIS REST Services Directory metadata information about ArcGISDynamicMapServiceLayer services. The typical syntax for this Home Url is: http://[EnterYourServerNameHere]/ArcGIS/rest/services. For example, the Home Url for the free ArcGIS Online web services is: 'http://server.arcgisonline.com/arcgis/rest/services' (see the following screenshot):
In the ArcGIS REST Services Directory, ArcGISDynamicMapServiceLayers are those that have the words "(MapServer)" appended to the end of the map service name. Click on the hyperlink for the "[MyMapServiceName] (MapServer)" to view the detailed metadata information about the published ArcGISDynamicMapServiceLayer service. The metadata information about the ArcGISDynamicMapServiceLayer contained in the ArcGIS REST Services Directory page correspond to many of the ArcGIS API for Silverlight Properties that are discoverable using client application code logic. Some particular items of interest about viewing the ArcGISDynamicMapServiceLayer metadata contained in the ArcGIS REST Services Directory page include: Layers, Single Fused Map Cache/Tile Info, Spatial Reference, Supports Dynamic Layers, and Time Info. The following is a brief discussion on these particular metadata items:
-
Layers: this corresponds to the ArcGISDynamicMapServiceLayer.Layers Property and provides information on the sub-layers that comprise an ArcGISDynamicMapServiceLayer. One of the key pieces of information obtained from the ArcGISDynamicMapServiceLayer.Layers Property is the LayerInfo.ID Property. The LayerInfo.ID is the integer value of the specific sub-layer in the ArcGISDynamicMapServiceLayer.
Each sub-layer also corresponds to a FeatureLayer which has unique capabilities discussed in the conceptual document entitled 'creating a feature layer'. The Url for a specific FeatureLayer is the same Url as an ArcGISDynamicMapServiceLayer with a forward slash and the integer value of the sub-layer. For example, assume an ArcGISDynamicMapServiceLayer has the Url of http://dk-red2a:6080/arcgis/rest/services/UTAH/MapServer and it has a 5 sub-layers. If you wanted to access the first sub-layer specifically as a FeatureLayer, the Url would be: http://dk-red2a:6080/arcgis/rest/services/UTAH/MapServer/0.
You can determine the default ArcGISDynamicMapServiceLayer sub-layer visibility as defined by the map service in ArcGIS Server by using the ArcGISDynamicMapServiceLayer.GetLayerVisibility Method. You can use the client application to override the sub-layers visibility coming back as a map image using the ArcGISDynamicMapServiceLayer.VisibleLayers Property. The ArcGISDynamicMapServiceLayer.VisibleLayers Property should be used after the ArcGISDynamicMapServiceLayer has been initialized.
You can control which features are returned for a specific sub-layer in the map image from ArcGIS Server by specify the ArcGISDynamicMapServiceLayer.LayerDefinitions Property.
For ArcGISDynamicMapServiceLayers that have temporal data that is enabled, you can control which temporal features are returned on a specific sub-layer using the ArcGISDynamicMapServiceLayer.LayerTimeOptions Property.
-
Single Fused Map Cache/Tile Info: the Single Fused Map Cache value returns a Boolean. If the Single Fused Map Cache = true then the published map service can be used to create an ArcGISDynamicMapServiceLayer or an ArcGISTiledMapServiceLayer because they share the same Url to access the map service. An ArcGISTiledMapServiceLayer will have detailed Tile Info metadata when the Single Fused Map Cache = true.
The following example should help to clarify this concept: Using the free ArcGIS Online map service called "World_light_Gray_Base" found at the following REST Url:
http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer
You will see in the ArcGIS REST Services Directory that the metadata contains the text: Single Fused Map Cache: true this means that the map service could be used to define an ArcGISTiledMapServiceLayer or an ArcGISDynamicMapServiceLayer and as such you could define XAML syntax like the following:<esri:Map x:Name="Map1" WrapAround="True"> <esri:ArcGISTiledMapServiceLayer ID="World_Light_Gray_Base_V1" Url="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"/> <esri:ArcGISDynamicMapServiceLayer ID="World_Light_Gray_Base_V2" Url="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"/> </esri:Map>
Conversly, using the free ESRI beta testing map service called "USA_1990-2000_Population_Change" found at the following REST Url:
http://servicesbeta.esri.com/ArcGIS/rest/services/Demographics/USA_1990-2000_Population_Change/MapServer
You will see in the ArcGIS REST Services Directory that metadata contains the text: Single Fused Map Cache: false, this means that the map service can only be used to define an ArcGISDynamicMapServiceLayer because cached tiled layers have not been generated. As such you could define XAML syntax like the following:<esri:Map x:Name="Map1" WrapAround="True"> <esri:ArcGISDynamicMapServiceLayer ID="USA_1990-2000_Population_Change" Url="http://servicesbeta.esri.com/ArcGIS/rest/services/Demographics/USA_1990-2000_Population_Change/MapServer"/> </esri:Map>
-
Spatial Reference: The spatial reference is a combination of an ellipsoid, datum, and a coordinate system used to display geographic data of the three dimensional Earth on a two dimensional surface (such as a piece of paper of computer monitor). ArcGISDynamicMapServiceLayer's have the ability to be re-projected on-the-fly to match the spatial reference of other data types subject to a few conditions. Read the discussion in the Map.SpatialReference Property documentation for more information. You can access the spatial reference information using the client side ArcGISDynamicMapServiceLayer.SpatialReference Property.
-
Supports Dynamic Layers: the Supports Dynamic Layers value returns a Boolean. If the Supports Dynamic Layers = true then the ArcGISDynamicMapServiceLayer supports the ability to issue Dynamic Layer requests from the client application. See the Dynamic Layers section later in this document for more information.
-
Time Info: If the Time Info section is present in the ArcGIS REST Services Directory metadata for the ArcGISDynamicMapServiceLayer, then developers can take advantage of using the Map.TimeExtent Property to display snapshots of the temporal data that cover a specified time period. Once common use case is to bind a TimeSlider Control with a Map Control to provide an interactive user experience of showing how geographic temporal data changes over time.
The following image shows a screenshot of a fictitious map service name where each of the noted metadata items for an ArcGISDynamicMapServiceLayer have been highlighted and noted:
Starting with ArcGIS Server v10.1 and with the development framework of the ArcGIS API 3.0 for Silverlight, the ArcGISDynamicMapServiceLayer Class adds the ability to create Dynamic Layers. Dynamic Layers allow the execution of various ArcGIS Server requests from a client application. The client side requests that can be issued to ArcGIS Server include the ability to:
- Change the rendering of an existing ArcGISDynamicMapServiceLayer. See the code examples for the ArcGISDynamicMapServiceLayer.LayerDrawingOptions Property, the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method, and the LayerDrawingOptionsCollection Class.
- Create a layer on-the-fly for the Workspace Types of: Database, Shapefile, FileGDB, and Raster. See the code examples in the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property and the DynamicLayerInfoCollection Class.
- Perform table joins.
- Query for specific records. See the code example for the QueryDataSource Class.
- Identify features. See the code example for the Tasks.IdentifyParameters.DynamicLayerInfos Property.
- Return raster images.
There are four new Types (i.e. Properties, Methods, Events, etc.) that were added to the ArcGISDynamicMapServiceLayer Class that allows for the creation of Dynamic Layers, they are:
- CreateDynamicLayerInfosFromLayerInfos Method
- DynamicLayerInfos Property
- LayerDrawingOptions Property
- SupportsDynamicLayers Property
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 (review the LayerSource Digression topic later in this document for a more in-depth discussion). 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.
It is also necessary for Dynamic Layers that will be displayed in a Map Control to have the appropriate Rendering applied. Use the ArcGISDynamicMapServiceLayer.LayerDrawingOptions Property (which is a LayerDrawingOptionsCollection Class) to set the Rendering of each Dynamic Layer. Make sure that the LayerDrawingOptions.LayerID and DynamicLayerInfo.ID match in order for the Dynamic Layer to draw in the Map.
When creating a Dynamic Layer it should be noted that re-projection from its SpatialReference to the Map.SpatialReference will automatically occur. This automatic re-projection enables layers of different SpatialReferences to line up property on top of each other in the Map. There is one noteworthy item that should be mentioned however, the QueryDataSource Class has a SpatialReference Property that must be set correctly. Developers can use the ArcGIS REST Services Directory to determine what the QueryDataSource.SpatialReference Property should be.
By default ArcGIS Server restricts 1000 features being returned per service request of a Dynamic Layer to improve performance. To limit the number of features that are returned per request for a Dynamic Layer set a LayerDefinition via the ArcGISDynamicMapServiceLayer.LayerDefinitions Property. A LayerDefinition acts as a where clause just like in a traditional RDBMS to restrict which geographic features are drawn in the Dynamic Layer. When constructing a Dynamic Layer on-the-fly using the LayerDataSource Type, you will be responsible for creating the LayerDefinition from scratch; there is not a method like the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method to generate a pre-populated ObservableCollection(Of LayerDefinition) objects. When constructing the LayerDefintion for a DynamicLayer, it is imperative that the LayerDefinition.LayerID match the LayerDrawingOptions.LayerID and the DynamicLayerInfo.ID (see the code example in the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property documentation).
NOTE: Because creating and using Dynamic Layers requires both ArcGIS Server v10.1 and higher and the development framework of the ArcGIS API 3.0 for Silverlight and higher; use the ArcGISDynamicMapServiceLayer.SupportsDynamicLayers Property to ensure that these conditions have been met.
The following image is simplified Object Model Diagram demonstrating the key Types that are asscoiated with using a Dynamic Layer.
This digression discusses the LayerSource inherited Classes of LayerDataSource and LayerMapSource which are essential to setting the DynamicLayerInfo.Source Property for constructing a Dynamic Layer.
LayerMapSource
The LayerMapSource Class allows for the creation of Dynamic Layers based upon an existing ArcGISDynamicMapServiceLayer sub-layer that was created in ArcMap and published in ArcGIS Server. Developers can use either the information that is in the ArcGIS REST Services Directory pages or the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method to obtain the information necessary to create a Dynamic Layer. Dynamic Layers based upon a sub-layer of an ArcGISDynamicMapServiceLayer can be created in XAML or code-behind.
NOTE: There are code examples in the ArcGISDynamicMapServiceLayer.LayerDrawingOptions Property, ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method, and LayerDrawingOptionsCollection Class demonstrate various ways to create a Dynamic Layer from an existing sub-layer of an ArcGISDynamicMapServiceLayer using the LayerMapSource option.
Assume for the Url="http://servicesbeta2.esri.com/arcgis/rest/services/USA/MapServer" that the following ArcGIS REST Services Directory page exists. A developer could create a Dynamic Layer using any of the sub-layers in the ArcGISDynamicMapServiceLayer to create a custom rendering, namely: Cities, Highways, States or Counties. See the following screen shot for reference:
LayerDataSource
The LayerDataSource Class allows for the creation of Dynamic Layers on-the-fly based upon the Workspace Type of Database, Shapefile, FileGDB, and Raster that is specified when an ArcGISDynamicMapServiceLayer is published from ArcMap to ArcGIS Server (see the following screen shot of the 'Add Dynamic Workspace' dialog):
These Workspace Type values are not seen via the normal ArcGIS REST Services Directory pages nor can they be deduced by the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method. To create a Dynamic Layer using the LayerDataSource option requires information sharing between the manager/administrator of ArcGIS Server and the application developer.
In order for a developer to issue client-side requests to ArcGIS Server to create a Dynamic Layer based upon the LayerDataSource Class, the WorkspaceID and DataSourceName information must be known. The following provides details on how these two pieces of information can be found (it is assumed that an ArcGISDynamicMapServiceLayer which has Dynamic Layers was already enabled and was previously published on ArcGIS Server):
-
WorkspaceID
In the ArcGIS Server Manager, with the 'Manage Services' tab active, click on the hyperlink for the 'Map Service' that has the Dynamic Layer enabled. Then click on the 'Capabilities' tab and look towards the bottom of the page, the name of the WorkspaceID will be shown, along with its Workspace Type, and a clickable hyperlink that will provide all of the Connection String information. Make a written note of all of this information as this will be used by the developer to create a Dynamic Layer in the client application. Note: The Connection String information provides key information to figure out the second piece of critical information, the DataSourceName for each Dynamic Layer to generated in the client application.Example: Assume that an ArcGISDynamicMapServiceLayer service which had Dynamic Layer capabilities enabled was called 'DKRED2A_TEST_NODATA'. A developer could see the ArcGIS REST Services Directory information about the ArcGISDynamicMapServiceLayer via the Url="http://DK-RED2A:6080/arcgis/rest/services/DKRED2A_TEST_NODATA/MapServer". Furthermore, the ArcGIS Server Administrator/Manager used the ArcGIS Server Manager application to provide the Capabilities of the service to the developer that looked like the following screen shot:
-
DataSourceName
In ArcCatalog, ensure the 'Catalog Tree' dockable window is open. Expand the appropriate node in 'Catalog Tree' (i.e. Folder Connections, Database Servers, Database Connections, GIS Servers, etc.) to discover the correct DataSourceName. For example to to discover the DataSourceName for a Workspace Type of Database you would expand the 'Database Connections' node and click on the 'Database Connection' that has the 'Database' that was listed in the 'Connection String' from the ArcGIS Service Manager application for the ArcGISDynamicMapServiceLayer. The various DataSourceNames will be listed in the Contents tab. Note: the DataSourceNames will have as the first part of their string the name of the 'Database' that was in the 'Connection String'.Example: Using the same ArcGISDynamicMapServiceLayer with Dynamic Layer capabilities enabled called 'DKRED2A_TEST_NODATA' in the prior example, the ArcGIS Server Administrator/Manager used the ArcCatalog application to provide the all of the DataSourceNames to the developer that looked like the following screen shot:
These two pieces of information (i.e. the WorkspaceID and DataSourceName) become the starting point for constructing/modifying one of the four inherited Classes of the Abstract DataSource Class. The four inherited DataSource Classes to utilize in creating/using a Dynamic Layer are:
Given these screen shots for the fictitious ArcGISDynamicMapServiceLayer that had Dynamic Layer capabilities enabled, then a developer could now construct a Dynamic Layer on the client-side to make a request to ArcGIS Server for an on-the-fly image rendering. Using the preceding screen shots we know the WorkspaceID = "MyDatabaseWorkspaceID". The developer can choose from numerous DataSourceName types, in our fictitious example we will choose DataSourceName = "Redlands.DBO.EP_Streets_01A". The developer could then ensure that they had the correct information from the ArcGIS Server manager/administrator by accessing the publically available ArcGIS REST Services Directory for the Url="http://dk-red2a:6080/arcgis/rest/services/DKRED2A_TEST_NODATA/MapServer" and click on the Dynamic Layer link, enter the correct JSON syntax, and click the 'Get Dynamic Layer' button to see if valid information comes back about the Dynamic Layer. Continuing on with our fictitious ArcGISDynamicMapServiceLayer, the screen shots would look like the following:
And finally to round out the fictitious example, this is what some sample XAML code would look like for the Dynamic Layer:
<esri:ArcGISDynamicMapServiceLayer Url="http://DK-RED2A:6080/arcgis/rest/services/DKRED2A_TEST_NODATA/MapServer" DisableClientCaching="True"> <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos> <esri:DynamicLayerInfoCollection> <esri:DynamicLayerInfo ID="102"> <esri:DynamicLayerInfo.Source> <esri:LayerDataSource> <esri:LayerDataSource.DataSource> <esri:TableDataSource WorkspaceID="MyDatabaseWorkspaceID" DataSourceName="RedlandsTest.DBO.EP_Streets_01A"/> </esri:LayerDataSource.DataSource> </esri:LayerDataSource> </esri:DynamicLayerInfo.Source> </esri:DynamicLayerInfo> </esri:DynamicLayerInfoCollection> </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos> <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions> <esri:LayerDrawingOptionsCollection> <esri:LayerDrawingOptions LayerID="102" > <esri:LayerDrawingOptions.Renderer> <esri:SimpleRenderer> <esri:SimpleLineSymbol Color="Black" Width="4" Style="Solid" /> </esri:SimpleRenderer> </esri:LayerDrawingOptions.Renderer> </esri:LayerDrawingOptions> </esri:LayerDrawingOptionsCollection> </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions> </esri:ArcGISDynamicMapServiceLayer>
The code example in the ArcGISDynamicMapServiceLayer.DynamicLayerInfos Property demonstrates how to create a Dynamic Layer using an Esri provided ArcGISDynamicMapServiceLayer service using the LayerDataSource option (specifically via an FileGDB layer using the TableDataSource Class).
How to use:
When the application loads an ArcGISDynamicMapServiceLayer will automatically be added to the Map (it was specified in XAML). Click the Button to add another ArcGISDynaicMapServiceLayer to the Map (it will be added via code-behind). The ID of each layer will displayed in the TextBox.
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 to the application. Set the Extent to North America. --> <esri:Map x:Name="Map1" WrapAround="True" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,238,0,0" Height="350" Width="415" Extent="-20686341,712444,-5228835,12734949"> <!-- Add an ArcGISDynamicMapServiceLayer. Wire-up the Initilized Event to display information about the layer in a TextBox.--> <esri:ArcGISDynamicMapServiceLayer ID="World_Light_Gray_Base" Url="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer" Initialized="ArcGISDynamicMapServiceLayer_Initialized"/> </esri:Map> <!-- Add a Button that will allow the user to add another ArcGISDynamicMapServiceLayer via code-behind. --> <Button Name="Button1" Height="23" HorizontalAlignment="Left" Margin="0,209,0,0" VerticalAlignment="Top" Width="706" Content="Add another ArcGISDynamicMapServiceLayer (via code-behind) for the specified Url." Click="Button1_Click" /> <!-- TextBox to display information about about the ArcGISDynamicMapServiceLayers added to the Map. --> <TextBox Height="350" HorizontalAlignment="Left" Margin="421,238,0,0" Name="TextBox1" VerticalAlignment="Top" Width="285" /> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="174" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" Text="When the application loads an ArcGISDynamicMapServiceLayer will automatically be added to the Map (it was specified in XAML). Click the Button to add another ArcGISDynaicMapServiceLayer to the Map (it will be added via code-behind). The ID of each layer will displayed in the TextBox." /> </Grid> |
C# | Copy Code |
---|---|
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e) { // This function will execute as a result of the ArcGISDynamicMapServiceLayer that was defined in XAML // being Initialized. // Get the ArcGISDynamicMapServiceLayer. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)sender; // Get the ID of the ArcGISDynamicMapServiceLayer. string myID = myArcGISDynamicMapServiceLayer.ID; // Create a StringBuilder object to hold information about the ArcGISDynamicMapServiceLayer and add some // useful information to it. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); myStringBuilder.Append("The 1st ArcGISDynamicMapServiceLayer was" + Environment.NewLine); myStringBuilder.Append("added via XAML and it's ID is: " + Environment.NewLine); myStringBuilder.Append(myID); // Display the results of the StringBuilder text to the user. TextBox1.Text = myStringBuilder.ToString(); } private void Button1_Click(object sender, System.Windows.RoutedEventArgs e) { // This function execute as a result of the user clicking the Button. It adds an ArcGISDynamicMapServiceLayer // using code-behind. // Create an ArcGISDynamicServiceLayer. The Map1 object (a Map class) was previously defined in XAML. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer2 = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer(); // Set the Url of the ArcGISDynamicServiceLayer to a public service. myArcGISDynamicMapServiceLayer2.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Unemployment_Rate/MapServer"; // Set the ID of the ArcGISDynamicServiceLayer. myArcGISDynamicMapServiceLayer2.ID = "USA_Unemployment_Rate"; // Wire-up the Initialized Event of the ArcGISDynamicServiceLayer. Note how a different Initilized Event // is being used verses the one defined in XAML. They could share the same Initialized Event but we created // two seperate ones to demonstration purposes. myArcGISDynamicMapServiceLayer2.Initialized += ArcGISDynamicMapServiceLayer_Initialized2; // Add the ArcGISDynamicServiceLayer to the Map. Map1.Layers.Add(myArcGISDynamicMapServiceLayer2); } private void ArcGISDynamicMapServiceLayer_Initialized2(object sender, EventArgs e) { // This function will execute as a result of the ArcGISDynamicMapServiceLayer that was defined in code-behind // being Initialized. // Get the ArcGISDynamicMapServiceLayer. ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer2 = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)sender; // Get the ID of the ArcGISDynamicMapServiceLayer. string myID2 = myArcGISDynamicMapServiceLayer2.ID; // Create a StringBuilder object to hold information about the ArcGISDynamicMapServiceLayer and add some // useful information to it. System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder(); myStringBuilder.Append(TextBox1.Text + Environment.NewLine); myStringBuilder.Append(Environment.NewLine); myStringBuilder.Append("The 2nd ArcGISDynamicMapServiceLayer was" + Environment.NewLine); myStringBuilder.Append("added via code-behind and it's ID is: " + Environment.NewLine); myStringBuilder.Append(myID2); // Display the results of the StringBuilder text to the user. TextBox1.Text = myStringBuilder.ToString(); } |
VB.NET | Copy Code |
---|---|
Private Sub ArcGISDynamicMapServiceLayer_Initialized(sender As System.Object, e As System.EventArgs) ' This function will execute as a result of the ArcGISDynamicMapServiceLayer that was defined in XAML ' being Initialized. ' Get the ArcGISDynamicMapServiceLayer. Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = CType(sender, ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) ' Get the ID of the ArcGISDynamicMapServiceLayer. Dim myID As String = myArcGISDynamicMapServiceLayer.ID ' Create a StringBuilder object to hold information about the ArcGISDynamicMapServiceLayer and add some ' useful information to it. Dim myStringBuilder As New Text.StringBuilder myStringBuilder.Append("The 1st ArcGISDynamicMapServiceLayer was" + vbCrLf) myStringBuilder.Append("added via XAML and it's ID is: " + vbCrLf) myStringBuilder.Append(myID) ' Display the results of the StringBuilder text to the user. TextBox1.Text = myStringBuilder.ToString End Sub Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) ' This function execute as a result of the user clicking the Button. It adds an ArcGISDynamicMapServiceLayer ' using code-behind. ' Create an ArcGISDynamicServiceLayer. The Map1 object (a Map class) was previously defined in XAML. Dim myArcGISDynamicMapServiceLayer2 As New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer ' Set the Url of the ArcGISDynamicServiceLayer to a public service. myArcGISDynamicMapServiceLayer2.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Unemployment_Rate/MapServer" ' Set the ID of the ArcGISDynamicServiceLayer. myArcGISDynamicMapServiceLayer2.ID = "USA_Unemployment_Rate" ' Wire-up the Initialized Event of the ArcGISDynamicServiceLayer. Note how a different Initilized Event ' is being used verses the one defined in XAML. They could share the same Initialized Event but we created ' two seperate ones to demonstration purposes. AddHandler myArcGISDynamicMapServiceLayer2.Initialized, AddressOf ArcGISDynamicMapServiceLayer_Initialized2 ' Add the ArcGISDynamicServiceLayer to the Map. Map1.Layers.Add(myArcGISDynamicMapServiceLayer2) End Sub Private Sub ArcGISDynamicMapServiceLayer_Initialized2(sender As Object, e As EventArgs) ' This function will execute as a result of the ArcGISDynamicMapServiceLayer that was defined in code-behind ' being Initialized. ' Get the ArcGISDynamicMapServiceLayer. Dim myArcGISDynamicMapServiceLayer2 As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = CType(sender, ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) ' Get the ID of the ArcGISDynamicMapServiceLayer. Dim myID2 As String = myArcGISDynamicMapServiceLayer2.ID ' Create a StringBuilder object to hold information about the ArcGISDynamicMapServiceLayer and add some ' useful information to it. Dim myStringBuilder As New Text.StringBuilder myStringBuilder.Append(TextBox1.Text + vbCrLf) myStringBuilder.Append(vbCrLf) myStringBuilder.Append("The 2nd ArcGISDynamicMapServiceLayer was" + vbCrLf) myStringBuilder.Append("added via code-behind and it's ID is: " + vbCrLf) myStringBuilder.Append(myID2) ' Display the results of the StringBuilder text to the user. TextBox1.Text = myStringBuilder.ToString End Sub |
System.Object
System.Windows.DependencyObject
ESRI.ArcGIS.Client.Layer
ESRI.ArcGIS.Client.DynamicLayer
ESRI.ArcGIS.Client.DynamicMapServiceLayer
ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7