ArcGIS Runtime SDK for .NET (WPF)

Create an offline layer

Taking individual layers offline allows you to build apps that can operate without network connectivity. Your users will be able to continue viewing maps, getting directions to locations, query and identify features, edit data and synchronize it when connectivity returns. You can choose to take a whole map and all of its layers offline but taking individual layers offline gives you more granular control. For example, you can decide when and how individual offline layers are created, used, and synchronized within your app.

Use either the Services pattern or the Desktop pattern to take layers offline. With the Services pattern you can use this API to download tile and feature data to your device from any ArcGIS Online or ArcGIS Enterprise service (as long as the service is enabled for offline use). With the Desktop pattern you can author packages in ArcGIS Pro or create local data sources, such as mobile geodatabases, shapefiles, GeoPackages, and tile caches, and sideload them onto your devices.

Services pattern

If your users need to access up-to-date information use the Services pattern to take your layer offline from ArcGIS Online or ArcGIS Enterprise services. This pattern allows you to build apps that can download feature data (also known as operational data) and tiled data directly to your device any time network connectivity is available.

To obtain offline feature data, l create and download a specific geographical area from a sync-enabled feature service into a mobile geodatabase. If you edit this feature data, you can control whether the edits are uploaded, whether other users edits are downloaded, or both, when connectivity is restored. This synchronization process allows the app to maintain an up-to-date view of the feature data.

For tiled data, you can create raster and vector tile caches from your own data or from Esri's export enabled basemaps, as follows:

You can export, download, and store these caches locally as packages and access them while your device is offline. You cannot edit this data, and if you require updates to the data, you must export and download them again.

Feature layers

You can view, identify, query, and edit features by taking specific features and feature layers offline with this API. Do this by exporting and downloading the features to geodatabase feature tables within a mobile geodatabase. The feature service must be from ArcGIS for Server 10.2.2 or later, or from a service hosted in ArcGIS Online. The feature service must have sync enabled capabilities (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:

  • In ArcGIS Online: you must edit the feature service item and check the Sync check box.
  • In ArcGIS Server: see the  Prepare data for offline use in the ArcGIS Server documentation.

To create the mobile geodatabase you must:

  1. Generate the geodatabase parameters and define the area of interest, the layers, any expression filters etc., if required.
  2. Create the geodatabase, populated it with all the relevant features, and downloaded 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 (envelope, in other words) 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 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 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 non-versioned, 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 GenerateGeodatabase method on the GeodatabaseSyncTask. 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, outGeodatabasePath);


// Handle the JobChanged event to check the status of the job.
generateGdbJob.JobChanged += (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 == Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded)
    {
        // If the job succeeded, call a function to add local data to the map.
        AddLocalLayerToMap();
    }
    else if (generateGdbJob.Status == Esri.ArcGISRuntime.Tasks.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.");

Your geodatabase is now on the local machine or device.

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.

Note:

For details on synchronizing offline feature edits, see Sync offline edits.

Tiled layers

Tiled layers typically provide geographical context to your maps as basemaps that display beneath your operational data. 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 raster and vector basemaps for you to export and download:

Download raster tiled data

You can take raster tiled data offline by exporting and downloading the tiled data as a tile package (*.tpk) using the ExportTileCacheTask class. This task requires that the tiled map service supports 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.

To create the raster tile cache you must:

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

Generate export tile cache parameters

Construct a default set of parameters ( ExportTileCacheParameters) by passing an area of interest along with the min and max scale thresholds to the CreateDefaultExportTileCacheParametersAsync method on the ExportTileCacheTask.

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 min and max scale for the service's tiling scheme. You can, if you wish, 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(
    areaOfInterest: MyMapView.VisibleArea,
    minScale: MyMapView.MapScale,
    maxScale: 0);

Export and download the raster tile cache

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

// Destination path for the local package (.tpk file), including name.
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "StreetMapTiles.tpk");


