Generate offline map with local basemap

View on GitHub
Sample viewer app

Use the OfflineMapTask to take a web map offline, but instead of downloading an online basemap, use one which is already 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 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

Tap on "Generate Offline Map". You will be prompted to choose whether you wish to download the online basemap or use the "naperville_imagery.tpk" basemap (see Offline Data section). If you choose to download the online basemap, the offline map will be generated with the same (topographic) basemap as the online web map. To download the Esri basemap, an organizational account is required.

If you choose to use the 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. Since the application is not exporting online ArcGIS Online basemaps you will not need to log-in.

How it works

  1. Create a PortalItem object using a web map's ID and create an ArcGISMap from it.
  2. Initialize an OfflineMapTask object using the map.
  3. Request the default parameters for the task with OfflineMapTask.createDefaultGenerateOfflineMapParametersAsync().
  4. A GenerateOfflineMapJob is created by calling OfflineMapTask.generateOfflineMap.

    • If desired, set the GenerateOfflineMapParameters.referenceBasemapDirectory to the absolute path of the directory which contains the .tpk file.
    • Otherwise a basemap will be downloaded.
  5. Run the GenerateOfflineMapJob with basemap settings from step 4.

Relevant API

  • GenerateOfflineMapJob
  • GenerateOfflineMapParameters
  • GenerateOfflineMapResult
  • OfflineMapTask

Offline Data

  1. Download the data from ArcGIS Online.
  2. Open your command prompt and navigate to the folder where you extracted the contents of the data from step 1.
  3. Push the data into the scoped storage of the sample app: adb push naperville_imagery.tpk /Android/data/com.esri.arcgisruntime.sample.generateofflinemapwithlocalbasemap/files/naperville_imagery.tpk


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

Sample Code
 * 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package com.esri.arcgisruntime.sample.generateofflinemapwithlocalbasemap;

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class LocalBasemapAlertDialogFragment extends DialogFragment {

  private static final String ARGS_TITLE = ProgressDialogFragment.class.getSimpleName() + "_title";
  private static final String ARGS_MESSAGE = ProgressDialogFragment.class.getSimpleName() + "_message";
  private static final String ARGS_POSITIVE = ProgressDialogFragment.class.getSimpleName() + "_positive";
  private static final String ARGS_NEGATIVE = ProgressDialogFragment.class.getSimpleName() + "_negative";

  private LocalBasemapAlertDialogFragment.OnClickListener mOnClickListener;

  private String mTitle;
  private String mMessage;
  private String mPositive;
  private String mNegative;

  public static LocalBasemapAlertDialogFragment newInstance(String title, String message, String positive, String negative) {
    LocalBasemapAlertDialogFragment fragment = new LocalBasemapAlertDialogFragment();
    Bundle args = new Bundle();
    args.putString(ARGS_TITLE, title);
    args.putString(ARGS_MESSAGE, message);
    args.putString(ARGS_POSITIVE, positive);
    args.putString(ARGS_NEGATIVE, negative);
    return fragment;

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    // prevent re-creation during configuration chance to allow us to dismiss this DialogFragment

    if (getArguments() != null) {
      mTitle = getArguments().getString(ARGS_TITLE);
      mMessage = getArguments().getString(ARGS_MESSAGE);
      mPositive = getArguments().getString(ARGS_POSITIVE);
      mNegative = getArguments().getString(ARGS_NEGATIVE);

  @Override public void onAttach(Context context) {
    if (context instanceof LocalBasemapAlertDialogFragment.OnClickListener) {
      mOnClickListener = (LocalBasemapAlertDialogFragment.OnClickListener) context;

  @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    // create a dialog to show progress
    return new AlertDialog.Builder(getActivity())
        .setPositiveButton(mPositive, (dialog, which) -> {
          if (mOnClickListener != null) {
        .setNegativeButton(mNegative, (dialog, which) -> {
          if (mOnClickListener != null) {

  public void onDestroyView() {
    Dialog dialog = getDialog();
    // handles
    if (dialog != null && getRetainInstance()) {

  interface OnClickListener {
    void onPositiveClick();
    void onNegativeClick();