Dynamic Layers in XAML

Download Samples Repository

Description

This sample demonstrates how to load dynamic map service layers in xaml.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.DynamicLayersInXAML"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
	
	<Grid >
		<Grid.Resources>
			<esri:SimpleLineSymbol x:Key="SLS" Color="Transparent" Width="1"/>
			<esri:SimpleLineSymbol x:Key="BlackSLS" Color="Black" Width="1"/>
		</Grid.Resources>
		<esri:MapView x:Name="MyMapView">
			<esri:Map >
				<esri:ArcGISDynamicMapServiceLayer ID="USA" 
													 ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" >
					<esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
						<esri:LayerDefinition LayerID="0" Definition="CAPITAL = 'Y'" />
					</esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
					<esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
						<esri:LayerDrawingOptionCollection>
							<esri:LayerDrawingOptions LayerID="0" ShowLabels="True">
								<esri:LayerDrawingOptions.Renderer>
									<esri:SimpleRenderer>
										<esri:SimpleMarkerSymbol Color="Red" Size="10" Style="Diamond" />
									</esri:SimpleRenderer>
								</esri:LayerDrawingOptions.Renderer>
							</esri:LayerDrawingOptions>
							<esri:LayerDrawingOptions LayerID="2">
								<esri:LayerDrawingOptions.Renderer>
									<esri:ClassBreaksRenderer Field="POP2000">
										<esri:ClassBreakInfo Maximum="1000000" Minimum="0">
											<esri:ClassBreakInfo.Symbol>
												<esri:SimpleFillSymbol Color="#74E01B" Outline="{StaticResource SLS}" />
											</esri:ClassBreakInfo.Symbol>
										</esri:ClassBreakInfo>
										<esri:ClassBreakInfo Maximum="2000000">
											<esri:ClassBreakInfo.Symbol>
												<esri:SimpleFillSymbol Color="#1BE025" Outline="{StaticResource SLS}" />
											</esri:ClassBreakInfo.Symbol>
										</esri:ClassBreakInfo>
										<esri:ClassBreakInfo Maximum="5000000">
											<esri:ClassBreakInfo.Symbol>
												<esri:SimpleFillSymbol Color="#1BE087" Outline="{StaticResource SLS}" />
											</esri:ClassBreakInfo.Symbol>
										</esri:ClassBreakInfo>
										<esri:ClassBreakInfo Maximum="10000000">
											<esri:ClassBreakInfo.Symbol>
												<esri:SimpleFillSymbol Color="#D6E01B" Outline="{StaticResource SLS}" />
											</esri:ClassBreakInfo.Symbol>
										</esri:ClassBreakInfo>
										<esri:ClassBreakInfo Maximum="40000000">
											<esri:ClassBreakInfo.Symbol>
												<esri:SimpleFillSymbol Color="#E0871B" Outline="{StaticResource SLS}" />
											</esri:ClassBreakInfo.Symbol>
										</esri:ClassBreakInfo>
									</esri:ClassBreaksRenderer>
								</esri:LayerDrawingOptions.Renderer>
							</esri:LayerDrawingOptions>
							<esri:LayerDrawingOptions LayerID="4">
								<esri:LayerDrawingOptions.Renderer>
									<esri:SimpleRenderer>
										<esri:SimpleFillSymbol Color="Blue" Outline="{StaticResource BlackSLS}"/>
									</esri:SimpleRenderer>
								</esri:LayerDrawingOptions.Renderer>
							</esri:LayerDrawingOptions>
						</esri:LayerDrawingOptionCollection>
					</esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>

					<esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
						<esri:DynamicLayerInfoCollection>
							<esri:DynamicLayerInfo ID="0">
								<esri:DynamicLayerInfo.Source>
									<esri:LayerMapSource MapLayerID="0" />
								</esri:DynamicLayerInfo.Source>
							</esri:DynamicLayerInfo>
							<esri:DynamicLayerInfo ID="4">
								<esri:DynamicLayerInfo.Source>
									<esri:LayerDataSource>
										<esri:LayerDataSource.DataSource>
											<esri:TableDataSource WorkspaceID="MyDatabaseWorkspaceIDSSR2" 
																	DataSourceName="ss6.gdb.Lakes" />
										</esri:LayerDataSource.DataSource>
									</esri:LayerDataSource>
								</esri:DynamicLayerInfo.Source>
							</esri:DynamicLayerInfo>
							<esri:DynamicLayerInfo ID="2">
								<esri:DynamicLayerInfo.Source>
									<esri:LayerMapSource MapLayerID="2" />
								</esri:DynamicLayerInfo.Source>
							</esri:DynamicLayerInfo>
						</esri:DynamicLayerInfoCollection>
					</esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
				</esri:ArcGISDynamicMapServiceLayer>
			</esri:Map>
		</esri:MapView>
	</Grid>

</UserControl>
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Layers;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample demonstrates how to load dynamic map service layers in xaml. 
	/// </summary>
	/// <title>Dynamic Layers in XAML</title>
	/// <category>Layers</category>
	/// <subcategory>Dynamic Service Layers</subcategory>
	public partial class DynamicLayersInXAML : UserControl
	{
		public DynamicLayersInXAML()
		{
			InitializeComponent();

			MyMapView.Map.InitialViewpoint = new Viewpoint(new Envelope(-3170138, -1823795, 2850785, 1766663, SpatialReference.Create(102009)));

			(MyMapView.Map.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = new System.Collections.ObjectModel.ObservableCollection<int> { 0, 2, 4 };

		}
	}
}
Feedback on this topic?