Create and save map

View inWPFUWPFormsiOSAndroid
View on GitHub
Sample viewer app

Create and save a map as an ArcGIS PortalItem (i.e. web map).

Image of create and save map

Use case

Maps can be created programmatically in code and then serialized and saved as an ArcGIS web map. A web map can be shared with others and opened in various applications and APIs throughout the platform, such as ArcGIS Pro, ArcGIS Online, the JavaScript API, Collector, and Explorer.

How to use the sample

  1. Select the basemap and layers you'd like to add to your map.
  2. Press the Save button.
  3. Sign into an ArcGIS Online account.
  4. Provide a title, tags, and description.
  5. Save the map.

How it works

  1. A Map is created with a Basemap and a few operational layers.
  2. A Portal object is created and loaded. This will issue an authentication challenge, prompting the user to provide credentials.
  3. Once the user is authenticated, map.SaveAsAsync is called and a new Map is saved with the specified title, tags, and folder.

Relevant API

  • AuthenticationManager
  • ChallengeHandler
  • GenerateCredentialAsync
  • IOAuthAuthorizeHandler
  • Map
  • Map.SaveAsAsync
  • Portal

Tags

ArcGIS Online, OAuth, portal, publish, share, web map

Sample Code

AuthorMap.xamlAuthorMap.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<UserControl x:Class="ArcGISRuntime.WPF.Samples.AuthorMap.AuthorMap"
             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>
        <Style TargetType="ListBox">
            <Setter Property="Margin" Value="10" />
        </Style>
        <Style TargetType="TextBlock">
            <Setter Property="Margin" Value="0,5,5,0" />
            <Setter Property="VerticalAlignment" Value="Top" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="0,5,0,0" />
            <Setter Property="Padding" Value="2.5" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Text="Select a basemap:"
                       Grid.Row="0"
                       Margin="10,10,0,0" HorizontalAlignment="Right" />
            <ListBox x:Name="BasemapListBox"
                     Grid.Row="0" Grid.Column="1"
                     HorizontalAlignment="Stretch"
                     SelectionChanged="BasemapSelectionChanged" />
            <TextBlock Text="Choose layers:"
                       Grid.Row="1" Grid.Column="0"
                       Margin="10,10,0,0"
                       HorizontalAlignment="Right" />
            <ListBox x:Name="OperationalLayerListBox"
                     SelectionMode="Multiple"
                     Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch"
                     SelectionChanged="OperationalLayerSelectionChanged">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Key}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <TextBlock Text="Initial Extent:"
                       Grid.Row="2" Grid.Column="0"
                       HorizontalAlignment="Right"
                       Margin="10,15,0,0" />
            <Grid Grid.Row="2" Grid.Column="1"
                  Margin="10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="X Min:"
                           Grid.Row="0" Grid.Column="0"
                           VerticalAlignment="Center" />
                <TextBox x:Name="XMinTextBox"
                         Grid.Row="0" Grid.Column="1"
                         HorizontalAlignment="Stretch"
                         IsReadOnly="True" />
                <TextBlock Text="Y Min:"
                           Grid.Row="1" Grid.Column="0"
                           VerticalAlignment="Center" />
                <TextBox x:Name="YMinTextBox"
                         Grid.Row="1" Grid.Column="1"
                         IsReadOnly="True"
                         Text="" />
                <TextBlock Text="X Max:"
                           Grid.Row="2" Grid.Column="0"
                           VerticalAlignment="Center" />
                <TextBox x:Name="XMaxTextBox"
                         Grid.Row="2" Grid.Column="1"
                         IsReadOnly="True"
                         Text="" />
                <TextBlock Text="Y Max:"
                           Grid.Row="3" Grid.Column="0"
                           VerticalAlignment="Center" />
                <TextBox x:Name="YMaxTextBox"
                         Grid.Row="3" Grid.Column="1"
                         IsReadOnly="True"
                         Text="" />
            </Grid>
            <Button Content="New Map"
                    Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
                    VerticalAlignment="Top" HorizontalAlignment="Stretch"
                    Margin="10" Padding="5"
                    Click="ClearMapClicked" />
            <Grid x:Name="SaveMapGrid"
                  Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
                  Margin="10"
                  Visibility="Collapsed">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="Title:"
                           VerticalAlignment="Center" HorizontalAlignment="Right" />
                <TextBox x:Name="TitleTextBox"
                         Grid.Row="0" Grid.Column="1"
                         HorizontalAlignment="Stretch"
                         Text="My Map" />
                <TextBlock Text="Description:"
                           Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" />
                <TextBox x:Name="DescriptionTextBox"
                         Grid.Row="1" Grid.Column="1"
                         HorizontalAlignment="Stretch"
                         TextWrapping="Wrap"
                         Text="Authored and saved using ArcGIS Runtime SDK." />
                <TextBlock Text="Tags:"
                           Grid.Row="2" Grid.Column="0"
                           VerticalAlignment="Center" HorizontalAlignment="Right" />
                <TextBox x:Name="TagsTextBox"
                         Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch"
                         Text="ArcGIS Runtime, Sample" />
                <Button Content="Save Map to Portal"
                        Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
                        IsEnabled="{Binding ElementName=MyMapView }"
                        HorizontalAlignment="Stretch" Margin="0,10,0,0" Padding="5"
                        Click="SaveMapClicked" />
                <ProgressBar x:Name="SaveProgressBar"
                             Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
                             Height="15" Margin="10,0,10,0"
                             HorizontalAlignment="Stretch"
                             IsIndeterminate="True" Visibility="Hidden" />
            </Grid>
            <Grid x:Name="OAuthSettingsGrid"
                  Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
                  Margin="10"
                  Visibility="Visible">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="OAuth Settings"
                           Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                <TextBlock Text="Client ID:"
                           Grid.Row="1" Grid.Column="0"
                           VerticalAlignment="Center" HorizontalAlignment="Right" />
                <TextBox x:Name="ClientIdTextBox"
                         Grid.Row="1" Grid.Column="1"
                         HorizontalAlignment="Stretch" />
                <TextBlock Text="Redirect URL:"
                           Grid.Row="2" Grid.Column="0"
                           VerticalAlignment="Center" HorizontalAlignment="Stretch" />
                <TextBox x:Name="RedirectUrlTextBox"
                         Grid.Row="2" Grid.Column="1"
                         HorizontalAlignment="Stretch" />
                <Button Content="Save OAuth Settings"
                        Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
                        Margin="0,10,0,0" Padding="5"
                        HorizontalAlignment="Stretch"
                        Click="SaveOAuthSettingsClicked" />
            </Grid>
        </Grid>
        <esri:MapView x:Name="MyMapView"
                      Grid.Column="1" />
    </Grid>
</UserControl>

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