MobileMapPackage Class

  • MobileMapPackage
  • class Esri::ArcGISRuntime::MobileMapPackage

    A mobile map package. More...

    Header: #include <MobileMapPackage.h>
    Since: Esri::ArcGISRuntime 100.0
    Inherits: Esri::ArcGISRuntime::Object and Esri::ArcGISRuntime::Loadable

    This class was introduced in Esri::ArcGISRuntime 100.0.

    Public Functions

    MobileMapPackage(const QString &path, QObject *parent = nullptr)
    virtual ~MobileMapPackage() override
    void close()
    Esri::ArcGISRuntime::Expiration expiration() const
    Esri::ArcGISRuntime::Item *item() const
    Esri::ArcGISRuntime::LocatorTask *locatorTask() const
    QList<Esri::ArcGISRuntime::Map *> maps() const
    QString path() const
    QString version() const

    Reimplemented Public Functions

    virtual void cancelLoad() override
    virtual void load() override
    virtual Esri::ArcGISRuntime::Error loadError() const override
    virtual Esri::ArcGISRuntime::LoadStatus loadStatus() const override
    virtual void retryLoad() override

    Signals

    void doneLoading(Esri::ArcGISRuntime::Error loadError)
    void loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)
    void unpackCompleted(QUuid taskId, bool success)

    Static Public Members

    Esri::ArcGISRuntime::MobileMapPackage *instance()
    Esri::ArcGISRuntime::TaskWatcher unpack(const QString &mobileMapPackageFilePath, const QString &outputDirectory)

    Detailed Description

    Mobile map packages allow you to work with maps on a mobile device. A mobile map package contains all of the files necessary to work with your maps and is stored on a device as either:

    • A single archive file with an .mmpk extension.
    • A directory containing an unpacked mobile map package.

    You can create a mobile map package using either:

    • ArcGIS Pro (from version 1.3). This version of the ArcGIS Runtime SDK supports any MobileMapPackage up to major version 5. Mobile map packages created with ArcGIS Pro are stored in a file with an .mmpk extension.
    • ArcGIS Runtime. Use the OfflineMapTask::generateOfflineMap method to generate and download a mobile map package on-demand, or use the OfflineMapTask::downloadPreplannedOfflineMap to download a mobile map package already prepared by the map author. Mobile map packages created with the OfflineMapTask are stored in a directory containing an unpacked mobile map package.

    A mobile map package can encapsulate one or more maps along with their layers and data. Each package contains an Item with metadata about the package (description, thumbnail, etc.).

    Mobile map packages created with ArcGIS Pro can also include transportation networks, locators, and links to online services. You can choose whether to use:

    Online services (such as traffic or weather) can provide excellent contextual information for your users. If the mobile map package is going to be used in areas of poor connectivity, however, you must ensure that data critical to your workflow is stored locally on the device.

    Mobile map packages implement the Loadable interface; you need to load the MobileMapPackage before you can access its content. Once loaded you can:

    • Determine the version of this package using the MobileMapPackage::version property. ArcGIS Runtime currently supports mobile map packages up to and including major version 5. If the package is from an unsupported version, it will fail to load.
    • Discover whether the mobile map package has expired using the MobileMapPackage::expiration property.
    • Access the individual maps and display them in a MapView.
    • Programmatically add, modify, and remove layers in the map. Mobile map packages, however, are read-only and these changes to maps or layers are not persisted.

    Example:

    Obtain a Map from a MobileMapPackage and display it in a MapView

    // instatiate a mobile map package
    m_mobileMapPackage = new MobileMapPackage(path, this);
    
    // wait for the mobile map package to load
    connect(m_mobileMapPackage, &MobileMapPackage::doneLoading, this, [this](Error error)
    {
      if (!error.isEmpty())
      {
        qDebug() << QString("Package load error: %1 %2").arg(error.message(), error.additionalMessage());
        return;
      }
    
      if (!m_mobileMapPackage || !m_mapView || m_mobileMapPackage->maps().isEmpty())
      {
        return;
      }
    
      // The package contains a list of maps that could be shown in the UI for selection.
      // For simplicity, obtain the first map in the list of maps.
      // set the map on the map view to display
      m_mapView->setMap(m_mobileMapPackage->maps().at(0));
    
    });
    
    m_mobileMapPackage->load();

    Member Function Documentation

    MobileMapPackage::MobileMapPackage(const QString &path, QObject *parent = nullptr)

    Constructor that takes a file path and an optional parent.

    The path can refer to a file with a .mmpk extension or a directory containing an unpacked mobile map package.

    Note: Constructing a MobileMapPackage from a path to a .mmpk file does not load the MobileMapPackage automatically. You must call load to load it explicitly.

    [signal] void MobileMapPackage::doneLoading(Esri::ArcGISRuntime::Error loadError)

    Signal emitted when this object is done loading.

    • loadError - Details about any error that may have occurred.

    Note: If there is a load error it will also be emitted on the errorOccurred signal.

    See also Loadable and Object.

    [signal] void MobileMapPackage::loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)

    Signal emitted when the load status changes for this object.

    • loadStatus - The load status of this object.

    See also Loadable.

    [signal] void MobileMapPackage::unpackCompleted(QUuid taskId, bool success)

    Signal emitted when unpack completes.

    • taskId - The task ID that this signal corresponds to.
    • success - Whether the task was successful.

    [override virtual] MobileMapPackage::~MobileMapPackage()

    Destructor.

    [override virtual] void MobileMapPackage::cancelLoad()

    Reimplements: Loadable::cancelLoad().

    See Loadable.

    void MobileMapPackage::close()

    Closes a mobile map package.

    Closes a mobile map package and frees file locks on the underlying .mmpk file or directory.

    All references to mobile map package data (maps, layers, tables, networks, locators, etc.) should be released before closing the package. If active references to mobile map package data exist, this method will still close the package, but subsequent rendering and data access methods will fail. Results of accessing mobile map package data after close are undefined.

    After closing a mobile map package, the underlying .mmpk file or directory can be moved or deleted.

    Closing a mobile map package is not necessary if the package has not been loaded.

    This function was introduced in Esri::ArcGISRuntime 100.6.

    See also Geodatabase::close.

    Esri::ArcGISRuntime::Expiration MobileMapPackage::expiration() const

    Gets expiration details for this mobile map package, if provided.

    Expiration details provide:

    • The package’s expiration date and time.
    • Whether the maps can be accessed after expiration.
    • Any messages relevant for the user.

    These expiration details can be specified when the author creates a mobile map package using ArcGIS Pro (from version 2.4). This requires the ArcGIS Pro Publisher Extension. Mobile map packages created with the OfflineMapTask do not support expiration.

    By publishing a package with expiration details, the author can control the experience an end-user has when they try to access information that is no longer valid. For example, for time limited data (such as major sporting events), the author can ensure that the data cannot be accessed after the expiry date.

    During package loading, the ArcGIS Runtime will determine whether the mobile map package was authored with expiration. If so, then this property will be populated.

    If the package has expired and was authored as ExpirationType::preventExpiredAccess, loading will fail and you will not be able to access the maps. The expiration details will be accessible for you to examine and/or communicate to the user.

    You should check Expiration::isEmpty to see whether the returned expiration object is valid.

    This function was introduced in Esri::ArcGISRuntime 100.5.

    [static] Esri::ArcGISRuntime::MobileMapPackage *MobileMapPackage::instance()

    Returns an instance of the MobileMapPackage singleton.

    The instance is used to connect to the Object::errorOccurred, unpackCompleted signals. You do not need to obtain the instance to call the static methods on the MobileMapPackage.

    This function was introduced in Esri::ArcGISRuntime 100.2.

    Esri::ArcGISRuntime::Item *MobileMapPackage::item() const

    The mobile map package's Item describing metadata about the package.

    The item includes the metadata about the mobile map package, such as:

    • Title
    • Snippet (summary)
    • Description
    • Tags
    • Thumbnail

    If the package was created with ArcGIS Pro, the metadata was provided by the package author. If the package was created using the OfflineMapTask, the metadata was provided by the originating web map.

    A package's item will be an instance of a LocalItem.

    Returns nullptr if the package is not loaded.

    See also Item.

    [override virtual] void MobileMapPackage::load()

    Reimplements: Loadable::load().

    See Loadable.

    [override virtual] Esri::ArcGISRuntime::Error MobileMapPackage::loadError() const

    Reimplements: Loadable::loadError() const.

    See Loadable.

    [override virtual] Esri::ArcGISRuntime::LoadStatus MobileMapPackage::loadStatus() const

    Reimplements: Loadable::loadStatus() const.

    See Loadable.

    Esri::ArcGISRuntime::LocatorTask *MobileMapPackage::locatorTask() const

    Gets the locator contained in the mobile map package as a LocatorTask.

    Use this task to geocode and reverse-geocode addresses and places. There is only one LocatorTask in each mobile map package but it can be used by all maps.

    Returns nullptr if there is no LocatorTask in the package or the package is not loaded.

    See also LocatorTask.

    QList<Esri::ArcGISRuntime::Map *> MobileMapPackage::maps() const

    Gets a list of the maps contained in the mobile map package.

    To use the maps in a MobileMapPackage, you first need to load the package. If the mobile map package was created with ArcGIS Pro, the maps are presented in the same order in which they were packaged. Mobile map packages created with the OfflineMapTask will only contain one map.

    If you display the map by setting the map to a MapView, the map will automatically load. If you only need to access the map's content or metadata, you will need to load it by calling GeoModel::load. If the package is not loaded, an empty collection is returned.

    QString MobileMapPackage::path() const

    Gets the path of the mobile map package.

    The path can refer to a file with an .mmpk extension or a directory containing an unpacked mobile map package.

    [override virtual] void MobileMapPackage::retryLoad()

    Reimplements: Loadable::retryLoad().

    See Loadable.

    [static] Esri::ArcGISRuntime::TaskWatcher MobileMapPackage::unpack(const QString &mobileMapPackageFilePath, const QString &outputDirectory)

    Unpacks the mobile map package at mobileMapPackageFilePath to the outputDirectory

    This method returns a TaskWatcher for the asynchronous operation. Connect to the MobileMapPackage singleton provided by the instance() method to determine when the operation is completed.

    The unpack task writes the full content of the mobile map package to the output directory. Care should be taken on devices with limited storage space, especially if the original package is very large. After unpacking, you can remove the original .mmpk file from the device.

    Note that unpacking will fail if the package is expired and was authored as ExpirationType::preventExpiredAccess.

    • mobileMapPackageFilePath - the path to a mobile map package file (.mmpk)
    • outputDirectory - a path to a directory to write the mobile map package contents.

    This function was introduced in Esri::ArcGISRuntime 100.2.

    QString MobileMapPackage::version() const

    Returns the version of the mobile map package.

    The mobile map package version is set when the package is authored in ArcGIS Pro or when it is generated by the OfflineMapTask.

    This property will be populated when you attempt to load the package. The version property will always be populated for you to examine, even if the package is an unsupported version.

    ArcGIS Runtime SDKs currently support mobile map packages up to and including major version 5.

    You may wish to check the version property before trying to access specific functionality. For example:

    • Expiration details are only available from mobile map package version 3.1 onwards.
    • Links to online services are only available from mobile map package version 4.0 onwards.

    If the package fails to load, check that the version number has not exceeded the supported major version.

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