Generate offline map with local basemap

View on GitHubSample viewer app

Take a web map offline using a local basemap on the device.

Image of generate offline map with local basemap

Use case

There are a number of use-cases where you may wish to use a basemap which is already on the device, rather than downloading:

  • You want to limit the total download size.
  • You want to be able to share a single set of basemap files between many offline maps.
  • You want to use a custom basemap (for example authored in ArcGIS Pro) which is not available online.
  • You do not wish to sign into ArcGIS.com in order to download Esri basemaps.

The author of a web map can support the use of basemaps which are already on a device by configuring the web map to specify the name of a suitable basemap file. This could be a basemap which:

  • Has been authored in ArcGIS Pro to make use of your organizations custom data.
  • Is available as a PortalItem which can be downloaded once and re-used many times.

How to use the sample

Click on the "Take Map Offline" button. You will be prompted to choose whether you wish to download a basemap or use the local basemap (which is already saved in the samples-data directory as "naperville_imagery.tpkx").

If you choose to download the online basemap, the offline map will be generated with the same (topographic) basemap as the online web map.

If you choose to use the local basemap from the device, the offline map will be generated with the local imagery basemap. The download will be quicker since no tiles are exported or downloaded.

How it works

  1. Create an ArcGISMap with a portal item pointing to the web map.
  2. Create GenerateOfflineMapParameters specifying the download area geometry, min scale, and max scale.
  3. Once the generate offline map parameters are created, check the getReferenceBasemapFilename() property. The author of an online web map can configure this setting to indicate the name of a suitable basemap. In this sample, the app checks the local device for the suggested "naperville_imagery.tpkx" file.
  4. If the user chooses to use the basemap on the device, use setReferenceBasemapFileName() and setReferenceBasemapDirectory() on the generate offline map parameters to set the absolute path of the directory which contains the .tpkx file. If this property is set, no online basemap will be downloaded and instead, the mobile map will be created with a reference to the .tpkx on the device.
  5. A GenerateOfflineMapJob is created by calling offlineMapTask.generateOfflineMap passing the parameters and the download location for the offline map.
  6. Create the offline map job and start it.
  7. When the job is done, use getOfflineMap on the GenerateOfflineMapResult object to get the map.

Relevant API

  • GenerateOfflineMapJob
  • GenerateOfflineMapParameters
  • GenerateOfflineMapResult
  • OfflineMapTask

Offline data

This sample uses naperville_imagery.tpkx TileCache. It is downloaded from ArcGIS Online automatically.

Tags

basemap, download, local, offline, save, web map

Sample Code

GenerateOfflineMapDialog.javaGenerateOfflineMapDialog.javaGenerateOfflineMapWithLocalBasemapSample.java
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
/*
 * 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.
 */

package com.esri.samples.generate_offline_map_with_local_basemap;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;

/**
 * Custom dialog for selection of local basemap or online base map when generating an offline map.
 */
class GenerateOfflineMapDialog extends Dialog<Boolean> {

  @FXML
  private Label referencedBasemapFileNameLabel;
  @FXML
  private ButtonType localBasemapButton;
  @FXML
  private ButtonType downloadBasemapButton;

  private final StringProperty referencedBasemapFileName = new SimpleStringProperty();

  GenerateOfflineMapDialog() {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/generate_offline_map_with_local_basemap" +
            "/basemap_dialog.fxml"));
    loader.setRoot(this);
    loader.setController(this);

    setTitle("Generate offline map");

    try {
      loader.load();

      referencedBasemapFileNameLabel.textProperty().bind(referencedBasemapFileName);
    } catch (Exception e) {
      e.printStackTrace();
    }

    setResultConverter(dialogButton -> {
      if (dialogButton == localBasemapButton) {
        return true;
      } else if (dialogButton == downloadBasemapButton) {
        return false;
      }
      return null;
    });
  }

  public String getReferencedBasemapFileName() {
    return referencedBasemapFileName.get();
  }

  public StringProperty referencedBasemapFileNameProperty() {
    return referencedBasemapFileName;
  }

  public void setReferencedBasemapFileName(String referencedBasemapFileName) {
    this.referencedBasemapFileName.set(referencedBasemapFileName);
  }
}

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