Manage operational layers

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

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, create a new layer using the FeatureTable.

Tags

add, delete, layer, map, remove

Sample Code

ManageOperationalLayers.xamlManageOperationalLayers.xamlManageOperationalLayers.xaml.cs
Use dark colors for code blocksCopy
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
<UserControl x:Class="ArcGISRuntime.WinUI.Samples.ManageOperationalLayers.ManageOperationalLayers"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <UserControl.Resources>
        <DataTemplate x:Key="LayerItemTemplate">
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
        <Style x:Key="LayerListStyle" TargetType="ListView">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="MinHeight" Value="100" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <!--  Allow items to be dropped on the listview.  -->
            <Setter Property="AllowDrop" Value="True" />
            <!--  Allow items to be dragged out of the listview.  -->
            <Setter Property="CanDragItems" Value="True" />
            <!--  Allow items to be reordered within the listview  -->
            <Setter Property="CanReorderItems" Value="True" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <esriUI:MapView Map="{Binding Map}" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="Drag and drop layers to add, remove, and reorder them."
                           TextAlignment="Left"
                           TextWrapping="Wrap" />
                <TextBlock FontWeight="SemiBold"
                           Text="Layers in map"
                           TextAlignment="Center" />
                <!--
                    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.
                -->
                <ListView DragItemsStarting="ListBox_OnDragItemsStarting"
                          DragOver="ListBox_OnDragOver"
                          Drop="ListBox_OnDrop"
                          ItemTemplate="{StaticResource LayerItemTemplate}"
                          ItemsSource="{Binding IncludedLayers, Mode=TwoWay}"
                          Style="{StaticResource LayerListStyle}" />
                <TextBlock FontWeight="SemiBold"
                           Text="Layers not in map"
                           TextAlignment="Center" />
                <!--
                    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.
                -->
                <ListView DragItemsStarting="ListBox_OnDragItemsStarting"
                          DragOver="ListBox_OnDragOver"
                          Drop="ListBox_OnDrop"
                          ItemTemplate="{StaticResource LayerItemTemplate}"
                          ItemsSource="{Binding ExcludedLayers}"
                          Style="{StaticResource LayerListStyle}" />
            </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.