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:
- Feature and annotation layers — Download a specific geographical area from a sync-enabled feature service into a mobile geodatabase. Edits can be synchronized with other users when connectivity is restored. This synchronization process allows the app to maintain an up-to-date view of the feature data.
- Tiled layers
- Vector tiled data — ArcGIS vector tile services or vector basemaps in ArcGIS Online
- Image tiled data — Tiled ArcGIS map services, tiled ArcGIS image services, tiled basemaps or elevation sources in ArcGIS Online
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:
- Generate geodatabase parameters and define the area of interest, the layers, any expression filters, and so on, if required.
- 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.LayerOptions
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
ZON
.E = ' CO M' - 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.
// Create a new GeodatabaseSyncTask to create a local version of feature service data.
Uri featureServiceUri = new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/SaveTheBaySync/FeatureServer");
GeodatabaseSyncTask gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(featureServiceUri);
// Define an extent for the features to include.
Envelope dataExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry as Envelope;
// Get the default parameters for generating a geodatabase.
GenerateGeodatabaseParameters generateGdbParams = await gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(dataExtent);
// Set the synchronization model to per layer.
generateGdbParams.SyncModel = SyncModel.Layer;
// Define the layers and features to include.
int marineLayerId = 0;
int birdsLayerId = 1;
string dolphinsOnlyWhereClause = "type = 11";
// Clear and re-create the layer options.
generateGdbParams.LayerOptions.Clear();
generateGdbParams.LayerOptions.Add(new GenerateLayerOption(marineLayerId, dolphinsOnlyWhereClause));
generateGdbParams.LayerOptions.Add(new GenerateLayerOption(birdsLayerId));
// Do not return attachments.
generateGdbParams.ReturnAttachments = false;
// Create the generate geodatabase job, pass in the parameters and an output path for the local geodatabase.
// ...
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.
// 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.
GenerateGeodatabaseJob generateGdbJob = gdbSyncTask.GenerateGeodatabase(generateGdbParams, @"C:\Temp\savethebay.geodatabase");
// Handle the StatusChanged event to check the status of the job.
generateGdbJob.StatusChanged += async (sender, args) =>
{
// If there was an error, report it and return.
if (generateGdbJob.Error != null)
{
Console.WriteLine("Error creating geodatabase: " + generateGdbJob.Error.Message);
return;
}
// Check the job status.
if (generateGdbJob.Status == JobStatus.Succeeded)
{
// If the job succeeded, call a function to add local data to the map.
await AddLocalDataToMap(generateGdbJob);
}
else if (generateGdbJob.Status == JobStatus.Failed)
{
// If the job failed, report failure.
Console.WriteLine("Unable to create local geodatabase.");
}
else
{
// The job is still running, report the last message.
Console.WriteLine(generateGdbJob.Messages[generateGdbJob.Messages.Count - 1].Message);
}
};
// Start the job and report the job ID.
generateGdbJob.Start();
Console.WriteLine("Submitted job #" + generateGdbJob.ServerJobId + " 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
Now that you have a geodatabase on your local machine or device, you'll create the relevant layer from the geodatabase feature tables.
- Get the geodatabase from the generate geodatabase job.
- Load the geodatabase.
- Create feature layers from the geodatabase feature tables.
- Create annotation layers from the geodatabase annotation tables.
// Get the local geodatabase from the job result.
Geodatabase localGdb = await geodatabaseJob.GetResultAsync();
// Create a new feature layer for each feature table in the local geodatabase.
foreach (FeatureTable featureTable in localGdb.GeodatabaseFeatureTables)
{
FeatureLayer featureLayer = new FeatureLayer(featureTable);
MyMapView.Map.OperationalLayers.Add(featureLayer);
}
// Create an annotation layer for each feature table that contains annotation.
// (Annotation is stored in a ArcGISFeatureTable rather than the more generic FeatureTable)
foreach (ArcGISFeatureTable annoFeatureTable in localGdb.GeodatabaseAnnotationTables)
{
AnnotationLayer annoLayer = new AnnotationLayer(annoFeatureTable);
MyMapView.Map.OperationalLayers.Add(annoLayer);
}
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 — ArcGIS vector tile services or vector basemaps in ArcGIS Online
- Download image tiled data — Tiled ArcGIS map services, tiled ArcGIS image services, or tiled basemaps and elevation sources in ArcGIS Online
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 export
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:
- Instantiate the export vector tiles task and check whether the vector tiles have custom style resources.
- Specify the export vector tiles task parameters for a specific maximum scale and area of interest.
- 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.
// Connect to a portal (ArcGIS Online) to access a portal item ("Colored pencil" vector tile layer).
ArcGISPortal portal = await ArcGISPortal.CreateAsync();
string itemId = "4cf7e1fb9f254dcda9c8fbadb15cf0f8";
PortalItem vectorTiledLayerItem = await PortalItem.CreateAsync(portal, itemId);
// Initialize the export vector tile task with the portal item for a vector tiled layer.
// (Can use a URL if only the default styles are required).
ExportVectorTilesTask exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTiledLayerItem);
// Check if the vector tile layer has style resources.
bool hasStyleResources = exportVectorTileTask.HasStyleResources;
// Choose whether to download just the style resources or both the styles and the tiles.
if (hasStyleResources)
{
//...
}
else
{
//...
}
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.
// Create the default export vector tile cache job parameters.
ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync(
new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.Wgs84),
maxScale: MyMapView.MapScale);
// Destination path for the local vector cache (.vtpk file).
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "VectorMapTiles.vtpk");
// Create the job from the parameters and path to the local cache.
ExportVectorTilesJob exportVectorTilesJob = exportVectorTileTask.ExportVectorTiles(exportVectorTileParams, tileCachePath);
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
).
// Get the URL to the vector tile layer source.
Uri vectorTileLayerUri = vectorTiledLayer.Source;
// Initialize the export vector tile task with the vector tile source (URI).
exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTileLayerUri);
// Create the default export vector tile cache job parameters.
ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync(
new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.Wgs84),
maxScale: MyMapView.MapScale);
// Destination path for the local vector cache (.vtpk file).
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "VectorMapTiles.vtpk");
// Create the job from the parameters and path to the local cache.
ExportVectorTilesJob exportVectorTilesJob = exportVectorTileTask.ExportVectorTiles(exportVectorTileParams, tileCachePath);
// Handle job status change to check the status.
exportVectorTilesJob.StatusChanged += async (sender, args) =>
{
// Show job status and progress.
Console.WriteLine($"Job status: {exportVectorTilesJob.Status}, progress: {exportVectorTilesJob.Progress}%");
// When the job succeeds, display the local vector tiles.
if (exportVectorTilesJob.Status == JobStatus.Succeeded)
{
// Get the result from the job.
ExportVectorTilesResult result = await exportVectorTilesJob.GetResultAsync();
// Create a vector tile cache from the result.
VectorTileCache vectorCache = result.VectorTileCache;
// Create new vector tiled layer using the tile cache.
ArcGISVectorTiledLayer localVectorTileLayer = new ArcGISVectorTiledLayer(vectorCache);
// Display the layer as a basemap.
MyMapView.Map = new Map(new Basemap(localVectorTileLayer));
}
};
// Start 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.
// Get the portal item for the layer.
string vectorTiledLayerItemId = vectorTiledLayer.Item.ItemId;
PortalItem vectorTiledLayerItem = await PortalItem.CreateAsync(portal, vectorTiledLayerItemId);
// Initialize the export vector tile task with the portal item for a vector tiled layer.
ExportVectorTilesTask exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTiledLayerItem);
// Create the default export vector tile cache job parameters.
ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync(
new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.Wgs84),
maxScale: MyMapView.MapScale);
// Destination path for the local vector cache (.vtpk file) and style resources.
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "VectorMapTiles.vtpk");
string resourcePath = System.IO.Path.Combine(myDocumentsFolder, "styleResources");
// Create the job from the parameters and paths to the local cache and resources.
ExportVectorTilesJob exportVectorTilesJob = exportVectorTileTask.ExportVectorTiles(exportVectorTileParams, tileCachePath, resourcePath);
// Handle job status change to check the status.
exportVectorTilesJob.StatusChanged += async (sender, args) =>
{
// Show job status and progress.
Console.WriteLine($"Job status: {exportVectorTilesJob.Status}, progress: {exportVectorTilesJob.Progress}%");
// When the job succeeds, display the local vector tiles.
if (exportVectorTilesJob.Status == JobStatus.Succeeded)
{
// Get the result from the job.
ExportVectorTilesResult result = await exportVectorTilesJob.GetResultAsync();
// Create a vector tile cache and item resource cache from the result.
VectorTileCache vectorCache = result.VectorTileCache;
ItemResourceCache resourceCache = result.ItemResourceCache;
// Create new vector tiled layer using the tile and resource caches.
ArcGISVectorTiledLayer vectorTileLayer = new ArcGISVectorTiledLayer(vectorCache, resourceCache);
// Display the layer as a basemap.
MyMapView.Map = new Map(new Basemap(vectorTileLayer));
}
};
// Start 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
ItemResourceCache
property from the
ExportVectorTilesResult
class.
// Get the portal item for the layer.
string vectorTiledLayerItemId = vectorTiledLayer.Item.ItemId;
PortalItem vectorTiledLayerItem = await PortalItem.CreateAsync(portal, vectorTiledLayerItemId);
// Initialize the export vector tile task with the portal item for a vector tiled layer.
ExportVectorTilesTask exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTiledLayerItem);
// Destination path for the local style resources.
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string resourcePath = System.IO.Path.Combine(myDocumentsFolder, "styleResources");
// Create the job from the path to the local resources.
ExportVectorTilesJob exportStylesJob = exportVectorTileTask.ExportStyleResourceCache(resourcePath);
// Handle job status change to check the status.
exportStylesJob.StatusChanged += async (sender, args) =>
{
// Show job status and progress.
Console.WriteLine($"Job status: {exportStylesJob.Status}, progress: {exportStylesJob.Progress}%");
// When the job succeeds, access the local styles.
if (exportStylesJob.Status == JobStatus.Succeeded)
{
// Get the result from the job.
ExportVectorTilesResult result = await exportStylesJob.GetResultAsync();
// Get stuff from the resource cache.
ItemResourceCache resourceCache = result.ItemResourceCache;
// ...
}
};
// Start the job.
exportStylesJob.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 export
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:
- Generate the default export image tile cache parameters and set any of the properties.
- 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.
// URL to the map service with tiles to export.
Uri tilesMapServiceUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
// Instantiate an export tiles task with the URL to the tiled service.
ExportTileCacheTask exportTileCacheTask = await ExportTileCacheTask.CreateAsync(tilesMapServiceUri);
// Create the export tile cache parameters.
ExportTileCacheParameters exportTileParams = await exportTileCacheTask.CreateDefaultExportTileCacheParametersAsync(
new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.Wgs84),
minScale: 10000,
maxScale: 0);
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.
// Destination path for the local package (.tpkx file), including name.
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "TerrainImageTiles.tpkx");
// Get the job.
ExportTileCacheJob exportTilesJob = exportTileCacheTask.ExportTileCache(exportTileParams, tileCachePath);
// Handle job status change to check progress.
exportTilesJob.StatusChanged += async (sender, args) =>
{
// Report the current job status and progress.
Console.WriteLine($"Job changed; status: {exportTilesJob.Status}, progress: {exportTilesJob.Progress}%");
// When the job completes successfully, store the result (local tile cache).
if (exportTilesJob.Status == JobStatus.Succeeded)
{
// Get the local tile cache.
MyTileCache = await exportTilesJob.GetResultAsync();
}
};
// Start the export tile cache job.
exportTilesJob.Start();
The tile cache from an exported basemap tile layer can be used in your map or scene:
// Use the tile cache to create an ArcGISTiledLayer.
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(MyTileCache);
// Display the tiled layer as a basemap.
MyMapView.Map = new Map(new Basemap(MyTiledLayer));
The tile cache from exported elevation data can be used as an elevation source in your scene:
ArcGISTiledElevationSource localElevationSource = new ArcGISTiledElevationSource(MyTileCache);
Surface elevationSurface = new Surface();
elevationSurface.ElevationSources.Add(localElevationSource);
Scene scene = new Scene();
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 theExportTileCacheTask
class, which returns anEstimateTileCacheSizeJob
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
max
via the administrator account to change the default limit of 100,000 tiles.Export Tiles Count