What is offline data?
Offline data is data that is generated and downloaded from a data service, or from the basemap styles service.
You can use offline data to build applications that:
- Support disaster recovery operations when infrastructure has been damaged.
- Enable mobile workers to collect and edit data.
- Provide current, detailed maps to large workforces.
- Display offline vector tile or image tile basemap layers.
How offline data works
To use offline data, you start with a reference to a service. The following services can be used to generate offline data:
- The basemap styles service (including default basemap styles and custom basemap styles created using the Vector Tile Style Editor).
- A feature service that has been offline enabled (including related records and attachments).
- A vector tile service that has been offline enabled.
- An image tile service that has been offline enabled.
Offline data for a requested geographic area is generated by the service and downloaded to a device. It can then be used without a network connection.
There are two types of offline data:
-
Tile data, created from one of the following service types and downloaded as a read-only package of static tiles. Depending on the type of service, tiles will be downloaded as vector tiles or image tiles.:
Source tile service type Downloaded files Basemap styles service (vector basemap layer) VTPK + Item Resource Cache Basemap styles service (image basemap layer) TPK Custom basemap style created with the Vector Tile Style Editor VTPK + Item Resource Cache Offline enabled vector tile service VTPK Offline enabled image tile service TPK -
Feature data, created from a feature service. The offline data is downloaded as a geodatabase file that can contain data for feature layers, non-spatial tables, and attachments. This data can be created, updated, or deleted according to the capabilities of the source feature service. Offline data edits can be synchronized with the source feature service whenever a network connection is available. To support offline data, the feature service must be sync enabled.
The typical steps to download offline data are:
- Reference an offline enabled service. The basemap styles service and custom basemap styles are always offline enabled.
- Download an area of the service.
Download
Use a reference to an offline enabled service and request offline data for a geographic area. The service will generate offline data which you can then download to your device.
You specify where to store downloaded offline data on the local device. Offline data remains on the device until you explicitly delete it from the device's file system.
Depending on the type of service, offline data is downloaded as feature data, vector tiles, or image tiles:
How to download offline data
Offline data is downloaded from a feature service as a geodatabase file.
The steps to download offline data from a feature service are:
- Create a Geodatabase Sync Task referencing the feature service.
GeodatabaseSyncTask geodatabaseSyncTask = await GeodatabaseSyncTask.CreateAsync(featureServiceUrl);
- Use the Geodatabase Sync Task to create a Generate Geodatabase Job specifying the requested geographic area, and the download location for the geodatabase file that will be created.
GenerateGeodatabaseParameters gdbParams = await geodatabaseSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(areaOfInterest);
GenerateGeodatabaseJob generateJob = geodatabaseSyncTask.GenerateGeodatabase(gdbParams, "path\\to\\file.geodatabase");
- Start the job and wait for it to complete, returning a ready to use Geodatabase that references the downloaded geodatabase file. Use this to access Geodatabase Feature Tables which can be queried and edited. You can use a Geodatabase Feature Table to create an Feature Layer, which can be added to a map.
Geodatabase generateResult = await generateJob.GetResultAsync();
Offline data is downloaded from a vector tile service or the basemap styles service as a vector tile package (VTPK) and typically an item resource cache.
Most default basemap styles and all custom basemap styles are downloaded as a vector tile package and an item resource cache.
The following default basemap styles cannot be downloaded as a vector tile package, and are downloaded as an image tile package:
ArcGIS:
Imagery ArcGIS:
Imagery: Standard ArcGIS:
Hillshade: *
The steps to download offline data as a vector tile package (VTPK) are:
- Create an Export Vector Tiles Task referencing the vector tile service or basemap styles service.
ExportVectorTilesTask exportVectorTilesTask = await ExportVectorTilesTask.CreateAsync(vectorServiceUri);
- Use the Export Vector Tiles Task to create an Export Vector Tiles Job specifying the requested geographic area, and the download location for both the VTPK and the item resource cache that will be created. When downloading vector tiles from the basemap styles service, by default the item resource cache will include a full set of fonts for multiple languages. Applications that only need Latin fonts can opt-in to downloading a smaller set of fonts. This typically reduces the size of the downloaded fonts by about 80MB.
ExportVectorTilesParameters exportVectorTilesParams = await exportVectorTilesTask.CreateDefaultExportVectorTilesParametersAsync(areaOfInterest, 0);
ExportVectorTilesJob exportVectorTilesJob = exportVectorTilesTask.ExportVectorTiles(exportVectorTilesParams, "path\\to\\file.vtpk", "\\path\\to\\cache\\dir");
- Start the job and wait for it to complete, returning a ready to use Vector Tile Cache that references the downloaded VTPK file and an Item Resource Cache that references the downloaded item resource cache. Use these to create an ArcGIS Vector Tiled Layer which can be added to a map.
ExportVectorTilesResult vectorExportResult = await exportVectorTilesJob.GetResultAsync();
ArcGISVectorTiledLayer vectorTileLayer = new ArcGISVectorTiledLayer(vectorExportResult.VectorTileCache, vectorExportResult.ItemResourceCache);
Offline data is downloaded from an image tile service or the basemap styles service as an image tile package (TPK).
The following default basemap styles are downloaded as an image tile package:
ArcGIS:
Imagery ArcGIS:
Imagery: Standard ArcGIS:
Hillshade: *
Other default basemap styles and all custom basemap styles are downloaded as a vector tile package and an item resource cache.
The steps to download offline data as an image tile package (TPK) are:
- Create an Export Tile Cache Task referencing the image tile service or basemap styles service.
ExportTileCacheTask exportImageTilesTask = await ExportTileCacheTask.CreateAsync(imageTileUrl);
- Use the Export Tile Cache Task to create an Export Tile Cache Job specifying the requested geographic area, minimum and maximum scales to include image tiles, and the download location for the tile package that will be created. The minimum scale is particularly important as the number of image tiles that are included goes up exponentially as you zoom further into the map, increasing the size of the offline data TPK and the time it takes to generate it.
ExportTileCacheParameters exportImageTileParams = await exportImageTilesTask.CreateDefaultExportTileCacheParametersAsync(
areaOfInterest: areaOfInterest,
minScale: 500_000_000,
maxScale: 10_000_000);
ExportTileCacheJob exportImageTilesJob = exportImageTilesTask.ExportTileCache(exportImageTileParams, "\\path\\to\\file.tpk");
- Start the job and wait for it to complete, returning a ready to use Tile Cache that references the downloaded TPK file. Use this to create an ArcGIS Tiled Layer which can be added to a map.
TileCache exportImageTileCacheResult = await exportImageTilesJob.GetResultAsync();
ArcGISTiledLayer imageTiledLayer = new ArcGISTiledLayer(exportImageTileCacheResult);
Access
When you first download offline data the ArcGIS Maps SDKs for Native Apps provides you with a ready-to-use API reference to the offline data. To access previously downloaded offline data, you must create this API reference directly.
How to access offline data
Access previously downloaded offline data from a feature service by creating a Geodatabase from the downloaded geodatabase file:
Geodatabase offlineGeodatabase = await Geodatabase.OpenAsync("path\\to\\file.geodatabase");
Use the Geodatabase to create Geodatabase Feature Tables which can be queried and edited. A Geodatabase Feature Table can be used to create a Feature Layer which can be added to a map.
The steps to access previously downloaded offline data from a VTPK are:
- Create a Vector Tile Cache from the downloaded VTPK file.
- Optionally create an Item Resource Cache from the downloaded item resource cache folder.
VectorTileCache vectorTileCache = await VectorTileCache.CreateAsync("\\path\\to\\file.vtpk");
ItemResourceCache itemResourceCache = new ItemResourceCache("\\path\\to\\cache\\dir");
ArcGISVectorTiledLayer offlineVectorTileLayer = new ArcGISVectorTiledLayer(vectorTileCache, itemResourceCache);
Use the Vector Tile Cache and optional Item Resource Cache to create an ArcGIS Vector Tiled Layer which can be added to a map
Access previously downloaded offline data from an image tile package (TPK) by creating a Tile Cache from the downloaded TPK file:
TileCache offlineTileCache = new TileCache("\\path\\to\\file.tpk");
ArcGISTiledLayer reopenedImagedTileLayer = new ArcGISTiledLayer(offlineTileCache);
Use the Tile Cache to create an ArcGIS Tiled Layer which can be added to a map.
Edit
You can edit offline data from a feature service if the source feature service allows editing. To learn more, see Editing offline data.
Synchronize
Offline data from a feature service can be synchronized with its source service.
You can choose whether to:
- Upload edits from offline data to the source feature service.
- Download edits from the source feature service to the offline data.
- Both upload and download (bidirectional sync). This is the default.
To synchronize offline data with its source feature service, a network connection is required.
How to synchronize offline data
- Create an Geodatabase Sync Task referencing the source feature service for the offline data.
Uri serviceUrl = offlineGeodatabase.Source;
GeodatabaseSyncTask gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(serviceUrl);
- Use the Geodatabase Sync Task to create a Geodatabase Sync Job by providing the previously downloaded Geodatabase.
SyncGeodatabaseParameters offlineSyncParams = await gdbSyncTask.CreateDefaultSyncGeodatabaseParametersAsync(offlineGeodatabase);
SyncGeodatabaseJob syncJob = gdbSyncTask.SyncGeodatabase(offlineSyncParams, offlineGeodatabase);
- Start the job. If it completes without errors, the offline data and feature service will be in sync.
Synchronization errors typically occur because of network connectivity issues during the sync process. The synchronization mechanism is robust to these types of errors, however, and they can be resolved by synchronizing again when a reliable network connection becomes available.
If you encounter a synchronization error, you can safely continue to view and edit the offline data until you are able to synchronize again.
IReadOnlyList<SyncLayerResult> syncResult = await syncJob.GetResultAsync();
if (syncJob.Status != Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded)
{
// Handle errors
}
Synchronization conflicts
If there are attribute or geometry level conflicts on a feature during synchronization, the most recently synchronized edit will be applied. For example, if both user A and user B edit the same feature while offline, if user A synchronizes their edits first, then user B synchronizes their edits, the updated feature will represent the edits made by user B.
Unregister
When you download offline data from a feature service, the offline data is registered with the feature service. This allows the feature service to track edits and compare its state with the offline data, and enables synchronizing the offline data with the feature service. When the offline data is no longer needed, you should unregister it to clean up the tracking metadata stored on the feature service.
How to unregister downloaded offline data from a feature service
Offline data from a feature service is downloaded as a geodatabase file. The steps to unregister it are:
- Create a Geodatabase from the downloaded geodatabase file.
- Load the Geodatabase.
- Read the Sync Enabled property of the Geodatabase. If this is false, no further action is needed.
- Get the feature service URL from the Geodatabase.
- Create a Geodatabase Sync Task with the feature service URL to reference the source feature service for the geodatabase.
- Use the Geodatabase Sync Task to unregister the geodatabase from the source feature service.
Code examples
Download a vector tile basemap layer
Use the Export Vector Tile Task to download a geographic area of a hosted vector tile layer with a custom style.
Create and start an Export Vector Tiles Job to generate and download the tiles and custom style. When the job completes, you will receive a result object containing a reference to the downloaded vector tile package (VTPK) of tiles, and the item resource cache for the custom style. You can use these to create a Vector Tile Layer, and set that as the basemap of the Map being displayed in a Map View:
- Create an Export Vector Tiles Task referencing the hosted vector tile layer item.
- Get a set of default parameters to download the area of interest, specifying the largest scale content detail to include.
- Create an Export Vector Tiles Job.
- Start the job and wait for it to complete.
var areaOfInterest = new Envelope(new MapPoint(-118.542587, 34.391663, SpatialReferences.Wgs84), 5, 5);
areaOfInterest = (Envelope)GeometryEngine.Project(areaOfInterest, SpatialReferences.WebMercator);
PortalItem hostedItem = await PortalItem.CreateAsync(await ArcGISPortal.CreateAsync(), "46a87c20f09e4fc48fa3c38081e0cae6");
ExportVectorTilesTask exportVectorTileCacheTask = await ExportVectorTilesTask.CreateAsync(hostedItem);
ExportVectorTilesParameters exportVectorTilesParams = await exportVectorTileCacheTask.CreateDefaultExportVectorTilesParametersAsync(
areaOfInterest: areaOfInterest,
maxScale: 100);
ExportVectorTilesJob exportJob = exportVectorTileCacheTask.ExportVectorTiles(
parameters: exportVectorTilesParams,
vectorTileCachePath: "path\\to\\something.vtpk",
itemResourceCachePath: "path\\to\\cache\\dir");
ExportVectorTilesResult exportResult = await exportJob.GetResultAsync();
var offlineVectorTileLayer = new ArcGISVectorTiledLayer(
vectorTileCache: exportResult.VectorTileCache,
itemResourceCache: exportResult.ItemResourceCache
);
MainMapView.Map.Basemap = new Basemap(offlineVectorTileLayer);
Download offline data from a feature service
Use the Geodatabase Sync Task to download a geographic area of a hosted feature layer.
Create and start a Generate Geodatabase Job to generate and download a geodatabase file of offline data. When the job completes, you will receive a Geodatabase object referencing the downloaded geodatabase file. You can access tables of feature data to create Feature Layers and add them to the Map being displayed in a Map View:
- Create a Geodatabase Sync Task referencing the hosted feature layer item.
- Get a set of default parameters to download the area of interest, and modify them to not download attachments.
- Create a Generate Geodatabase Job.
- Start the job and wait for it to complete.
MainMapView.Map = new Map(BasemapStyle.ArcGISStreets);
var areaOfInterest = new Esri.ArcGISRuntime.Geometry.Polygon(new [] {
new MapPoint(-88.153245, 41.778064, SpatialReferences.Wgs84),
new MapPoint(-88.146708, 41.778870, SpatialReferences.Wgs84),
new MapPoint(-88.145878, 41.769764, SpatialReferences.Wgs84),
new MapPoint(-88.153431, 41.770330, SpatialReferences.Wgs84)
});
var featureServiceUri = new Uri("https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/WaterDistributionNetwork/FeatureServer");
GeodatabaseSyncTask geodatabaseSyncTask = await GeodatabaseSyncTask.CreateAsync(featureServiceUri);
GenerateGeodatabaseParameters gdbGenerateParameters
= await geodatabaseSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(areaOfInterest.Extent);
gdbGenerateParameters.ReturnAttachments = false;
GenerateGeodatabaseJob job = geodatabaseSyncTask.GenerateGeodatabase(gdbGenerateParameters, "path\\to\\file.geodatabase");
// Optionally listen for progress changes
job.ProgressChanged += (o,e) => { };
Geodatabase generateResult = await job.GetResultAsync();
MainMapView.Map.OperationalLayers.AddRange(generateResult.GeodatabaseFeatureTables.Select(table => new FeatureLayer(table)));
MainMapView.SetViewpointGeometryAsync(areaOfInterest, 50);