Honor mobile map package expiration date

View inC++QMLView on GitHubSample viewer app

Access the expiration information of an expired mobile map package.

screenshot

Use case

The data contained within a mobile map package (MMPK) may only be relevant for a fixed period of time. Using ArcGIS Pro, the author of an MMPK can set an expiration date to ensure the user is aware the data is out of date.

As long as the author of an MMPK has set an expiration date, the expiration date can be read even if the MMPK has not yet expired. For example, developers could also use this API to warn app users that an MMPK may be expiring soon.

How to use the sample

Load the app. The author of the MMPK used in this sample chose to set the MMPK's map as still readable, even if it's expired. The app presents expiration information to the user.

How it works

  1. Create a MobileMapPackage passing in the path to the mobile map package's location on the device.
  2. Load the mobile map package.
  3. Present Expiration information to the user with the Expiration.message and Expiration.dateTime properties, which are set by the map author.

Relevant API

  • Expiration
  • MobileMapPackage

Offline Data

Read more about how to set up the sample's offline data here.

Link Local Location
Lothian Rivers Anno MMPK <sdcard>/ArcGIS/Samples/MapPackage/LothianRiversAnno.mmpk

Tags

expiration, mmpk

Sample Code

HonorMobileMapPackageExpiration.qml
Use dark colors for code blocksCopy
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// [WriteFile Name=HonorMobileMapPackageExpiration, Category=Maps]
// [Legal]
// Copyright 2019 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import Esri.ArcGISRuntime 100.15
import Esri.ArcGISExtras 1.1

Rectangle {
    width: 800
    height: 600

    property url dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/mmpk/"
    property string expirationDate
    property string expirationTime
    property string expirationMessage

    // Create MapView
    MapView {
        id: mapView
        anchors.fill: parent

        Component.onCompleted: {
            // Set the focus on MapView to initially enable keyboard navigation
            forceActiveFocus();
        }
    }

    Component.onCompleted: {
        mmpk.load();
    }

    // Create a Mobile Map Package and set the path
    MobileMapPackage {
        id: mmpk
        path: dataPath + "LothianRiversAnno.mmpk"

        // wait for the mobile map package to load
        onLoadStatusChanged: {
            // only proceed once the map package is loaded
            if (loadStatus !== Enums.LoadStatusLoaded) {
                return;
            }

            if (mmpk.maps.length < 1) {
                return;
            }

            // check if the package is expired
            if (expiration) {
                if (expiration.expired) {
                    const dateTime = expiration.dateTime;
                    expirationDate = dateTime.toISOString().split("T")[0];
                    expirationTime = dateTime.toISOString().split("T")[1].substring(0,8)
                    expirationMessage = expiration.message;

                    // return if access after expiration is not allowed
                    if (expiration.type === Enums.ExpirationTypePreventExpiredAccess)
                        return;
                }
            }

            // set the map view's map to the first map in the mobile map package
            mapView.map = mmpk.maps[0];
        }

        onErrorChanged: {
            console.log("Mobile Map Package Error: %1 %2".arg(error.message).arg(error.additionalMessage));
        }
    }

    Rectangle {
        anchors {
            verticalCenter: parent.verticalCenter
            left: parent.left
            right: parent.right
        }
        height: 100
        color: "#303030"
        opacity: 0.75
        visible: mmpk.expiration ? mmpk.expiration.expired : false

        Text {
            id: expirationText
            anchors.centerIn: parent
            width: parent.width
            horizontalAlignment: Text.AlignHCenter
            wrapMode: Text.WordWrap
            color: "white"
            text: "%1\nExpired on %2 at %3 UTC".arg(expirationMessage).arg(expirationDate).arg(expirationTime)
        }
    }
}

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