Generate offline map with local basemap

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Use the OfflineMapTask to take a web map offline, but instead of downloading an online basemap, use one which is already on the device.

Image of Generate offline map with local basemap

Use case

Reasons to use a basemap which is already on the device, rather than downloading:

  • You want to limit the total download size.
  • You want to be able to share a single set of basemap files between many offline maps.
  • You want to use a custom basemap (for example authored in ArcGIS Pro) which is not available online.
  • You do not wish to sign into ArcGIS.com in order to download Esri basemaps.

The author of a web map can support the use of basemaps which are already on a device by configuring the web map to specify the name of a suitable basemap file. This could be a basemap which:

  • Has been authored in ArcGIS Pro to make use of your organizations custom data.
  • Is available as a PortalItem which can be downloaded once and re-used many times.

How to use the sample

  1. Use the button to start taking the map offline.
  2. Specify whether to download the basemap or use a basemap already taken offline.
  3. If you choose to download the online basemap, the offline map will be generated with the same (topographic) basemap as the online web map.
  4. To download the Esri basemap, you may be prompted to sign in to ArcGIS.com.
  5. If you choose to use the basemap from the device, the offline map will be generated with the local imagery basemap. The download will be quicker since no tiles are exported or downloaded.
  6. Since the application is not exporting online ArcGIS Online basemaps you will not need to log-in.

How it works

The sample creates a PortalItem object using a web map's ID. This portal item is used to initialize an OfflineMapTask object. When the button is clicked, the sample requests the default parameters for the task, with the selected extent, by calling OfflineMapTask.CreateDefaultGenerateOfflineMapParameters.

Once the parameters are created, the application checks the GenerateOfflineMapParameters.ReferenceBasemapFilename property. The author of an online web map can configure this setting to indicate the name of a suitable basemap. In this example, the application checks the local file-system for the suggested "naperville_imagery.tpkx".

If the user chooses to use the basemap on the device, the GenerateOfflineMapParameters.ReferenceBasemapDirectory is set to the absolute path of the directory which contains the .tpkx file.

A GenerateOfflineMapJob is created by calling OfflineMapTask.GenerateOfflineMap passing the parameters and the download location for the offline map.

When the GenerateOfflineMapJob is started it will check whether GenerateOfflineMapParameters.ReferenceBasemapDirectory has been set. If this property is set, no online basemap will be downloaded and instead, the mobile map will be created with a reference to the .tpkx on the device.

Relevant API

  • GenerateOfflineMapJob
  • GenerateOfflineMapParameters
  • GenerateOfflineMapResult
  • OfflineMapTask

Offline data

This sample uses naperville_imagery.tpkx. It is downloaded from ArcGIS Online automatically before the sample runs.

Tags

basemap, download, local, offline, save, web map

Sample Code

OfflineBasemapByReference.xamlOfflineBasemapByReference.xamlOfflineBasemapByReference.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
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
<ContentPage x:Class="ArcGISRuntimeXamarin.Samples.OfflineBasemapByReference.OfflineBasemapByReference"
             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>
        <esriUI:MapView x:Name="MyMapView" />
        <Frame x:Name="TakeOfflineArea"
               Margin="30"
               Padding="20"
               BackgroundColor="White"
               BorderColor="Black"
               HorizontalOptions="End"
               VerticalOptions="Start"
               WidthRequest="375">
            <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
                <Button Clicked="TakeMapOfflineButton_Click"
                        IsEnabled="True"
                        Text="Take map offline"
                        WidthRequest="250" />
            </StackLayout>
        </Frame>
        <Frame x:Name="MessageArea"
               Margin="30"
               Padding="5"
               BackgroundColor="White"
               BorderColor="Black"
               HorizontalOptions="End"
               IsVisible="False"
               VerticalOptions="Start"
               WidthRequest="450">
            <StackLayout>
                <Label Margin="10"
                       HorizontalOptions="Center"
                       Text="Map is offline!"
                       VerticalOptions="Center" />
            </StackLayout>
        </Frame>
        <Grid x:Name="BusyIndicator"
              BackgroundColor="#807f7f7f"
              IsVisible="False">
            <Grid HorizontalOptions="Center" VerticalOptions="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Label Margin="10"
                       FontSize="18"
                       HorizontalOptions="Center"
                       TextColor="White"
                       VerticalOptions="Center">
                    <Label.FormattedText>
                        <FormattedString>
                            <Span Text="Generating offline map... " />
                            <Span x:Name="Percentage" Text="" />
                        </FormattedString>
                    </Label.FormattedText>
                </Label>
                <ProgressBar x:Name="ProgressBar"
                             Grid.Row="1"
                             Margin="0,0,0,10"
                             HeightRequest="10"
                             HorizontalOptions="Center"
                             IsEnabled="True"
                             VerticalOptions="Center"
                             WidthRequest="100" />
                <Button Grid.Row="2"
                        Clicked="CancelJobButton_Click"
                        HorizontalOptions="Center"
                        Text="Cancel"
                        WidthRequest="100" />
            </Grid>
        </Grid>
        <Grid x:Name="LoadingIndicator"
              BackgroundColor="#807f7f7f"
              IsVisible="True">
            <Grid HorizontalOptions="Center" VerticalOptions="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Label Margin="10"
                       FontSize="18"
                       Text="Loading online map..."
                       TextColor="White" />
                <ProgressBar Grid.Row="1"
                             HeightRequest="10"
                             HorizontalOptions="Center"
                             IsEnabled="True"
                             VerticalOptions="Center"
                             WidthRequest="100" />
            </Grid>
        </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.