Manage operational layers

View inWPFUWPFormsiOSAndroid
View on GitHub
Sample viewer app

Add, remove, and reorder operational layers in a map.

Image of manage operational layers

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

  1. Get the operational layers from the map using map.OperationalLayers.
  2. 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, clone the layer with layer.Clone() before duplicating.

Tags

add, delete, layer, map, remove

Sample Code

ManageOperationalLayers.xamlManageOperationalLayers.xaml.cs
                                                     
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
<UserControl x:Class="ArcGISRuntime.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>
        <DataTemplate x:Key="LayerListTemplate" DataType="esri:Layer">
            <Label Content="{Binding Name}" />
        </DataTemplate>
        <Style TargetType="ListBoxItem" x:Key="LayerListBoxItemStyle">
            <!-- PreviewMouseLeftButtonDown is the event that is raised when the user clicks and holds the click. -->
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBox_DragPreviewMove" />
            <!-- Drop is raised when user lets go while doing a drag-and-drop operation. -->
            <EventSetter Event="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. -->
            <Setter Property="AllowDrop" Value="True" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <esri:MapView Map="{Binding Map}" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel Orientation="Vertical">
                <Label Content="Drag and drop to reorder and move layers." />
                <Label Content="Layers in map"
                       HorizontalContentAlignment="Center"
                       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. -->
                <ListBox x:Name="IncludedListBox"
                         ItemsSource="{Binding IncludedLayers}"
                         ItemTemplate="{StaticResource LayerListTemplate}"
                         ItemContainerStyle="{StaticResource LayerListBoxItemStyle}"
                         AllowDrop="True"
                         MinHeight="100"
                         Drop="ListBoxItem_OnDrop" />
                <Label Content="Layers not in map"
                       HorizontalContentAlignment="Center"
                       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. -->
                <ListBox x:Name="ExcludedListBox"
                         ItemsSource="{Binding ExcludedLayers, Mode=TwoWay}"
                         ItemTemplate="{StaticResource LayerListTemplate}"
                         ItemContainerStyle="{StaticResource LayerListBoxItemStyle}"
                         AllowDrop="True"
                         MinHeight="100"
                         Drop="ListBoxItem_OnDrop" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.