Learn how to download and display an offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more for a user-defined geographical area of a web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more .

display an offline map on demand

Offline maps An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more allow users to continue working when network connectivity is poor or lost. If a web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more is enabled for offline use, a user can request that ArcGIS generates an offline map for a specified geographic area of interest.

In this tutorial, you will download an offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more for an area of interest from the web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more of the stormwater network within Naperville, IL, USA . You can then use this offline map without a network connection.

Before starting this tutorial:

Optionally, you may want to install the ArcGIS Maps SDK for .NET to get access to project templates in Visual Studio (Windows only) and offline copies of the NuGet packages.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

To start the tutorial, complete the Display a web map tutorial. This creates a map loaded from a portal item stored in ArcGIS Online. You can choose to implement either API key authentication or user authentication.

Open a Visual Studio solution

  1. Open the Visual Studio solution you created by completing the Display a web map tutorial.
  2. Continue with the following instructions to download and display an offline map for a user-defined geographic area of a web map.

Update the tutorial name used in the project (optional)

The Visual Studio solution, project, and the namespace for all classes currently use the name DisplayAWebMap. Follow the steps below if you prefer the name to reflect the current tutorial. These steps are not required, your code will still work if you keep the original name.

Get the web map item ID

You can use ArcGIS tools Tools, also known as developer tools, are ArcGIS software applications such as portal and ArcGIS Pro that developers can use to prepare content and data for custom applications they are building. Learn more to create and view web maps A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more . Use the Map Viewer Map Viewer is a browser-based mapping tool that can view, create, and save web maps. It can also perform mapping, visualization, and spatial analysis operations. Learn more to identify the web map item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more . This item ID will be used later in the tutorial.

  1. Go to the Naperville water network in the Map Viewer Map Viewer is a browser-based mapping tool that can view, create, and save web maps. It can also perform mapping, visualization, and spatial analysis operations. Learn more in ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more . This web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more displays stormwater network within Naperville, IL, USA .
  2. Make a note of the item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more at the end of the browser’s URL. The item ID should be:

    acc027394bc84c2fb04d1ed317aac674

Display the web map

You can display a web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more using the web map’s item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more . Create a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more from the web map portal item An item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. Learn more , and display it in your app.

  1. In the Visual Studio > Solution Explorer, double-click MapViewModel.cs to open the file.

  2. Add additional required using statements at the top of the class.

    MapViewModel.cs
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
  3. In MapViewModel.cs, modify the SetupMap() function to update the web map’s item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more to that of the Naperville water network.

    The existing code creates a PortalItem using the item ID An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. Learn more and an ArcGISPortal referencing ArcGIS Online ArcGIS Online is a GIS mapping, analytics, data hosting, and content management software as a service (SaaS) product. It includes applications, tools, APIs, and location services for users and developers. It is subscription-based and requires an ArcGIS Online account. Learn more . It sets the MapViewModel.Map property to a new Map created using the PortalItem.

    MapViewModel.cs
    43 collapsed lines
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
    namespace DisplayAnOfflineMapOnDemand
    {
    class MapViewModel : INotifyPropertyChanged
    {
    public MapViewModel()
    {
    _ = SetupMap();
    }
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Map? _map;
    public Map? Map
    {
    get { return _map; }
    set
    {
    _map = value;
    OnPropertyChanged();
    }
    }
    private async Task SetupMap()
    {
    // Create a portal pointing to ArcGIS Online.
    ArcGISPortal portal = await ArcGISPortal.CreateAsync();
    // Create a portal item for a specific web map id.
    string webMapId = "acc027394bc84c2fb04d1ed317aac674";
    PortalItem mapItem = await PortalItem.CreateAsync(portal, webMapId);
    // Create the map from the item.
    Map map = new Map(mapItem);
    // Set the view model "Map" property.
    this.Map = map;
    5 collapsed lines
    }
    }
    }
  4. Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see a map of the stormwater network within Naperville, IL, USA . Use the mouse to drag, scroll, and double-click the map view to explore the map.

Specify an area of the web map to take offline

