Add, remove, and reorder operational layers in a map.
Use case
Operational layers display the primary content of the map and usually provide dynamic content for the user to interact with (as opposed to basemap layers that provide context).
The order of operational layers in a map determines the visual hierarchy of layers in the view. You can bring attention to a specific layer by rendering above other layers.
How to use the sample
When the app starts, a list displays the operational layers that are currently displayed in the map. Right-click on the list item to remove the layer, or left-click to move it to the top. The map will be updated automatically.
The second list shows layers that have been removed from the map. Click one to add it to the map.
How it works
Get the operational layers from the map using map.OperationalLayers.
Add or remove layers using layerList.Add(layer) and layerList.Remove(layer) respectively. The last layer in the list will be rendered on top.
Relevant API
ArcGISMapImageLayer
Map
MapView
MapView.OperationalLayers
Additional information
You cannot add the same layer to the map multiple times or add the same layer to multiple maps. Instead, create a new layer using the FeatureTable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<UserControlx:Class="ArcGIS.WPF.Samples.ManageOperationalLayers.ManageOperationalLayers"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"><UserControl.Resources><DataTemplatex:Key="LayerListTemplate"DataType="esri:Layer"><LabelContent="{Binding Name}" /></DataTemplate><Stylex:Key="LayerListBoxItemStyle"TargetType="ListBoxItem"><!-- PreviewMouseLeftButtonDown is the event that is raised when the user clicks and holds the click. --><EventSetterEvent="PreviewMouseLeftButtonDown"Handler="ListBox_DragPreviewMove" /><!-- Drop is raised when user lets go while doing a drag-and-drop operation. --><EventSetterEvent="Drop"Handler="ListBoxItem_OnDrop" /><!-- AllowDrop specifies that dragged items can be dropped on this item. --><!-- ListBox items need to be supported for dragging to enable re-ordering. --><SetterProperty="AllowDrop"Value="True" /></Style></UserControl.Resources><Grid><esri:MapViewMap="{Binding Map}" /><BorderStyle="{StaticResource BorderStyle}"><StackPanelOrientation="Vertical"><LabelContent="Drag and drop to reorder and move layers." /><LabelHorizontalContentAlignment="Center"Content="Layers in map"FontWeight="SemiBold" /><!--
Item template defined in UserControl.Resources above specifies that each listbox
item's content consists of a label with the layer's Name property displayed.
--><!-- The item container style is used to define events and properties on listbox items. --><ListBoxx:Name="IncludedListBox"MinHeight="100"AllowDrop="True"Drop="ListBoxItem_OnDrop"ItemContainerStyle="{StaticResource LayerListBoxItemStyle}"ItemTemplate="{StaticResource LayerListTemplate}"ItemsSource="{Binding IncludedLayers}" /><LabelHorizontalContentAlignment="Center"Content="Layers not in map"FontWeight="SemiBold" /><!--
Item template defined in UserControl.Resources above specifies that each listbox
item's content consists of a label with the layer's Name property displayed.
--><!-- The item container style is used to define events and properties on listbox items. --><ListBoxx:Name="ExcludedListBox"MinHeight="100"AllowDrop="True"Drop="ListBoxItem_OnDrop"ItemContainerStyle="{StaticResource LayerListBoxItemStyle}"ItemTemplate="{StaticResource LayerListTemplate}"ItemsSource="{Binding ExcludedLayers, Mode=TwoWay}" /></StackPanel></Border></Grid></UserControl>