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:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

  3. The ArcGIS Runtime API for Qt is installed.

Steps

Add a mobile map package

  1. Download or create the MahouRivieraTrails.mmpk mobile map package. You can download the mobile map package from here: MahouRivieraTrails.mmpk. Otherwise, complete the steps in the Create a mobile map package tutorial, using ArcGIS Pro to create the package.

  2. Copy the file MahouRivieraTrails.mmpk to the following local path: <userhome>/ArcGIS/Runtime/Data/mmpk/, where <userhome> is your user home location (for example, C:\users\username on Windows, or $HOME on Linux).

Create a new ArcGIS Runtime Qt Creator Project

  1. Launch Qt Creator and create a new project. Under Choose a Template, select Qt Quick C++ app project for the latest version of ArcGIS Runtime installed.

  2. Name your project display_an_mmpk.

  3. Accept all defaults. At the Define Project Details window, leave the ArcGIS Online Basemap selection as is. Complete the project creation.

Modify the project to use a mobile map package

The project you created from the template includes classes for the Basemap , Map , and QUrl. Because the mobile map package contains the map, basemap, and all the data layers it requires, in the following steps you will remove the unneeded code from your project and add/modify other code as needed.

  1. In Projects, double-click Headers > Display_an_mmpk.h to open the file. Remove the code that forward declares the Map class.

    Display_an_mmpk.h
    Use dark colors for code blocks
    18 19 20 21 22 23
    Remove line
    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
    namespace Esri
    {
    namespace ArcGISRuntime
    {
    
    class Map;
    
  2. Remove the code that creates the Map pointer variable m_map.

    Display_an_mmpk.h
    Use dark colors for code blocks
    44 45 46 47 48 49 50 51
    Remove line
    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
    private:
        Esri::ArcGISRuntime::MapQuickView* mapView() const;
        void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
        void setupViewpoint();
    
    
        Esri::ArcGISRuntime::Map* m_map = nullptr;
    
  3. Under private, declare the new function you will implement to load the mobile map package. Then save and close the file.

    Display_an_mmpk.h
    Use dark colors for code blocks
    40 41 42 43 44
    Add line.
    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
    private:
        Esri::ArcGISRuntime::MapQuickView* mapView() const;
        void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
        void setupMapFromMmpk();
    
  4. In Projects, double-click Sources > Display_an_mmpk.cpp to open the file. Remove the lines #include "Basemap.h" and #include "Map.h". Also remove #include <QUrl> because it is not needed.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    15 16 17 18 19 20 21 22 23 24
    Remove lineRemove lineRemove line
    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
    #include "Display_a_map.h"
    
    #include "ArcGISRuntimeEnvironment.h"
    
    #include "Basemap.h"
    #include "Map.h"
    
    #include "MapQuickView.h"
    
    #include <QUrl>
    
  5. Add include statements for the MobileMapPackage class, the Error class, and the Qt Qdir class.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    13 14 15 16 17 18 19
    Add line.Add line.Add line.
    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
    #include "Display_an_mmpk.h"
    
    #include "MapQuickView.h"
    
    #include "MobileMapPackage.h"
    #include "Error.h"
    #include <QDir>
    
  6. Remove the comma after QObject(parent) and then modify the constructor to remove initialization with BasemapStyle and the Map. (Note that the BasemapStyle configured for your project may be different than that shown here.)

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    30 31 32 33 34
    Change lineRemove line
    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
    Display_a_map::Display_a_map(QObject* parent /* = nullptr */):
    
        QObject(parent),
    
        m_map(new Map(BasemapStyle::ArcGISTopographic, this))
    
  7. Remove the line of code that assigns the Map (m_map) to m_mapView.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    58 59 60 61 62 63 64 65 66 67 68
    Remove line
    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
    // Set the view (created in QML)
    void Display_a_map::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
    
        m_mapView->setMap(m_map);
    
  8. Add a call to a function that reads the map from the mobile map package. You will implement this function in the next step.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    37 38 39 40 41 42 43 44 45 46 47 48 49
    Add line.
    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
    // Set the view (created in QML)
    void Display_an_mmpk::setMapView(MapQuickView* mapView)
    {
        if (!mapView || mapView == m_mapView)
        {
            return;
        }
    
        m_mapView = mapView;
    
        setupMapFromMmpk();
    
        emit mapViewChanged();
    
  9. Add code to implement setupMapFromMmpk(). This function defines the path to the MMPK file, instantiates the mobile map package using the MobileMapPackage constructor, loads the mobile map package, and once loaded, sets the first map in the mobile map package to the MapView . This also checks that the MMPK file loaded correctly.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    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
    Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.Add line.
    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
        setupMapFromMmpk();
    
        emit mapViewChanged();
    
    }
    
    void Display_an_mmpk::setupMapFromMmpk()
    {
        // Instantiate a MobileMapPackage object and establish the path to the MMPK file.
        MobileMapPackage* m_mobileMapPackage = new MobileMapPackage(QDir::homePath() + "/ArcGIS/Runtime/Data/mmpk/MahouRivieraTrails.mmpk", this);
    
        // Use connect to signal when the package is done loading so that m_mapView can be set to the first map (0).
        // Check that the mmpk file has loaded correctly.
        connect(m_mobileMapPackage, &MobileMapPackage::doneLoading, this, [m_mobileMapPackage, this](Error error)
        {
            // Check that the mmpk file has loaded correctly
            if (!error.isEmpty())
            {
                qDebug() << "Error:" << error.message()<< error.additionalMessage();
                return;
            }
    
            // Get the first map in the list of maps, and set the map on the map view to display.
            // This could be set to any map in the list.
            m_mapView->setMap(m_mobileMapPackage->maps().at(0));
        });
    
        m_mobileMapPackage->load();
    }
  10. Press Ctrl + R to run the app.

You see a map of trailheads, trails, and parks for the area south of the Santa Monica mountains. Drag, zoom in, and zoom out 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.