You can specify an area of the web map A web map is a map stored as a JSON object that defines properties such as the basemap layer, data layers, layer styles, and pop-up styles. Its JSON structure is defined by the web map specification. Learn more to take offline using either an Envelope or a Polygon. You can use a graphic to display the area on the map.

  1. In the MapViewModel class, create a new property named GraphicsOverlays. This will be a collection of GraphicsOverlay to display a graphic A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more of the area to take offline.

    32 collapsed lines
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
    namespace DisplayAnOfflineMapOnDemand
    {
    class MapViewModel : INotifyPropertyChanged
    {
    public MapViewModel()
    {
    _ = SetupMap();
    }
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Map? _map;
    public Map? Map
    {
    get { return _map; }
    set
    {
    _map = value;
    OnPropertyChanged();
    }
    }
    private GraphicsOverlayCollection? _graphicsOverlays;
    public GraphicsOverlayCollection? GraphicsOverlays
    {
    get { return _graphicsOverlays; }
    set
    {
    _graphicsOverlays = value;
    OnPropertyChanged();
    }
    }
    22 collapsed lines
    private async Task SetupMap()
    {
    // Create a portal pointing to ArcGIS Online.
    ArcGISPortal portal = await ArcGISPortal.CreateAsync();
    // Create a portal item for a specific web map id.
    string webMapId = "acc027394bc84c2fb04d1ed317aac674";
    PortalItem mapItem = await PortalItem.CreateAsync(portal, webMapId);
    // Create the map from the item.
    Map map = new Map(mapItem);
    // Set the view model "Map" property.
    this.Map = map;
    }
    }
    }
  2. Modify the SetupMap() function. Use an EnvelopeBuilder to create a new Envelope that defines an area to take offline.

    MapViewModel.cs
    68 collapsed lines
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
    namespace DisplayAnOfflineMapOnDemand
    {
    class MapViewModel : INotifyPropertyChanged
    {
    public MapViewModel()
    {
    _ = SetupMap();
    }
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Map? _map;
    public Map? Map
    {
    get { return _map; }
    set
    {
    _map = value;
    OnPropertyChanged();
    }
    }
    private GraphicsOverlayCollection? _graphicsOverlays;
    public GraphicsOverlayCollection? GraphicsOverlays
    {
    get { return _graphicsOverlays; }
    set
    {
    _graphicsOverlays = value;
    OnPropertyChanged();
    }
    }
    private async Task SetupMap()
    {
    // Create a portal pointing to ArcGIS Online.
    ArcGISPortal portal = await ArcGISPortal.CreateAsync();
    // Create a portal item for a specific web map id.
    string webMapId = "acc027394bc84c2fb04d1ed317aac674";
    PortalItem mapItem = await PortalItem.CreateAsync(portal, webMapId);
    // Create the map from the item.
    Map map = new Map(mapItem);
    // Set the view model "Map" property.
    this.Map = map;
    // Define area of interest (envelope) to take offline.
    EnvelopeBuilder envelopeBldr = new EnvelopeBuilder(SpatialReferences.Wgs84)
    {
    XMin = -88.1526,
    XMax = -88.1490,
    YMin = 41.7694,
    YMax = 41.7714
    };
    Envelope offlineArea = envelopeBldr.ToGeometry();
    5 collapsed lines
    }
    }
    }
  3. Display a graphic of the area to take offline.

    Use a SimpleLineSymbol and a SimpleFillSymbol to display a new Graphic of the offlineArea with a red outline. Add the graphic to a new GraphicsOverlay and set the MapViewModel.GraphicsOverlays property to display it in the map view.

    MapViewModel.cs
    80 collapsed lines
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
    namespace DisplayAnOfflineMapOnDemand
    {
    class MapViewModel : INotifyPropertyChanged
    {
    public MapViewModel()
    {
    _ = SetupMap();
    }
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Map? _map;
    public Map? Map
    {
    get { return _map; }
    set
    {
    _map = value;
    OnPropertyChanged();
    }
    }
    private GraphicsOverlayCollection? _graphicsOverlays;
    public GraphicsOverlayCollection? GraphicsOverlays
    {
    get { return _graphicsOverlays; }
    set
    {
    _graphicsOverlays = value;
    OnPropertyChanged();
    }
    }
    private async Task SetupMap()
    {
    // Create a portal pointing to ArcGIS Online.
    ArcGISPortal portal = await ArcGISPortal.CreateAsync();
    // Create a portal item for a specific web map id.
    string webMapId = "acc027394bc84c2fb04d1ed317aac674";
    PortalItem mapItem = await PortalItem.CreateAsync(portal, webMapId);
    // Create the map from the item.
    Map map = new Map(mapItem);
    // Set the view model "Map" property.
    this.Map = map;
    // Define area of interest (envelope) to take offline.
    EnvelopeBuilder envelopeBldr = new EnvelopeBuilder(SpatialReferences.Wgs84)
    {
    XMin = -88.1526,
    XMax = -88.1490,
    YMin = 41.7694,
    YMax = 41.7714
    };
    Envelope offlineArea = envelopeBldr.ToGeometry();
    // Create a graphic to display the area to take offline.
    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 2);
    SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Transparent, lineSymbol);
    Graphic offlineAreaGraphic = new Graphic(offlineArea, fillSymbol);
    // Create a graphics overlay and add the graphic.
    GraphicsOverlay areaOverlay = new GraphicsOverlay();
    areaOverlay.Graphics.Add(offlineAreaGraphic);
    // Add the overlay to a new graphics overlay collection.
    GraphicsOverlayCollection overlays = new GraphicsOverlayCollection
    {
    areaOverlay
    };
    // Set the view model's "GraphicsOverlays" property (will be consumed by the map view).
    this.GraphicsOverlays = overlays;
    5 collapsed lines
    }
    }
    }
  4. In the Visual Studio > Solution Explorer, double-click MainWindow.xaml to open the file.

  5. Use data binding to bind the GraphicsOverlays property of the MapViewModel to the MapView control.

    14 collapsed lines
    <Window x:Class="DisplayAnOfflineMapOnDemand.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:DisplayAnOfflineMapOnDemand"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
    <local:MapViewModel x:Key="MapViewModel" />
    </Window.Resources>
    <Grid>
    <esri:MapView x:Name="MainMapView"
    Map="{Binding Map, Source={StaticResource MapViewModel}}"
    GraphicsOverlays="{Binding GraphicsOverlays, Source={StaticResource MapViewModel}}" />
    3 collapsed lines
    </Grid>
    </Window>
  6. Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see a red outline on the stormwater network within Naperville, IL, USA . This indicates the area of the web map that you are going to take offline.

Download and display the offline map

You can generate and download an offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more for a specified area of interest using an asynchronous task. When complete, it will provide the offline map for display in your map view A map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more .

  1. Return to the MapViewModel.cs file and add code to the SetupMap function to create an OfflineMapTask that references the online map by calling the static OfflineMapTask.CreateAsync method.

    MapViewModel.cs
    // Set the view model's "GraphicsOverlays" property (will be consumed by the map view).
    this.GraphicsOverlays = overlays;
    // Create an offline map task using the current map.
    OfflineMapTask offlineMapTask = await OfflineMapTask.CreateAsync(map);
  2. Get default parameters to generate and download the offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more . Modify them to download a read-only offline map.

    MapViewModel.cs
    // Create an offline map task using the current map.
    OfflineMapTask offlineMapTask = await OfflineMapTask.CreateAsync(map);
    // Create a default set of parameters for generating the offline map from the area of interest.
    GenerateOfflineMapParameters parameters = await offlineMapTask.CreateDefaultGenerateOfflineMapParametersAsync(offlineArea);
    parameters.UpdateMode = GenerateOfflineMapUpdateMode.NoUpdates;
  3. Set a download location for the offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more .

    MapViewModel.cs
    // Create a default set of parameters for generating the offline map from the area of interest.
    GenerateOfflineMapParameters parameters = await offlineMapTask.CreateDefaultGenerateOfflineMapParametersAsync(offlineArea);
    parameters.UpdateMode = GenerateOfflineMapUpdateMode.NoUpdates;
    // Build a folder path named with today's date/time in the "My Documents" folder.
    string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string downloadDirectory = System.IO.Path.Combine(documentsFolder, "OfflineMap_" + DateTime.Now.ToFileTime().ToString());
  4. Create a new GenerateOfflineMapJob using the parameters and downloadDirectory.

    MapViewModel.cs
    // Build a folder path named with today's date/time in the "My Documents" folder.
    string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string downloadDirectory = System.IO.Path.Combine(documentsFolder, "OfflineMap_" + DateTime.Now.ToFileTime().ToString());
    GenerateOfflineMapJob generateJob = offlineMapTask.GenerateOfflineMap(parameters, downloadDirectory);
  5. Create a function called GenerateJob_ProgressChanged. This function will respond when the job completes or fails and will track the precent complete as the job runs. Add a try/catch block to handle exceptions and start by getting a reference to the GenerateOfflineMapJob, passed in as the sender argument.

    MapViewModel.cs
    // Build a folder path named with today's date/time in the "My Documents" folder.
    string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string downloadDirectory = System.IO.Path.Combine(documentsFolder, "OfflineMap_" + DateTime.Now.ToFileTime().ToString());
    GenerateOfflineMapJob generateJob = offlineMapTask.GenerateOfflineMap(parameters, downloadDirectory);
    }
    private async void GenerateJob_ProgressChanged(object? sender, EventArgs e)
    {
    try
    {
    var generateJob = sender as GenerateOfflineMapJob;
    if(generateJob == null) { return; }
    }
    catch (Exception ex)
    {
    MessageBox.Show($"Error generating offline map: {ex.Message}");
    }
    }
  6. If the job succeeds, set the MapViewModel.Map property with the offline map result. If it fails, notify the user. If the job is running, write the percent complete to the console.

    MapViewModel.cs
    try
    {
    var generateJob = sender as GenerateOfflineMapJob;
    if(generateJob == null) { return; }
    // If the job succeeds, show the offline map in the map view.
    if (generateJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded)
    {
    var result = await generateJob.GetResultAsync();
    this.Map = result.OfflineMap;
    Debug.WriteLine("Generate offline map: Complete");
    }
    // If the job fails, notify the user.
    else if (generateJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Failed)
    {
    MessageBox.Show($"Unable to generate a map for that area: {generateJob?.Error?.Message}");
    }
    else
    {
    int percentComplete = generateJob.Progress;
    Debug.WriteLine($"Generate offline map: {percentComplete}%");
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show($"Error generating offline map: {ex.Message}");
    }
  7. Return to your code in SetupMap and assign the GenerateJob_ProgressChanged function to handle the Job.ProgressChanged() event.

    MapViewModel.cs
    GenerateOfflineMapJob generateJob = offlineMapTask.GenerateOfflineMap(parameters, downloadDirectory);
    generateJob.ProgressChanged += GenerateJob_ProgressChanged;
  8. Start the generateJob by calling its Job.Start() method.

    MapViewModel.cs
    111 collapsed lines
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Esri.ArcGISRuntime.Geometry;
    using Esri.ArcGISRuntime.Mapping;
    using System.ComponentModel;
    using System.Runtime.CompilerServices;
    using System.Threading.Tasks;
    using Esri.ArcGISRuntime.Portal;
    using Esri.ArcGISRuntime.Symbology;
    using Esri.ArcGISRuntime.Tasks.Offline;
    using Esri.ArcGISRuntime.UI;
    using System.Windows;
    using System.Diagnostics;
    using System.Drawing;
    namespace DisplayAnOfflineMapOnDemand
    {
    class MapViewModel : INotifyPropertyChanged
    {
    public MapViewModel()
    {
    _ = SetupMap();
    }
    public event PropertyChangedEventHandler? PropertyChanged;
    protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    private Map? _map;
    public Map? Map
    {
    get { return _map; }
    set
    {
    _map = value;
    OnPropertyChanged();
    }
    }
    private GraphicsOverlayCollection? _graphicsOverlays;
    public GraphicsOverlayCollection? GraphicsOverlays
    {
    get { return _graphicsOverlays; }
    set
    {
    _graphicsOverlays = value;
    OnPropertyChanged();
    }
    }
    private async Task SetupMap()
    {
    // Create a portal pointing to ArcGIS Online.
    ArcGISPortal portal = await ArcGISPortal.CreateAsync();
    // Create a portal item for a specific web map id.
    string webMapId = "acc027394bc84c2fb04d1ed317aac674";
    PortalItem mapItem = await PortalItem.CreateAsync(portal, webMapId);
    // Create the map from the item.
    Map map = new Map(mapItem);
    // Set the view model "Map" property.
    this.Map = map;
    // Define area of interest (envelope) to take offline.
    EnvelopeBuilder envelopeBldr = new EnvelopeBuilder(SpatialReferences.Wgs84)
    {
    XMin = -88.1526,
    XMax = -88.1490,
    YMin = 41.7694,
    YMax = 41.7714
    };
    Envelope offlineArea = envelopeBldr.ToGeometry();
    // Create a graphic to display the area to take offline.
    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 2);
    SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Transparent, lineSymbol);
    Graphic offlineAreaGraphic = new Graphic(offlineArea, fillSymbol);
    // Create a graphics overlay and add the graphic.
    GraphicsOverlay areaOverlay = new GraphicsOverlay();
    areaOverlay.Graphics.Add(offlineAreaGraphic);
    // Add the overlay to a new graphics overlay collection.
    GraphicsOverlayCollection overlays = new GraphicsOverlayCollection
    {
    areaOverlay
    };
    // Set the view model's "GraphicsOverlays" property (will be consumed by the map view).
    this.GraphicsOverlays = overlays;
    // Create an offline map task using the current map.
    OfflineMapTask offlineMapTask = await OfflineMapTask.CreateAsync(map);
    // Create a default set of parameters for generating the offline map from the area of interest.
    GenerateOfflineMapParameters parameters = await offlineMapTask.CreateDefaultGenerateOfflineMapParametersAsync(offlineArea);
    parameters.UpdateMode = GenerateOfflineMapUpdateMode.NoUpdates;
    // Build a folder path named with today's date/time in the "My Documents" folder.
    string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string downloadDirectory = System.IO.Path.Combine(documentsFolder, "OfflineMap_" + DateTime.Now.ToFileTime().ToString());
    GenerateOfflineMapJob generateJob = offlineMapTask.GenerateOfflineMap(parameters, downloadDirectory);
    generateJob.ProgressChanged += GenerateJob_ProgressChanged;
    generateJob.Start();
    }
    37 collapsed lines
    private async void GenerateJob_ProgressChanged(object? sender, EventArgs e)
    {
    try
    {
    var generateJob = sender as GenerateOfflineMapJob;
    if(generateJob == null) { return; }
    // If the job succeeds, show the offline map in the map view.
    if (generateJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Succeeded)
    {
    var result = await generateJob.GetResultAsync();
    this.Map = result.OfflineMap;
    Debug.WriteLine("Generate offline map: Complete");
    }
    // If the job fails, notify the user.
    else if (generateJob.Status == Esri.ArcGISRuntime.Tasks.JobStatus.Failed)
    {
    MessageBox.Show($"Unable to generate a map for that area: {generateJob?.Error?.Message}");
    }
    else
    {
    int percentComplete = generateJob.Progress;
    Debug.WriteLine($"Generate offline map: {percentComplete}%");
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show($"Error generating offline map: {ex.Message}");
    }
    }
    }
    }
  9. Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see an offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more for the specified area of the stormwater network within Naperville, IL, USA . Remove your network connection and you will still be able to use the mouse to drag, scroll, and double-click the map view to explore this offline map.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link in the right-hand panel of the page.

  2. Unzip the file to a location on your machine.

  3. Open the .sln file in Visual Studio.

Since the downloaded solution does not contain authentication credentials, you must first set up authentication to create credentials, and then add the developer credentials to the solution.

Set up authentication

To access the secure ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authentication API key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more or user authentication User authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth2.0. Learn more using an ArcGIS Location Platform An ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS Online An ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

To complete this tutorial, click on the tab in the switcher below for your authentication type of choice, either API key authentication or User authentication.

Create a new API key access token An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privileges Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s) Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Set developer credentials in the solution

To allow your app users to access ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

  1. In Visual Studio, in the Solution Explorer, click App.xaml.cs to open the file.

  2. Set the ArcGISEnvironment.ApiKey property with your API key access token.

    App.xaml.cs
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    // Set the access token for ArcGIS Maps SDK for .NET.
    Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
    // Call a function to set up the AuthenticationManager for OAuth.
    UserAuth.ArcGISLoginPrompt.RegisterOAuthConfig();
    }
  3. Remove the code that sets up user authentication.

    App.xaml.cs
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    // Set the access token for ArcGIS Maps SDK for .NET.
    Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR_ACCESS_TOKEN";
    // Call a function to set up the AuthenticationManager for OAuth.
    UserAuth.ArcGISLoginPrompt.RegisterOAuthConfig();
    }

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Run the solution

Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.

You should see an offline map An offline map is a map area and its data content downloaded from an offline-enabled web map for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more for the specified area of the stormwater network within Naperville, IL, USA . Remove your network connection and you will still be able to use the mouse to drag, scroll, and double-click the map view to explore this offline map.

What’s next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: