Work with offline data

Consider taking individual layers offline as offline data if you want to construct the map or scene yourself and provide users with up-to-date information from ArcGIS Online or ArcGIS Enterprise. This topic describes how to generate and download offline data to use the following layers offline:

You can export and download tiled layer caches locally and access them while your device is offline. It is important to note that you cannot edit tiled layer data (vector tiled data and image tiled data). If you require updates to the tiled layer data, you must export and download them again.

Feature and annotation layers

You can take features (including annotation, related records, and attachments) offline, from a feature service, by downloading them to geodatabase feature tables within a mobile geodatabase. To do this, the feature service must be hosted on ArcGIS Enterprise 10.2.2 or later for features or from a service hosted in ArcGIS Online, provided that the feature service has been sync enabled (allow disconnected editing with synchronization).

You can use an existing feature service or create features services for your own data. To enable sync for a feature service, do the following:

  • ArcGIS Online — Edit the feature service item and check the Sync check box.
  • ArcGIS Enterprise — See Prepare data for offline use in the ArcGIS Server documentation.

To create the mobile geodatabase, you must do the following:

  1. Generate geodatabase parameters and define the area of interest, the layers, any expression filters, and so on, if required.
  2. Create the geodatabase, populate it with all the relevant features, and download it to the user's device.

Generate geodatabase parameters

When you create a mobile geodatabase, you must provide a set of parameters, described below, to define exactly which data is downloaded.

  • The geographical area of interest. You typically supply the area of interest as an extent (in other words, an envelope) but point, line, and polygon (including multipart) geometries are also supported. This allows you to create more detailed areas of interest. Regardless of the geometry, any features that intersect with the supplied area of interest are extracted.
  • The spatial reference of the mobile geodatabase.
  • Individual layers can be managed using the GenerateGeodatabaseParameters.getLayerOptions() property:
    • Determine which layers are included in the mobile geodatabase.
    • Subset the features by providing an expression that filters features by attribute values, such as ZONE = 'COM'.
    • The synchronization model controls how edits made to the mobile geodatabase are applied back to the feature service during synchronization. The model supported is defined by the data that was used to create the sync-enabled feature service. If the data is nonversioned, the synchronization model is per layer. This is the most flexible model, allowing you to synchronize on a layer-by-layer basis, based on the layers you specify. If the data is versioned, the synchronization model is per geodatabase. This synchronizes the entire geodatabase, including all layers and tables, at once.
    • Specify whether to include feature attachments in the mobile geodatabase and whether they can be uploaded during synchronization.
    • Identify whether tables related to the layer are also included in the geodatabase.

You can obtain a default set of parameters ( GenerateGeodatabaseParameters ) using the createDefaultGenerateGeodatabaseParametersAsync method on the GeodatabaseSyncTask . If you provide the area of interest, the default parameters will be generated taking into account the capabilities supported by the ArcGIS feature service. You can update these default parameter values before creating the geodatabase.

Java
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
// instantiate the geodatabase sync task
String url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/SaveTheBaySync/FeatureServer";
GeodatabaseSyncTask geodatabaseSyncTask = new GeodatabaseSyncTask(url);

// define an extent within which the features are included
Envelope dataExtent = (Envelope) mapView.getCurrentViewpoint(Viewpoint.Type.BOUNDING_GEOMETRY).getTargetGeometry();

// get the default parameters for generating a geodatabase
ListenableFuture   geodatabaseParametersFuture =
        geodatabaseSyncTask.createDefaultGenerateGeodatabaseParametersAsync(dataExtent);
geodatabaseParametersFuture.addDoneListener(() -> {
  try {
    GenerateGeodatabaseParameters generateGdbParams = geodatabaseParametersFuture.get();

    // set the synchronization model per layer
    generateGdbParams.setSyncModel(SyncModel.PER_LAYER);

    // define the layers and features to use
    int marineLayerId = 0;
    int birdsLayerId = 1;
    String dolphinsOnlyWhereClause = "type = 11";

    // clear and repopulate the layer options
    generateGdbParams.getLayerOptions().clear();
    generateGdbParams.getLayerOptions().add(new GenerateLayerOption(marineLayerId, dolphinsOnlyWhereClause));
    generateGdbParams.getLayerOptions().add(new GenerateLayerOption(birdsLayerId, true));

    // do not return attachments
    generateGdbParams.setReturnAttachments(false);

    // create the generate geodatabase job, passing in the arguments and an output path for the local geodatabase
    // ...
  } catch (InterruptedException | ExecutionException e) {
    // deal with exception appropriately...
  }
});

