Learn how to display 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 a mobile map package (MMPK) A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more .

Map displaying the Mahou Riviera area with hiking trails and trailhead markers.

In this tutorial you will display a fully interactive 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 a mobile map package (MMPK) A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more . The map contains a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more 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 Maps SDK for Qt, version 300.1.0 or later is installed.

  4. The Qt 6.8.2 software development framework or later is installed.

  5. The CMake build system is installed.

Get the mobile map package

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.

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.

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

Create a new ArcGIS Maps Qt Creator Project

  1. Start Qt Creator.

  2. In the top menu bar, click File > New Project.

  3. In the New Project dialog, in the left frame, under Projects, select ArcGIS. Then select the ArcGIS Maps 300.1.0 Qt Quick C++ app project template (or a later version) and click Choose. This will launch the template wizard.

  4. In the Project Location template, name your project Display_an_mmpk. You can specify your own “create in” location for where the project will be created or leave the default. Click Next.

  5. In the Define Build System template, keep the default choice of CMake for your build system. Click Next.

  6. In the Define Project Details template, give this app a description or leave as is. For the GeoView type dropdown menu accept the default, 2D Map. For the ArcGIS Online Basemap dropdown menu, leave the default. There is no need to supply an API Key (also called an access token), you can leave it blank. Click Next.

  7. In the Kit Selection template, check on the kit you previously set up when you installed Qt (Desktop Qt 6.8.2 MSVC2022 64bit or higher required). Click Next.

  8. In the Project Management template, the option to Add as a subproject to root project is only available if you have already created a root project. If you have a version control system set up, you can select it in the dropdown but it is not needed to complete this tutorial. Click Finish to complete the template wizard.

  9. Close any open files as a result of the creation of the new Qt project process.

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.

In the project Display_an_mmpk > Display_an_mmpk > Header Files folder of Qt Creator, double-click the Display_an_mmpk.h file to open it. Remove the code that forward declares the Map class.

Display_an_mmpk.h
#ifndef DISPLAY_AN_MMPK_H
#define DISPLAY_AN_MMPK_H
namespace Esri::ArcGISRuntime {
class Map;

Remove the code that creates the Map pointer variable m_map. Then save the file.

Display_an_mmpk.h
private:
Esri::ArcGISRuntime::MapQuickView* mapView() const;
void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
Esri::ArcGISRuntime::Map* m_map = nullptr;

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.

In the project Display_an_mmpk > Display_an_mmpk > Source Files folder of Qt Creator, double-click the Display_an_mmpk.cpp file to open it. Remove the lines #include "Map.h" and #include "MapTypes.h".

Display_an_mmpk.cpp
#include "Display_an_mmpk.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"

Modify the constructor to remove the line with the comma and the m_map variable.

Display_an_mmpk.cpp
using namespace Esri::ArcGISRuntime;
Display_an_mmpk::Display_an_mmpk(QObject *parent /* = nullptr */)
: QObject(parent)
, m_map(new Map(BasemapStyle::ArcGISStreets, this))
{}

Finally, in the setMapView function remove the line of code that assigns the variable m_map to m_mapView. Then save the file.

Display_an_mmpk.cpp
// Set the view (created in QML)
void Display_an_mmpk::setMapView(MapQuickView* mapView)
{
if (!mapView || mapView == m_mapView)
{
return;
}
m_mapView = mapView;
m_mapView->setMap(m_map);
emit mapViewChanged();
}

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).

In the project Display_an_mmpk > Display_an_mmpk > Header Files folder of Qt Creator, double-click the Display_an_mmpk.h file to open it. Under the private section, declare the new function you will implement to load the mobile map package. Then save the file.

Display_an_mmpk.h
private:
Esri::ArcGISRuntime::MapQuickView* mapView() const;
void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
void setupMapFromMmpk();

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.

In the project Display_an_mmpk > Display_an_mmpk > Source Files folder of Qt Creator, double-click the Display_an_mmpk.cpp file to open it. Add #include statements for the MobileMapPackage, and Error classes.

Display_an_mmpk.cpp
#include "Display_an_mmpk.h"
#include "MapQuickView.h"
#include "MobileMapPackage.h"
#include "Error.h"

In the setMapView() function, add a call to the setMapFromMmpk() function that reads the map from the mobile map package. You will implement this function in the next step.

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

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
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();
}

A MobileMapPackage can contain many maps in a Maps list. Loading the mobile map package A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more is an asynchronous process. The file is read on a thread that does not block the UI.

Press Ctrl + R to run the app.

You should 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.

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

Option 2: Download the solution

Click the Download solution link on this page under the Solution title and unzip the file to a location on your machine.

In Qt Creator, choose File > Open File or Project… from them menus. In the Open file dialog, navigate to the CMakeLists.txt file for the solution you unzipped and click the Open button.

The Configure Project window will appear for you to specify the Qt Kit to use to compile the project. Check on the Qt Kit called Desktop Qt 6.8.2 MSVC2022 64bit before clicking the Configure Project button at the bottom of the page.

Set the path to the MMPK file

In the project Display_an_mmpk > Display_an_mmpk > Source Files folder of Qt Creator, double-click the Display_an_mmpk.cpp file to open it. Locate the following lines and update m_mobileMapPackage variable with correct path to the MMPK file on your device for the string <PATH_TO_MMPK_FILE>/MahouRivieraTrails.mmpk (for example: C:/tutorial_mmpk/MahouRivieraTrails.mmpk). Then save the file.

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

Run the app

Press Ctrl + R to run the app.

You should 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: