Learn how to display a map from a mobile map package (MMPK).
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:
An ArcGIS account to access API keys. If you don't have an account, sign up for free.
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 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 Maps Qt Creator Project
Select the ArcGIS Maps 200.0.0 Qt Quick C++ app project template (or a later version) and click Choose.
You may have several selections for the ArcGIS project type. Be sure to select ArcGIS Maps 200.0.0 Qt Quick C++ app (or a later version).
Name your project display_an_mmpk.
Accept all defaults. At the Define Project Details window, leave the ArcGIS Online Basemap selection as is. Complete the project creation.
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. Then click Next.
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.
In Projects, double-click Headers > Display_an_mmpk.h to open the file. Remove the code that forward declares the Map class.
1. 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.)
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.
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
setupMapFromMmpk();
emit mapViewChanged();
}
voidDisplay_an_mmpk::setupMapFromMmpk(){
// Instantiate a MobileMapPackage object and establish the path to the MMPK file. MobileMapPackage* m_mobileMapPackage = newMobileMapPackage(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 correctlyif (!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 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 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.