Create the geodatabase

Obtain a job to generate and download the geodatabase by passing the GenerateGeodatabaseParameters to the GeodatabaseSyncTask.generateGeodatabase() method on the GeodatabaseSyncTask class. Run the job to generate and download the geodatabase to the device.

Java
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
// Instantiate the geodatabase sync task and define the task parameters (see previous example).

// Create the generate geodatabase job, pass in the parameters and an output path for the local geodatabase.
final GenerateGeodatabaseJob generateGdbJob =
        gdbSyncTask.generateGeodatabase(generateGdbParams, "local/path/to/store/.geodatabase");

// handle the JobChanged event to check the status of the job
generateGdbJob.addJobChangedListener(() -> {
  System.out.println("Job Status: " + generateGdbJob.getStatus().name());
  if (generateGdbJob.getError() != null) {
    System.out.println("Error Message: " + generateGdbJob.getError().getMessage());
  }

  // check the job status
  if (generateGdbJob.getStatus() == Job.Status.SUCCEEDED) {
    // if the job succeeded, call a method to add local data to the map
    addLocalLayerToMap();
  } else if (generateGdbJob.getStatus() == Job.Status.FAILED) {
    // if the job failed, report failure
    System.out.println("Unable to create local geodatabase.");
  } else {
    // the job is still running, report last message
    System.out.println(generateGdbJob.getMessages().get(generateGdbJob.getMessages().size() - 1));
  }
});
// start the job and display job id
generateGdbJob.start();
System.out.println("Submitted job #" + generateGdbJob.getServerJobId() + " to create local geodatabase");

If you generate the geodatabase using these methods, it will automatically register the geodatabase with its original service. This allows the data in the geodatabase to be synchronized with the original service. If you want to load this geodatabase onto a number of devices and allow those users to synchronize changes with the original service, you must register these individual geodatabases with the original service.

Create layers from geodatabase feature tables

Java
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
// get the local geodatabase from the job result
Geodatabase geodatabase = generateGeodatabaseJob.getResult();

// load the geodatabase
geodatabase.loadAsync();
geodatabase.addDoneLoadingListener(() -> {
  if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {
    // create a new feature layer for each feature table in the local geodatabase
    for (FeatureTable featureTable : geodatabase.getGeodatabaseFeatureTables()) {
      FeatureLayer featureLayer = new FeatureLayer(featureTable);
      mapView.getMap().getOperationalLayers().add(featureLayer);
    }
    // Create an annotation layer from each feature table that contains annotation
    // NOTE: Annotations are stored in ArcGISFeatureTables rather than the more generic FeatureTables
    for (ArcGISFeatureTable annotationFeatureTable : geodatabase.getGeodatabaseAnnotationTables()) {
      AnnotationLayer annotationLayer = new AnnotationLayer(annotationFeatureTable);
      mapView.getMap().getOperationalLayers().add(annotationLayer);
    }
  }
});

Now that you have a geodatabase on your local machine or device, you'll create the relevant layer from the geodatabase feature tables.

  1. Get the geodatabase from the generate geodatabase job.
  2. Load the geodatabase.
    1. Create feature layers from the geodatabase feature tables.
    2. Create annotation layers from the geodatabase annotation tables.

Tiled layers

Tiled layers typically provide geographical context to your map or scene as basemaps that display beneath your data layers. Tiled layers may also provide offline elevation data for visualizing 3D terrain in a scene. You can export and download tile caches directly to your device from any tiled data source that is export enabled. Esri provides a number of vector and raster basemaps for you to export and download:

Download vector tiled data

You can take vector tiled data offline by exporting it from an ArcGIS vector tile service and downloading it as a vector tile package (.vtpk) using the ExportVectorTilesTask  class. The vector tile service used for this operation must support the creation of an offline vector tile cache; specifically, it must enable the  exportTiles operation. Vector tiles contain vector representations of data that can be restyled for different purposes, such as day and night viewing. You can download default styling resources along with the vector tiles and custom style resources from ArcGIS Portal items that host vector tile layers.

You have a number of workflows available to you depending on whether your vector tiled data has custom style resources, whether you want to download many custom styles that you can apply to a number of tile caches, or whether you just want to obtain the default tile cache.

To create a vector tile package (.vtpk file) and vector tile style resources, do the following:

  1. Instantiate the export vector tiles task and check whether the vector tiles have custom style resources.
  2. Specify the export vector tiles task parameters for a specific maximum scale and area of interest.
  3. Export the vector tiles. The vector tile package is populated with vector tiles and the default style resources from the ArcGIS vector tile service.

Instantiate the export vector tiles task

Instantiate the ExportVectorTilesTask using a URL to the portal item that represents an ArcGIS vector tiled layer. Load the task, and upon completion, check whether the vector tiles have custom style resources by checking the hasStyleResources Boolean value.

Java
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
// initialize the export vector tile task with the portal item for a vector tiled layer (or a URL if only the default styles are required)
PortalItem portalItem = new PortalItem(portal, itemId);
portalItem.loadAsync();
portalItem.addDoneLoadingListener(() -> {
  if (portalItem.getLoadStatus() == LoadStatus.LOADED) {
    ExportVectorTilesTask exportVectorTileTask = new ExportVectorTilesTask(portalItem);
    exportVectorTileTask.loadAsync();
    exportVectorTileTask.addDoneLoadingListener(() -> {
      if (exportVectorTileTask.getLoadStatus() == LoadStatus.LOADED) {

        // check if the vector tile layer has style resources
        Boolean hasStyleResources = exportVectorTileTask.hasStyleResources();

        // choose whether to download just the style resources or both the styles and the tiles
        if (hasStyleResources) {
          exportVectorTilesWithCustomStyleResource(exportVectorTileTask);
        } else {
          exportVectorTilesDefaultStyleResources(exportVectorTileTask);
        }

Specify the export vector tiles task parameters

To obtain a default set of parameters, call the createDefaultExportVectorTilesParametersAsync method and provide an area of interest (polygon or envelope) and a maximum scale. When you provide the maximum scale, you must be aware that there won't be any tiles when the map is zoomed in beyond this scale. If you set the maximum scale to 0, the export will include all levels of detail in the service.

This method returns the set of default parameters, ExportVectorTilesParameters , required to export the vector tiles to a vector tile package. The LODs have been calculated to support the maximum scale that you specified.

Java
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// create the default export vector tile cache job parameters
ListenableFuture exportVectorTileParamsFuture = exportVectorTilesTask
    .createDefaultExportVectorTilesParametersAsync(mapView.getVisibleArea(), mapView.getMapScale());
exportVectorTileParamsFuture.addDoneListener(() -> {
  try {
    ExportVectorTilesParameters exportVectorTileParams = exportVectorTileParamsFuture.get();

    // create the job from the parameters and a path
    ExportVectorTilesJob exportVectorTilesJob = exportVectorTilesTask
        .exportVectorTiles(exportVectorTileParams, vectorTileCachePath);
  } catch (InterruptedException | ExecutionException e) {
    dealWithException(e); // deal with exception appropriately...
  }
});

Export the vector tiles

Obtain a job to generate and download a vector tile package and its default style resources by passing the ExportVectorTilesParameters to the exportVectorTiles method on the ExportVectorTilesTask class. You must also provide a download path to store the vector tile package and its default style resources.

Run the ExportVectorTilesJob to export and download the vector tile package (.vtpk).

Java
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
// get the job
ExportVectorTilesJob exportVectorTilesJob = exportVectorTilesTask
    .exportVectorTiles(parameters, vectorTileCachePath);
exportVectorTilesJob.addJobDoneListener(() -> {
  // get the result when ready
  if (exportVectorTilesJob.getStatus() == Job.Status.SUCCEEDED) {
    // get the result
    ExportVectorTilesResult result = exportVectorTilesJob.getResult();
    VectorTileCache vectorCache = result.getVectorTileCache();

    // create new vector tiled layer from the caches
    ArcGISVectorTiledLayer vectorLayer = new ArcGISVectorTiledLayer(vectorCache);

    // add the layer to the map's operational layers
    mapView.getMap().getOperationalLayers().add(vectorLayer);
  } else if (exportVectorTilesJob.getStatus() == Job.Status.FAILED) {
    dealWithException(exportVectorTilesJob.getError()); // deal with exception appropriately...
  }
});

// run the job
exportVectorTilesJob.start();

Export the vector tiles with custom style resources

Obtain a job to generate and download a vector tile package containing tiles and associated style resources by passing the ExportVectorTilesParameters to the exportVectorTiles method on the ExportVectorTilesTask class. The portal item's associated style resources will be downloaded and saved separately. You must also provide a download path to store the vector tile package and a separate download path for the style resources.

Run the job to export and download the vector tile package (.vtpk) and the style resources to the device.

Java
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
// get the job
ExportVectorTilesJob exportVectorTilesJob = exportVectorTilesTask
    .exportVectorTiles(parameters, vectorTileCachePath, itemResourceCachePath);
exportVectorTilesJob.addJobDoneListener(() -> {
  // get the result when ready
  if (exportVectorTilesJob.getStatus() == Job.Status.SUCCEEDED) {
    // get the result
    ExportVectorTilesResult result = exportVectorTilesJob.getResult();
    VectorTileCache vectorCache = result.getVectorTileCache();
    ItemResourceCache resourceCache = result.getItemResourceCache();

    // create new vector tiled layer from the caches
    ArcGISVectorTiledLayer vectorLayer = new ArcGISVectorTiledLayer(vectorCache, resourceCache);

    // add the layer to the map's operational layers
    mapView.getMap().getOperationalLayers().add(vectorLayer);
  } else if (exportVectorTilesJob.getStatus() == Job.Status.FAILED) {
    dealWithException(exportVectorTilesJob.getError()); // deal with exception appropriately...
  }
});

// run the job
exportVectorTilesJob.start();

Export custom style resources

Obtain a job to download any custom style resources associated with the tasks vector tiles by passing a download path to the exportStyleResourceCache method on the ExportVectorTilesTask class.

Run the job to export the style resources. Obtain the getItemResourceCache property from the ExportVectorTilesResult class.

Java
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// get the job
ExportVectorTilesJob exportVectorTilesJob = exportVectorTilesTask.exportStyleResourceCache(itemResourceCachePath);
exportVectorTilesJob.addJobDoneListener(() -> {
  // get the result when ready
  if (exportVectorTilesJob.getStatus() == Job.Status.SUCCEEDED) {
    // get the result
    ExportVectorTilesResult result = exportVectorTilesJob.getResult();
    ItemResourceCache resourceCache = result.getItemResourceCache();
  } else if (exportVectorTilesJob.getStatus() == Job.Status.FAILED) {
    dealWithException(exportVectorTilesJob.getError()); // deal with exception appropriately...
  }
});

// run the job
exportVectorTilesJob.start();

Download image tiled data

You can take image tiled data offline by exporting and downloading the image tiled data as a tile package (.tpk or .tpkx) using the ExportTileCacheTask  class. This task requires that the tiled map or image service support the creation of an offline tile cache; specifically, it must enable the exportTiles operation. This can be found at the bottom of the service's HTML page. Esri provided basemaps and elevation sources will be swapped for their export-enabled services.

To create the tile cache, do the following:

  1. Generate the default export image tile cache parameters and set any of the properties.
  2. Export and download the image tile cache using the methods on the ExportTileCacheTask .

Generate default export image tile cache parameters

Construct a default set of parameters ( ExportTileCacheParameters ) by passing an area of interest (polygon or envelope) along with the minimum and maximum scale thresholds to the createDefaultExportTileCacheParametersAsync method on the ExportTileCacheTask class.

This method will return a set of parameters for the area of interest and will calculate the levels of detail (LODs) required to support the minimum and maximum scale for the service's tiling scheme. You can adjust these LOD levels or remove some before you download the cache.

Java
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
// instantiate the export task with the URL to the tiled service
ExportTileCacheTask exportTileCacheTask = new ExportTileCacheTask(tiledLayer.getUri());
exportTileCacheTask.loadAsync();

exportTileCacheTask.addDoneLoadingListener(() -> {
  if (exportTileCacheTask.getLoadStatus() == LoadStatus.LOADED) {
    // create the export tile cache parameters
    ListenableFuture parametersFuture = exportTileCacheTask
        .createDefaultExportTileCacheParametersAsync(mapView.getVisibleArea(), 2000000, 1000000);
    // get the export tile cache parameters
    parametersFuture.addDoneListener(() -> {
      try {
        ExportTileCacheParameters parameters = parametersFuture.get();
        exportDownloadRasterTileCache(exportTileCacheTask, parameters);
      } catch (InterruptedException | ExecutionException e) {
        dealWithException(e); // deal with exception appropriately...
      }
    });
  } else if (exportTileCacheTask.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
    dealWithException(exportTileCacheTask.getLoadError()); // deal with exception appropriately...
  }
});

Export and download the image tile cache

Obtain an export and download job by passing the ExportTileCacheParameters to the exportTileCache method on the ExportTileCacheTask class. Run the job to download the tile cache into a tile package that is placed in the download path on the device.

Java
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// get the job
ExportTileCacheJob exportTileCacheJob = exportTileCacheTask.exportTileCacheAsync(parameters, fileNameWithPath);

// handle status changes
exportTileCacheJob.addJobChangedListener(() -> {
  // add the exported tiles to the map
  if (exportTileCacheJob.getStatus() == Job.Status.SUCCEEDED) {
    TileCache tileCache = exportTileCacheJob.getResult();
    ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
    mapView.setMap(new ArcGISMap(new Basemap(tiledLayer)));
  } else if (exportTileCacheJob.getStatus() == Job.Status.FAILED) {
    dealWithException(exportTileCacheJob.getError()); // deal with exception appropriately...
  }
});

// run the job
exportTileCacheJob.start();

The tile cache from an exported basemap tile layer can be used in your map or scene:

Kotlin
Use dark colors for code blocksCopy
1
2
3
4
// Use the tile cache to create an ArcGISTiledLayer.
val tiledLayer = ArcGISTiledLayer(myTileCache)
// Display the tiled layer as a basemap.
myMapView.map = ArcGISMap(Basemap(tiledLayer))

The tile cache from exported elevation data can be used as an elevation source in your scene:

Kotlin
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
// get full path to the tile cache's local tile package
val localTilePackagePath = getExternalFilesDir(null)?.path + "TestData" + getString(R.string.local_tile_package_location)
val localElevationSource = ArcGISTiledElevationSource(localTilePackagePath)

val elevationSurface = Surface()
elevationSurface.elevationSources.add(localElevationSource)
val scene = ArcGISScene()
scene.baseSurface = elevationSurface
mySceneView.scene = scene

When creating an offline tile cache from a tiled service, consider the following:

  • The export tiles operation used to generate tile caches is only available with services hosted on ArcGIS Server 10.2.1 or later.
  • Estimation of tile cache size is not available on ArcGIS Online hosted tiled services.
  • The time required to create a tile cache varies depending on the extent requested, the number of levels requested, the network connection speed, and so on. Use the estimateTileCacheSize method on the  ExportTileCacheTask  class, which returns an  EstimateTileCacheSizeJob  to get the approximate size of a tile cache for a specific set of parameters. Try generating a smaller tile cache to get an idea of how long caching will take when planning a large offline data capture event.
  • There is a limit to the number of tiles you can generate in a single request. When generating a tile cache from an ArcGIS Online basemap, there is a limit of 100,000 tiles per request. Read more on this in the ArcGIS REST API documentation. Organizations that use their own ArcGIS Server to host an offline tile cache can configure the server's maxExportTilesCount via the administrator account to change the default limit of 100,000 tiles.

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