Generate Offline Map (Overrides)

View on GitHub
Sample viewer app

Take a web map offline with additional options for each layer.

screenshot

Use case

When taking a web map offline, you may adjust the data (such as layers or tiles) that is downloaded by using custom parameter overrides. This can be used to reduce the extent of the map or the download size of the offline map. It can also be used to highlight specific data by removing irrelevant data. Additionally, this workflow allows you to take features offline that don't have a geometry - for example, features whose attributes have been populated in the office, but still need a site survey for their geometry.

How to use the sample

  1. When the sample starts, you may be prompted to sign into arcgis.com.
  2. Click on "Generate Offline Map (Overrides)".
  3. Use the range slider to adjust the min/max levelIds to be taken offline for the Streets basemap.
  4. Use the spin-box to set the buffer radius for the streets basemap.
  5. Click the buttons to skip the System Valves and Service Connections layers.
  6. Use the combo-box to select the maximum flow rate for the features from the Hydrant layer.
  7. Use the check-box to skip the geometry filter for the water pipes features.
  8. Click "Start Job"
  9. Wait for the progress bar to indicate that the task has completed.
  10. You should see that the basemap does not display when you zoom out past a certain range and is padded around the original area of interest. The network dataset should extend beyond the target area. The System Valves and Service Connections should be omitted from the offline map and the Hydrants layer should contain a subset of the original features.

The sample creates a PortalItem object using a web map’s ID. This portal item is also used to initialize an OfflineMapTask object. When the button is clicked, the sample requests the default parameters for the task, with the selected extent, by calling OfflineMapTask::createDefaultGenerateOfflineMapParameters. Once the parameters are retrieved, they are used to create a set of GenerateOfflineMapParameterOverrides by calling OfflineMapTask::createGenerateOfflineMapParameterOverrides. The overrides are then adjusted so that specific layers will be taken offline using custom settings.

Streets basemap (adjust scale range)

In order to minimize the download size for offline map, this sample reduces the scale range for the "World Streets Basemap" layer by adjusting the relevant ExportTileCacheParameters in the GenerateOfflineMapParameterOverrides. The basemap layer is used to contsruct an OfflineMapParametersKeyobject. The key is then used to retrieve the specific ExportTileCacheParameters for the basemap and the levelIds are updated to skip unwanted levels of detail (based on the values selected in the UI). Note that the original "Streets" basemap is swapped for the "for export" version of the service - see https://www.arcgis.com/home/item.html?id=e384f5aa4eb1433c92afff09500b073d.

Streets Basemap (buffer extent)

To provide context beyond the study area, the extent for streets basemap is padded. Again, the key for the basemap layer is used to obtain the key and the default extent Geometry is retrieved. This extent is then padded (by the distance specified in the UI) using the GeoemetryEngine::bufferGeodesic function and applied to the ExportTileCacheParameters.

System Valves and Service Connections (skip layers)

In this example, the survey is primarily concerned with the Hydrants layer, so other information is not taken offline: this keeps the download smaller and reduces clutter in the offline map. The two layers "System Valves" and "Service Connections" are retrieved from the operational layers list of the map. They are then used to construct an OfflineMapParametersKey. This key is used to obtain the relevant GenerateGeodatabaseParameters from the GenerateOfflineMapParameterOverrides::generateGeodatabaseParameters property. The GenerateLayerOption for each of the layers is removed from the geodatabse parameters layerOptions by checking for the FeatureLayer::serviceLayerId. Note, that you could also choose to download only the schema for these layers by setting the GenerateLayerOption::queryOption to GenerateLayerQueryOption::None.

Hydrant Layer (filter features)

Next, the hydrant layer is filtered to exclude certain features. This approach could be taken if the offline map is intended for use with only certain data - for example, where a re-survey is required. To achieve this, a whereClause (for example, "Flow Rate (GPM) < 500") needs to be applied to the hydrant's GenerateLayerOption in the GenerateGeodatabaseParameters. The minimum flow rate value is obtained from the UI setting. The sample constructs a key object from the hydrant layer as in the previous step, and iterates over the available GenerateGeodatabaseParameters until the correct one is found and the GenerateLayerOption can be updated.

Water Pipes Dataset (skip geometry filter)

Lastly, the water network dataset is adjusted so that the features are downloaded for the entire dataset - rather than clipped to the area of interest. Again, the key for the layer is constructed using the layer and the relevant GenerateGeodatabaseParameters are obtained from the overrides dictionary. The layer options are then adjusted to set useGeometry to false.

Having adjusted the GenerateOfflineMapParameterOverrides to reflect the custom requirements for the offline map, the original parameters and the custom overrides, along with the download path for the offline map, are then used to create a GenerateOfflineMapJob object from the offline map task. This job is then started and on successful completion the offline map is added to the map view. To provide feedback to the user, the progress property of GenerateOfflineMapJob is displayed in a window.

As the web map that is being taken offline contains an Esri basemap, this sample requires that you sign in with an ArcGIS Online organizational account.

Relevant API

  • ExportTileCacheParameters
  • GenerateGeodatabaseParameters
  • GenerateLayerOption
  • GenerateOfflineMapJob
  • GenerateOfflineMapParameterOverrides
  • GenerateOfflineMapParameters
  • GenerateOfflineMapResult
  • OfflineMapParametersKey
  • OfflineMapTask

Additional information

For applications where you just need to take all layers offline, use the standard workflow (using only GenerateOfflineMapParameters). For a simple example of how you take a map offline, please consult the "Generate offline map" sample.

Tags

adjust, download, extent, filter, LOD, offline, override, parameters, reduce, scale range, setting

Sample Code

GenerateOfflineMap_Overrides.qmlDownloadButton.qmlGenerateOfflineMap_Overrides.cppGenerateOfflineMap_Overrides.hGenerateWindow.qmlOverridesWindow.qml
                                                                                                                                     
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// [WriteFile Name=GenerateOfflineMap, Category=Maps]
// [Legal]
// Copyright 2018 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 QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.Samples 1.0
import Esri.ArcGISRuntime.Toolkit 100.11

GenerateOfflineMap_OverridesSample {
    id: offlineMapOverridesSample
    clip: true
    width: 800
    height: 600

    onUpdateStatus: generateWindow.statusText = status;
    onUpdateProgress: generateWindow.progressText = progress;
    onHideWindow: {
        generateWindow.hideWindow(time);

        if (success) {
            extentRectangle.visible = false;
            downloadButton.visible = false;
        }
    }

    onShowLayerErrors: {
        msgDialog.detailedText = error;
        msgDialog.open();
    }

    // add a mapView component
    MapView {
        id: mapView
        anchors.fill: parent
        objectName: "mapView"

        // Create a button and anchor it to the attribution top
        DownloadButton {
            id: downloadButton
            anchors {
                horizontalCenter: parent.horizontalCenter
                bottom: mapView.attributionTop
                margins: 5
            }
            visible: mapLoaded

            onButtonClicked: {
                setAreaOfInterest(extentRectangle.x, extentRectangle.y, (extentRectangle.x + extentRectangle.width), (extentRectangle.y + extentRectangle.height));
            }
        }
    }

    // Create an extent rectangle for selecting the offline area
    Rectangle {
        id: extentRectangle
        anchors.centerIn: parent
        width: parent.width - 50
        height: parent.height - 125
        color: "transparent"
        visible: mapLoaded
        border {
            color: "red"
            width: 3
        }
    }

    OverridesWindow {
        id: overridesWindow
        anchors.fill: parent
        visible: overridesReady

        onBasemapLODSelected: setBasemapLOD(min, max);
        onBasemapBufferChanged: setBasemapBuffer(buffer);
        onRemoveSystemValvesChanged: removeSystemValves();
        onRemoveServiceConnectionChanged: removeServiceConnection();
        onHydrantWhereClauseChanged: setHydrantWhereClause(whereClause);
        onClipWaterPipesAOIChanged: setClipWaterPipesAOI(clip);
        onOverridesAccepted: {
            generateWindow.visible = true;
            takeMapOffline();
        }
    }

    GenerateWindow {
        id: generateWindow
        anchors.fill: parent
    }

    Dialog {
        id: msgDialog
        modal: true
        x: Math.round(parent.width - width) / 2
        y: Math.round(parent.height - height) / 2
        standardButtons: Dialog.Ok
        title: "Layer Errors"
        property alias text : textLabel.text
        property alias detailedText : detailsLabel.text
        ColumnLayout {
            Text {
                id: textLabel
                text: "Some layers could not be taken offline."
            }
            Text {
                id: detailsLabel
            }
        }
    }

    BusyIndicator {
        anchors.centerIn: parent
        running: taskBusy
    }

    /* Uncomment this section when running as standalone application
    AuthenticationView {
        anchors.fill: parent
    }
    */
}

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