// Get the job.
ExportTileCacheJob exportTilesJob = exportTileCacheTask.ExportTileCache(exportTileParams, tileCachePath);


// Handle job status change to check progress.
exportTilesJob.JobChanged += async (sender, args) =>
{
    // Report the current job status and progress.
    Debug.WriteLine($"Job changed; status: {exportTilesJob.Status}, progress: {exportTilesJob.Progress}%");


    // When the job completes successfully, display the local tile cache.
    if (exportTilesJob.Status == JobStatus.Succeeded)
    {
        // Get the local tile cache.
        TileCache cache = await exportTilesJob.GetResultAsync();


        // Use the tile cache to create an ArcGISTiledLayer.
        ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(cache);


        // Display the tiled layer as a basemap.
        MyMapView.Map = new Map(new Basemap(tiledLayer));
    }
};


// Start the export tile cache job.
exportTilesJob.Start();

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 10.2.1 for Server 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  EstimateTileCacheTaskJob 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 admin account to change the default limit of 100,000 tiles.

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 wish 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:

  1. Instantiate the export vector tiles task and check whether the vector tiles have custom style resources.
  2. Specify the export vector tile task parameters for a specific maximum scale and area of interest.
  3. Export the vector tiles with custom style resources. The vector tile package is populated with vector tiles from the ArcGIS vector tile service along with the custom style resources specified by the ArcGIS vector tile layer.
  4. Export custom style resources. These are the custom style resources specified by the ArcGIS vector tile layer.
  5. Export the vector tiles with default style resources. 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
{
    //...
}

Note:

You can instantiate the ExportVectorTilesTask with either

  • A URL to the portal item that represents an ArcGIS vector tiled layer. This gives you the ability to enable with the layer's custom styles. (Recommended approach)
  • A URL to the ArcGIS vector tile service itself. Use this option if you only want to display the service's default style.

Specify the export vector tiles task parameters

To obtain a default set of parameters call the ExportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync method and provide an area of interest 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 max 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 levels of detail (LODs) have been calculated to support the max scale that you specified.

