Overview

You will learn: how to load and display a mobile map package you created in the Prepare your data for offline use data lab.

ArcGIS Runtime SDK for .NET allows you to provide offline maps to your users so they can be productive when their network connectivity is poor or offline. The mobile map package is a file created with ArcGIS Pro, and loaded to your user's device.

In this lab you will learn how to load a mobile map package and then use it in your app.

Steps

Create a new ArcGIS Runtime App Visual Studio Project

  1. Start Visual Studio.

  2. Choose File > New > Project and select the ArcGIS Runtime App template for your chosen platform.

Load your mobile map package on to your device

  1. You created a mobile map package in the lab Prepare your data for offline use. Load that file on to your device. If you did not complete that lab, download the mobile map package we prepared.

Load and display the mobile map package

  1. Open the MapViewModel.cs code file in your project. Find the definition for the Map property in the class. Notice that the default map is currently set to display the streets vector basemap. You are going to load the map from a file so this assignment is not needed. Set the _map variable to null.

    private Map _map = null;
    
  2. Add a new method to load the mmpk file into a Map object and then update your MapViewModel to display it.

     async private void SetupMobileMap()
     {
         Boolean isMapLoaded = false;
         var mapPackageFolder = @"..\..\..\";
         var mapPackageFile = @"devlabs-package.mmpk";
         var mapPackagePath = System.IO.Path.Combine(mapPackageFolder, mapPackageFile);
         try
         {
             var mapPackage = await MobileMapPackage.OpenAsync(mapPackagePath);
             if (mapPackage != null && mapPackage.Maps.Count > 0)
             {
                 Map = mapPackage.Maps[0];
                 await Map.LoadAsync();
                 if (Map.LoadStatus != Esri.ArcGISRuntime.LoadStatus.FailedToLoad)
                 {
                     isMapLoaded = true;
                 }
             }
         }
         catch (System.IO.FileNotFoundException ex)
         {
             Console.Write(ex.Message);
         }
         if ( !isMapLoaded)
         {
             Map = new Map(Basemap.CreateStreetsVector());
         }
     }
    
  3. Update the MapViewModel constructor to call the new method.

     public MapViewModel()
     {
         SetupMobileMap();
     }
    

Congratulations, you're done!

Your map, as it was designed in ArcGIS Pro, should load and display with the view point centered on the Los Angeles area. If the map was not loaded successfully from the package, you will see the vector streets base map displayed at a global scale.

Challenge

Change map contents

Learn how you can change many elements of your map without writing any code. Return to ArcGIS Pro and alter your map: change the extent, add or remove layers, change symbology. Republish your mobile map package and load it on your device.

File selection

Add a UI to allow your user to pick the mmpk file instead of hard-coding it in your code.