View on GitHub Sample viewer app

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

Use case

There are a number of use-cases where you may wish 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 organization’s custom data.
  • Is available as a PortalItem which can be downloaded once and re-used many times.

How to use the sample

  1. Click on “Generate Offline Map”.
  2. You will be prompted to choose whether you wish to download the online basemap or use the “naperville_imagery.tpkx” basemap which is already on the device.
  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. 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.
  5. Since the application is not exporting online ArcGIS Online basemaps you will not need to log-in.

How it works

  1. 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.
  2. 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.
  3. A GenerateOfflineMapJob is created by calling OfflineMapTask::generateOfflineMap passing the parameters and the download location for the offline map.
  4. 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

Read more about how to set up the sample’s offline data here.

LinkLocal Location
Naperville Imagery Tile Package<userhome>/ArcGIS/Runtime/Data/tpkx/naperville_imagery.tpkx

Tags

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

Sample Code

DownloadButton.qml DownloadButton.qml GenerateOfflineMapLocalBasemap.cpp GenerateOfflineMapLocalBasemap.h GenerateOfflineMapLocalBasemap.qml GenerateWindow.qml main.cpp
// Copyright 2019 Esri.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import QtQuick
// Create the download button to export the tile cache
Rectangle {
property bool pressed: false
signal buttonClicked()
width: 190
height: 35
color: pressed ? "#959595" : "#D6D6D6"
radius: 5
border {
color: "#585858"
width: 1
}
Row {
anchors.fill: parent
spacing: 5
Image {
width: 38
height: width
source: "qrc:/Samples/Maps/GenerateOfflineMapLocalBasemap/download.png"
}
Text {
anchors.verticalCenter: parent.verticalCenter
text: "Generate Offline Map"
font.pixelSize: 14
color: "#474747"
}
}
MouseArea {
anchors.fill: parent
onPressed: downloadButton.pressed = true
onReleased: downloadButton.pressed = false
onClicked: {
buttonClicked();
}
}
}