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-tap on the list item to remove the layer, or left-tap to move it to the top. The map will be updated automatically.

The second list shows layers that have been removed from the map. Tap 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
58
59
60
61
62
63
64
65
66
67
68
<?xml version="1.0" encoding="utf-8" ?>

<ContentPage x:Class="ArcGISRuntimeXamarin.Samples.ManageOperationalLayers.ManageOperationalLayers"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime"
             xmlns:resources="clr-namespace:Forms.Resources;assembly=ArcGISRuntime">
    <ContentPage.Resources>
        <DataTemplate x:Key="LayerListTemplate" x:DataType="mapping:Layer">
            <ViewCell>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label Grid.Column="0"
                           Margin="5"
                           Text="{Binding Name}"
                           VerticalTextAlignment="Center" />
                    <Button Grid.Column="1"
                            Clicked="PromoteButton_Clicked"
                            Text="⬆" />
                    <Button Grid.Column="2"
                            Clicked="DemoteButton_Clicked"
                            Text="⬇" />
                    <Button Grid.Column="3"
                            Clicked="MoveButton_OnClicked"
                            Text="➡" />
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ContentPage.Resources>
    <RelativeLayout>
        <esriUI:MapView x:Name="MyMapView"
                        BindingContext="{x:Reference Name=ResponsiveFormContainer}"
                        Style="{StaticResource MapWithFormStyle}" />
        <resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
            <StackLayout>
                <Label Text="Use the buttons to re-arrange layers." />
                <Label FontAttributes="Bold"
                       HorizontalTextAlignment="Center"
                       Text="Layers in map" />
                <!--
                    Item template defined in UserControl.Resources above specifies that each listbox
                    item's content consists of a label with the layer's Name and three buttons.
                -->
                <ListView x:Name="IncludedListView"
                          HeightRequest="80"
                          ItemTemplate="{StaticResource LayerListTemplate}"
                          VerticalOptions="Start" />
                <Label FontAttributes="Bold"
                       HorizontalTextAlignment="Center"
                       Text="Layers not in map" />
                <!--
                    Item template defined in UserControl.Resources above specifies that each listbox
                    item's content consists of a label with the layer's Name and three buttons.
                -->
                <ListView x:Name="ExcludedListView"
                          HeightRequest="80"
                          ItemTemplate="{StaticResource LayerListTemplate}"
                          VerticalOptions="Start" />
            </StackLayout>
        </resources:ResponsiveFormContainer>
    </RelativeLayout>
</ContentPage>

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