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

The following are required for this tutorial:

  1. An ArcGIS account to access API keys. If you don't have an account, sign up for free.
  2. Your system meets the system requirements.
  3. The ArcGIS Maps SDK for Qt, version 200.3.0 or later is installed.
  4. The Qt 6.5.1 software development framework is installed.

Steps

Get the 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 a local path on your hard drive (for example: C:/tutorial_mmpk/MahouRivieraTrails.mmpk). Make a note of this path as you will need supply it in the function setupMapFromMmpk() towards the end of this tutorial.

Create a new ArcGIS Maps Qt Creator Project

  1. Select the ArcGIS Maps 200.3.0 Qt Quick C++ app project template (or a later version) and click Choose.

  2. Name your project display_an_mmpk and specify the "Create in" directory a location of your choosing. Click Next.

  3. In the Define Build System dialog, select qmake for your build system. Click Next.

  4. In the Define Project Details dialog, if desired give this app a description or keep the default text. Leave the rest of this dialog as is. Then click Next.

  5. On the Kit Selection dialog, check the kit(s) you previously set up when you installed the API. You should select a Desktop kit to run this tutorial (for example Desktop Qt 6.5.0 MSVC2019 64bit). Then click Next.

  6. At the Project Management dialog, the option to Add as a subproject to root project is only available if you have already created a root project. Ignore this dialog for this tutorial. Click Next.

Modify the project to remove unused template code from the header file

The project you created from the ArcGIS Maps Qt Quick C++ app project template includes a class for the Map. Because the mobile map package (MMPK) contains the map you will remove the unneeded code from your project.

  1. In the Edit tab, 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
    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
    #ifndef DISPLAY_AN_MMPK_H
    #define DISPLAY_AN_MMPK_H
    
    namespace Esri::ArcGISRuntime {
    
    class Map;
    
  2. Now remove the code that creates the Map pointer variable m_map.

    Display_an_mmpk.h
    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
    private:
        Esri::ArcGISRuntime::MapQuickView* mapView() const;
        void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
        Esri::ArcGISRuntime::Map* m_map = nullptr;
    

Modify the project to remove the unused template code from the C++ file

The project you created from the ArcGIS Maps Qt Quick C++ app project template includes: references to Map and MapTypes header files, a call to a constructor to initialize a new Map based on a Basemap, and a call to the MapView::setMap method that are not needed. Because the mobile map package (MMPK) contains the map you will remove the unneeded code from your project.

  1. In Edit tab, double-click Sources > Display_an_mmpk.cpp to open the file. Remove the lines #include "Map.h" and #include "MapTypes.h".

    Display_an_mmpk.cpp
    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
    #include "Display_an_mmpk.h"
    
    #include "Map.h"
    #include "MapTypes.h"
    
    #include "MapQuickView.h"
    
  2. 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
    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
    using namespace Esri::ArcGISRuntime;
    
    Display_an_mmpk::Display_an_mmpk(QObject* parent /* = nullptr */):
    
        QObject(parent),
    
        m_map(new Map(BasemapStyle::ArcGISStreets, this))
    
  3. Remove the line of code that assigns the variable m_map to m_mapView.

    Display_an_mmpk.cpp
    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
    // 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);
    

Modify the project to use a mobile map package in the header file

The mobile map package contains the map, basemap, and all the data layers it requires. We will modify the header file to declare the new function to implement loading the mobile map package (MMPK).

  1. 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
    Expand
    Use dark colors for code blocks
    37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 38 39 40 41 42 42 42 42 42 42
    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
    private:
        Esri::ArcGISRuntime::MapQuickView* mapView() const;
        void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
    
        void setupMapFromMmpk();
    
    Expand

Modify the project to use a mobile map package in the C++ file

The mobile map package contains the map, basemap, and all the data layers it requires. We will modify the C++ file to add the required include statements, provide the function that performs the work to load the mobile map package (MMPK), and call the function.

  1. Add #include statements for the MobileMapPackage, and Error classes.

    Display_an_mmpk.cpp
    Use dark colors for code blocks
    12 12 12 12 12 12 12 12 12 12 12 12 13 14 15 16 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18
    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"
    
  2. 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
    36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 37 38 39 40 41 42 43 44 45 46 47 48 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 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();
    
  3. 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. IMPORTANT: Make sure and provide correct path to the MMPK file on your hard drive for the string <PATH_TO_MMPK_FILE>/MahouRivieraTrails.mmpk (for example: C:/tutorial_mmpk/MahouRivieraTrails.mmpk).

    Display_an_mmpk.cpp
    Expand
    Use dark colors for code blocks
    46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 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
    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("<PATH_TO_MMPK_FILE>/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();
    }
  4. 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.