Display a map from a mobile map package

Learn how to display a map from a mobile map package (MMPK).

display a map from a mobile map package

In this tutorial you will display a fully interactive map from a mobile map package (MMPK). The map contains a basemap layer and data layers and does not require a network connection.

Prerequisites

Before starting this tutorial, you should:

  • Have an ArcGIS account and an API key to access ArcGIS services. If you don't have an account, sign up for free.
  • Ensure your development environment meets the system requirements.

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.

Steps

Open a Visual Studio solution

  1. To start the tutorial, complete the Display a map tutorial or download and unzip the solution.

  2. Open the .sln file in Visual Studio.

  3. If you downloaded the solution project, set your API key.

Update the tutorial name used in the project (optional)

The Visual Studio solution, project, and the namespace for all classes currently use the name DisplayAMap. 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.

Add a mobile map package to the project

Add a mobile map package (.mmpk) for distribution with your app.

  1. Create or download the MahouRivieraTrails.mmpk mobile map package. Complete the Create a mobile map package tutorial to create the package yourself. Otherwise, download the solution file: MahouRivieraTrails.mmpk.

  2. From the Visual Studio Project menu, choose Add > Existing item ....

  3. Navigate to the folder that contains your mobile map package. Change the file type in the dialog to All files (*.*), choose MahouRivieraTrails.mmpk, then click Add to add it to the project.

  4. In the Visual Studio Solution Explorer, select MahouRivieraTrails.mmpk. In the Properties window, set the following properties of the file.

    • Build Action: Content
    • Copy to Output Directory: Copy always

Open the mobile map package and display a map

Select a map from the maps contained in a mobile map package and display it in a map view. Use the MobileMapPackage class to access the mobile map package and load it to read its contents.

  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
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    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.Linq;
    using System.Threading.Tasks;
    
  3. In the MapViewModel class, remove all the existing code in the SetupMap() function.

    MapViewModel.cs
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
            private void SetupMap()
            {
    
                // Create a new map with a 'topographic vector' basemap.
                Map = new Map(BasemapStyle.ArcGISTopographic);
    
            }
    
  4. Modify the signature of the SetupMap() function to include the async keyword and to return Task rather than void.

    MapViewModel.cs
    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
            private async Task SetupMap()
            {
    
            }
    
    Expand
  5. (Optional) Modify the call to SetupMap() (in the MapViewModel constructor) to avoid a compilation warning. After changing SetupMap() to an asynchronous method, the following warning appears in the Visual Studio Error List.

    Use dark colors for code blocksCopy
    1
    2
    Because this call is not awaited, execution of the current method continues before the call is
    completed. Consider applying the 'await' operator to the result of the call.

    Because your code does not anticipate a return value from this call, the warning can be ignored. Your code will run despite the warning. But if you want to be more specific about your intentions with this call and to address the warning, add the following code to store the return value in a discard.

    MapViewModel.cs
    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
            public MapViewModel()
            {
    
                _ = SetupMap();
    
            }
    
    Expand
  6. Add the following code to the SetupMap() function. This code defines the path to the mobile map package relative to the app, creates the mobile map package using the MobileMapPackage constructor, loads the mobile map package asynchronously, and adds the first map in the mobile map package to the MapView.

    Expand
    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
                // Define the path to the mobile map package.
                string pathToMobileMapPackage = System.IO.Path.Combine(Environment.CurrentDirectory, @"MahouRivieraTrails.mmpk");
    
                // Instantiate a new mobile map package.
                MobileMapPackage mahouRivieraTrails_MobileMapPackage = new MobileMapPackage(pathToMobileMapPackage);
    
                // Load the mobile map package.
                await mahouRivieraTrails_MobileMapPackage.LoadAsync();
    
                // Show the first map in the mobile map package.
                this.Map = mahouRivieraTrails_MobileMapPackage.Maps.FirstOrDefault();
    
    Expand
  7. Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app.

You will see a map of trailheads, trails, and parks for the area south of the Santa Monica mountains. You can pinch (to zoom and rotate), drag, and double-tap the map view to explore the map.

What's next?

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

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