There are two main workflows you can use to deploy offline data. One option is to copy your data to a known location on your device and use the AppStudio Framework to determine the storage location. The second option is to bundle your data as a Qt resource within the app and copy the data out to a known location once the app is installed onto the device. This topic outlines the steps for each of these workflows.
Manually deploy data with your app
To manually deploy data to your device, follow these steps:
-
Author your TPKs, geodatabases, offline locators, and offline network datasets in ArcGIS Pro.
-
When you reference these files in QML code, refer to the relative location where your data will be stored.
Use dark colors for code blocks Copy import ArcGIS.AppFramework 1.0 property string localTPK: AppFramework.userHomePath + "/ArcGIS/Runtime/data/Topographic.tpk"
-
Before building your app, in the Settings tool accessible in the side panel, choose to enable External Storage on the Capabilities tab.
-
Using a file explorer app, copy the data to the specified data location.
Each operating system has a similar but slightly different data location as follows:
- Android:
Android/data/
.<your _app >/files/ ArcGI S/ Runtime/ Data - iOS:
<your
._app >/ Documents/ ArcGI S/ Runtime/ Data - macOS:
~/
.ArcGI S/ Runtime/ Data - Windows:
%userprofile%\
.ArcGI S\ Runtime\ Data - Ubuntu:
$
.HOM E/ ArcGI S/ Runtime/ Data
- Android:
By ensuring data is stored in these locations, and using the App
function, you can be sure that your app can read and write data on any deployed operating system.
Bundle your data as a Qt resource
Although Qt supports reading from embedded resources, Esri's underlying Runtime Core does not, as it relies on standard C I/O, which doesn't support Qt resources. This means that you can bundle your offline data with your app for deployment, but you'll need to copy the data from the embedded resource to a physical location on the device. The AppStudio Framework contains a copy
function that copies files from the embedded resource file to a physical location.
To bundle your data with your app, do the following:
-
Add a JavaScript function to your app that uses the
copy
function and returns the path to your output data.File -
Set the path property of your component equal to the JavaScript function that performs the copy.
When your app launches, it executes the
copy
function, and the component that uses the local data loads properly.File -
Before building your app, in the side panel, go to Settings > Capabilities, and enable External Storage.
The following code demonstrates copying data from the embedded resource to a physical location. You must add the source file (in this sample, Topographic.tpk
) to your project, in a subfolder named Data, for this code sample to work.
import QtQuick 2.7
import QtQuick.Controls 2.1
import ArcGIS.AppFramework 1.0
import Esri.ArcGISRuntime 100.8
App {
id: app
width: 640 * AppFramework.displayScaleFactor
height: 480 * AppFramework.displayScaleFactor
property string fileName: "Topographic.tpk"
property FileFolder sourceFolder: app.folder.folder("Data")
property FileFolder destFolder: AppFramework.userHomeFolder.folder("ArcGIS/Runtime/Data")
property string destPath: destFolder.filePath(fileName)
property url destUrl: destFolder.fileUrl(fileName)
function copyLocalData() {
destFolder.makeFolder();
sourceFolder.copyFile(fileName, destPath);
return destUrl;
}
MapView {
anchors.fill: parent
Map {
Basemap {
ArcGISTiledLayer {
url: copyLocalData()
}
}
}
}
}
The output location of this example for each platform is the same as what's listed in the Manually deploy data with your app section above. This workflow works best with smaller files (for example, small geodatabases or TPKs); for performance reasons, it is not recommended for large datasets.