Create and save map

View inWPFUWPFormsiOSAndroid
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.xamlAuthorMap.xaml.csSaveMapPage.xamlSaveMapPage.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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="ArcGISRuntime.Samples.AuthorMap.AuthorMap"
    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">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView" Grid.Row="0" />
        <ActivityIndicator
            x:Name="SaveMapProgressBar"
            Grid.Row="1"
            IsRunning="True"
            IsVisible="False" />
        <ListView
            x:Name="LayersList"
            Grid.Row="0"
            Grid.RowSpan="2"
            IsVisible="False"
            ItemTapped="LayerSelected" />
        <Grid
            x:Name="OAuthSettingsGrid"
            Grid.Row="0"
            HorizontalOptions="Center"
            VerticalOptions="Center"
            WidthRequest="300">
            <Grid.RowDefinitions>
                <RowDefinition Height="60" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label
                Grid.Row="0"
                Grid.ColumnSpan="2"
                HorizontalOptions="Center"
                Text="OAuth Settings"
                VerticalOptions="Start" />
            <Label
                Grid.Row="1"
                HorizontalOptions="End"
                Text="Client ID:"
                VerticalOptions="Center" />
            <Entry
                x:Name="ClientIDEntry"
                Grid.Row="1"
                Grid.Column="1"
                HorizontalOptions="Start"
                Placeholder="mYCl1enTiD"
                VerticalOptions="Center"
                WidthRequest="240" />
            <Label
                Grid.Row="2"
                HorizontalOptions="End"
                Text="Redirect URL:"
                VerticalOptions="Center" />
            <Entry
                x:Name="RedirectUrlEntry"
                Grid.Row="2"
                Grid.Column="1"
                HorizontalOptions="Start"
                Placeholder="http://my.redirect/url"
                VerticalOptions="Center"
                WidthRequest="240" />
            <Button
                Grid.Row="3"
                Grid.Column="0"
                Clicked="OAuthSettingsCancel"
                HorizontalOptions="End"
                Text="Cancel"
                VerticalOptions="End" />
            <Button
                Grid.Row="3"
                Grid.Column="1"
                Clicked="SaveOAuthSettings"
                HorizontalOptions="CenterAndExpand"
                Text="Use Settings"
                VerticalOptions="End" />
        </Grid>
        <Grid Grid.Row="2" Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button
                Grid.Column="0"
                Clicked="ShowLayerList"
                Text="Basemap" />
            <Button
                Grid.Column="1"
                Clicked="ShowLayerList"
                Text="Layers" />
            <Button
                Grid.Column="2"
                Clicked="NewMapButtonClick"
                Text="New" />
            <Button
                Grid.Column="3"
                Clicked="ShowSaveMapUI"
                Text="Save" />
        </Grid>
    </Grid>
</ContentPage>

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