View in MAUI WPF WinUI UWP View on GitHub

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.xaml AuthorMap.xaml AuthorMap.xaml.cs
<UserControl x:Class="ArcGIS.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" BasedOn="{StaticResource CalciteListBoxStyle}">
<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>
<ScrollViewer>
<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 Grid.Row="0"
Margin="10,10,0,0"
HorizontalAlignment="Right"
Text="Select a basemap:" />
<ListBox x:Name="BasemapListBox"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Stretch" />
<TextBlock Grid.Row="1"
Grid.Column="0"
Margin="10,10,0,0"
HorizontalAlignment="Right"
Text="Choose layers:" />
<ListBox x:Name="OperationalLayerListBox"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Stretch"
SelectionChanged="OperationalLayerSelectionChanged"
SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Grid.Row="2"
Grid.Column="0"
Margin="10,15,0,0"
HorizontalAlignment="Right"
Text="Initial Extent:" />
<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 Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Center"
Text="X Min:" />
<TextBox x:Name="XMinTextBox"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Stretch"
IsReadOnly="True" />
<TextBlock Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Text="Y Min:" />
<TextBox x:Name="YMinTextBox"
Grid.Row="1"
Grid.Column="1"
IsReadOnly="True"
Text="" />
<TextBlock Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
Text="X Max:" />
<TextBox x:Name="XMaxTextBox"
Grid.Row="2"
Grid.Column="1"
IsReadOnly="True"
Text="" />
<TextBlock Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Text="Y Max:" />
<TextBox x:Name="YMaxTextBox"
Grid.Row="3"
Grid.Column="1"
IsReadOnly="True"
Text="" />
</Grid>
<Button Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="10"
Padding="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Click="NewMapClicked"
Content="New Map" />
<Grid x:Name="SaveMapGrid"
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" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="Title:" />
<TextBox x:Name="TitleTextBox"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Stretch"
Text="My Map" />
<TextBlock Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Right"
Text="Description:" />
<TextBox x:Name="DescriptionTextBox"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Stretch"
Text="Authored and saved using ArcGIS Maps SDK for .NET."
TextWrapping="Wrap" />
<TextBlock Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Text="Tags:" />
<TextBox x:Name="TagsTextBox"
Grid.Row="2"
Grid.Column="1"
HorizontalAlignment="Stretch"
Text="ArcGIS, Sample" />
<Button Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,10,0,0"
Padding="5"
HorizontalAlignment="Stretch"
Click="SaveMapClicked"
Content="Save Map to Portal"
IsEnabled="{Binding ElementName=MyMapView}" />
<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>
</ScrollViewer>
<esri:MapView x:Name="MyMapView" Grid.Column="1" />
</Grid>
</UserControl>