// Create the default export vector tile cache job parameters.
ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync(
    areaOfInterest: MyMapView.VisibleArea,
    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 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. 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.

Note:

To obtain the vector tiles and its custom style resources you must instantiate the ExportVectorTilesTask with a portal item that represents an ArcGIS Vector Tiled Layer

// 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(
    areaOfInterest: MyMapView.VisibleArea,
    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.JobChanged += async (sender, args) =>
{
    // Show job status and progress.
    Debug.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.

Run the job to export the style resources. Obtain the ItemResourceCache from the ExportVectorTilesResult.

Note:

To obtain the custom style resources you must instantiate the ExportTileCacheTask with a portal item that represents an ArcGIS Vector Tiled Layer

// 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.JobChanged += async (sender, args) =>
{
    // Show job status and progress.
    Debug.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();

Export the vector tiles with default style resources

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. You must also provide a download path to store the vector tile package and it's default style resources.

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

Note:

To obtain the vector tiles and the default style resources you must instantiate the ExportTileCacheTask with a URL to the ArcGIS vector tile service.

// Get the URL to the vector tile layer source.
Uri vectorTileLayerUri = vectorTileLayer.Source;


// Initialize the export vector tile task with the vector tile source (URI).
ExportVectorTilesTask exportVectorTileTask = await ExportVectorTilesTask.CreateAsync(vectorTileLayerUri);


// Create the default export vector tile cache job parameters.
ExportVectorTilesParameters exportVectorTileParams = await exportVectorTileTask.CreateDefaultExportVectorTilesParametersAsync(
    areaOfInterest: MyMapView.VisibleArea,
    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.JobChanged += async (sender, args) =>
{
    // Show job status and progress.
    Debug.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();

Desktop pattern

The desktop pattern allows you to distribute your GIS layers to a wide range of users who do not have access to online ArcGIS services. Using ArcGIS Pro and ArcMap you can create GIS files and packages and deliver them via email, FTP, the cloud, networks, thumb drives, and so on. The recipient just sideloads the files onto their device so that the ArcGIS Runtime apps can work offline without a network connection.

You could send these files to members of the public, staff in your organization or offline field workers. The desktop pattern is particularly suited for distributing GIS data to large numbers of people who do not need to synchronize their edits with the original data source.

This pattern supports the following types of layers:

  • Raster tiled layer data stored in tile packages (.tpk).
  • Vector tiled layer data stored in vector tile packages (.vtpk).
  • Feature layer data stored in the following formats:
    • ArcGIS features held in a mobile geodatabases (.geodatabase).
    • Features stored in a GeoPackages provisioned by the OGC file format (.gpkg).
    • Features stored in the Shapefile format provided by the .shp file and its associated files (.dbf, .shx, etc).
  • Raster layer data stored in a raster dataset file or in a GeoPackage (.gpkg).

ArcGIS Pro and ArcMap provide a range of tools to create these GIS files and packages. The following sections demonstrate how you prepare these data files, add then to your ArcGIS Runtime app and create layers to display in your map.

Raster tiled layer

Raster tiled layers typically display pre-generated raster tiles as basemaps to give geographical context to other operational layers in a map. You can take a portion of this raster tiled data offline and store it within a single tile package (.tpk) file. You just need to specify the tiling scheme, the levels of detail, and the tile format using any of these tools:

  • Run the ArcGIS Pro python tool, Create Map Tile Package, to create a tile package file.
  • In ArcMap, choose File > Share As > Tile Package to create a tile package file, as described in the Tile Package option help topic.
  • In ArcMap, choose Share as > ArcGIS Runtime Content to export the map's basemap layer to a tile package file (.tpk) that is output within the ArcGIS Runtime Content folder. This is described in the Creating ArcGIS Runtime content help topic which is available with ArcGIS 10.2.1 for Desktop or later.

Review this document for more information about tile packages.

Note:

When you create a tile package it must have the same spatial reference as the map in which it will be displayed.

To create a tiled layer from a tile package (.tpk) file instantiate an ArcGISTiledLayer object with the path to the tile package file on the device.

// Path to the local package (.tpk file).
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "StreetMapTiles.tpk");


// Create a tile cache from the local data.
TileCache cache = new TileCache(tileCachePath);


// Use the tile cache to create an ArcGISTiledLayer.
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(cache);


// Display the tiled layer as a basemap.
MyMapView.Map = new Map(new Basemap(tiledLayer));

Vector tiled layer

Vector tiled layers contain vector representations of data across a range of scales. Unlike raster tiles, they can adapt to the resolution of their display device as you zoom in and out. You can take an area of vector tiled data offline by exporting the vector tiles to a vector tile package file (.vtpk) using the Create Vector Tile Package tool in ArcGIS Pro. Be aware that ArcGIS Pro does not support custom styles and only packages the default styles into the vector tile package.

Note:

When you create a vector tile package it must be in the same spatial reference as the map in which it will be displayed.

To create a vector tiled layer from the vector tile package (.vtpk) instantiate an ArcGISVectorTiledLayer object with the vector tile package's file URL. The default style will be loaded directly from the vector tile package.

// Path to the local vector tile package (.vtpk file).
string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string tileCachePath = System.IO.Path.Combine(myDocumentsFolder, "PencilMapTiles.vtpk");


// Create a vector tile cache from the local data.
VectorTileCache cache = new VectorTileCache(tileCachePath);


// Use the tile cache to create an ArcGISVectorTiledLayer.
ArcGISVectorTiledLayer tiledLayer = new ArcGISVectorTiledLayer(cache);


// Display the vector tiled layer as a basemap.
MyMapView.Map = new Map(new Basemap(tiledLayer));

Feature layer

Feature layers allow you to display, select and query individual features and their attributes. If supported, you can also edit features, their attributes and their attachments. The desktop pattern allows you to work with features offline using cached features stored in an offline file, such as a geodatabase file (.geodatabase), a GeoPackage file (.gpkg), or a shapefile (.shp).

ArcGIS features

To generate a mobile geodatabase use the Share as > ArcGIS Runtime Content menu item as described in the ArcMap help topic Creating ArcGIS Runtime content. This is available with ArcGIS for Desktop 10.2.1 or later.

To create an offline feature layer from a mobile geodatabase (.geodatabase):

  1. Instantiate the Geodatabase object with path to the geodatabase file.
  2. Load the geodatabase and instantiate a FeatureTable from one of the geodatabase's feature tables.
  3. Finally, create a FeatureLayer from the FeatureTable and add it as an operational layer to the map.

// Get the path to a local geodatabase.
string geodatabasePath = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "recreation.geodatabase");


// Open the geodatabase by providing the path.
Geodatabase localGdb = await Geodatabase.OpenAsync(geodatabasePath);


// Access one of the feature tables in the geodatabase using its name.
GeodatabaseFeatureTable trailheadsTable = localGdb.GeodatabaseFeatureTable("Trailheads");


// Create a feature layer from the table and add it to the map's operational layers.
FeatureLayer trailheadsLayer = new FeatureLayer(trailheadsTable);
MyMapView.Map.OperationalLayers.Add(trailheadsLayer);

GeoPackage

GeoPackage is an open, standards-based, platform-independent, portable, self-describing, compact format for transferring geospatial information. It uses a single SQLite file (.gpkg) that conforms to the OGC GeoPackage Standard. You can create a GeoPackage file (.gpkg) from your own data using the create a SQLite Database tool in ArcGIS Pro.

To display features stored in a GeoPackage file you must:

  1. Instantiate the GeoPackage with the .gpkg file path.
  2. Load the GeoPackage and then examine its list of GeoPackageFeatureTables.
  3. Create a FeatureLayer from one of the GeoPackageFeatureTables and add it as an operational layer to the map.

// Get the path to a local geopackage.
string geopackagePath = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "trails.gpkg");


// Open the geopackage by providing the path.
GeoPackage trailsGpkg = await GeoPackage.OpenAsync(geopackagePath);


// Iterate feature tables in the package to find one by name.
foreach (GeoPackageFeatureTable table in trailsGpkg.GeoPackageFeatureTables)
{
    if (table.TableName.ToLower() == "trailheads")
    {
        // Create a feature layer from the table and add it to the map's operational layers.
        FeatureLayer trailheadsLayer = new FeatureLayer(table);
        MyMapView.Map.OperationalLayers.Add(trailheadsLayer);
    }
}

Shapefiles

To create a feature layer from a shapefile (.shp):

  1. Instantiate the ShapefileFeatureTable with the path to the shapefile. This path must point to the .shp file and the associated .shx and .dbf files must be present at the same location.
  2. Create a FeatureLayer from the ShapefileFeatureTable and add it as an operational layer to the map.

// Get the path to a local shapefile.
string shapefilePath = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "trails.shp");


// Create a shapefile feature table using the path.
ShapefileFeatureTable trailsFeatureTable = await ShapefileFeatureTable.OpenAsync(shapefilePath);


// Create a feature layer from the table and add it to the map's operational layers.
FeatureLayer trailsLayer = new FeatureLayer(trailsFeatureTable);
MyMapView.Map.OperationalLayers.Add(trailsLayer);

Raster layer

Raster datasets consist of a matrix of cells where an individual cell contains a value representing information. Each cell's value can be discrete, in the case of a soil map, or continuous, such as air temperature. You can identify and query these cell values and define renderers to display the data. In addition, raster data can also comprise satellite or aerial images and photographs for visualizing an area. This SDK supports several raster formats. You can sideload these onto your device and add the raster dataset to your map using the RasterLayer class.

Explore these topics for more information: