View on GitHub Sample viewer app

Take a map offline using a preplanned map area.

Image of download preplanned map area

Use case

Generating offline maps on demand for a specific area can be time consuming for users and a processing load on the server. If areas of interest are known ahead of time, a web map author can pre-create packages for these areas. This way, the generation only needs to happen once, making the workflow more efficient for users and servers.

An archeology team could define preplanned map areas for dig sites which can be taken offline for field use. To see the difference, compare this sample to the “Generate offline map” sample.

How to use the sample

Select a map area from the Preplanned map areas list. The download progress will be shown and when a download is complete it will be displayed in the map view.

How it works

  1. Open the online ArcGISMap from a PortalItem and display it.
  2. Create an OfflineMapTask using the portal item.
  3. Get the PreplannedMapAreas from the task.
  4. To download a selected map area, create default DownloadPreplannedOfflineMapParameters from the OfflineMapTask using the selected preplanned map area.
  5. Set the update mode of the preplanned map area.
  6. Use the parameters and a local path to create a DownloadPreplannedOfflineMapJob from the task.
  7. Start the DownloadPreplannedOfflineMapJob. Once it has completed, get the DownloadPreplannedOfflineMapResult.
  8. Get the ArcGISMap from the result and display it in the MapView.

Relevant API

  • DownloadPreplannedOfflineMapJob
  • DownloadPreplannedOfflineMapParameters
  • DownloadPreplannedOfflineMapResult
  • OfflineMapTask
  • PreplannedMapArea

About the data

The Naperville stormwater network map is based on ArcGIS Solutions for Stormwater and provides a realistic depiction of a theoretical stormwater network.

Additional information

PreplannedUpdateMode can be used to set the way the preplanned map area receives updates in several ways:

  • NoUpdates - No feature updates will be performed.
  • DownloadScheduledUpdates - Scheduled, read-only updates will be downloaded from the online map area and applied to the local mobile geodatabases.
  • DownloadScheduledUpdatesAndUploadNewFeatures - Scheduled, read-only updates are downloaded from the online map area and applied to the local mobile geodatabases. Newly added features can also be uploaded to the feature service.
  • SyncWithFeatureServices - Changes, including local edits, will be synced directly with the underlying feature services.

For more information about offline workflows, see Offline maps, scenes, and data in the ArcGIS Developers guide.

Tags

map area, offline, pre-planned, preplanned

Sample Code

MainActivity.kt MainActivity.kt DownloadPreplannedMapAreaViewModel.kt DownloadPreplannedMapAreaScreen.kt
/* Copyright 2025 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.arcgismaps.sample.downloadpreplannedmaparea
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.downloadpreplannedmaparea.screens.DownloadPreplannedMapAreaScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import java.io.File
class MainActivity : ComponentActivity() {
// The directory where the offline map will be saved
private val offlineMapPath by lazy {
application.getExternalFilesDir(null)?.path.toString() + File.separator + application.getString(
R.string.download_preplanned_map_area_app_name
)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
// Delete any existing offline maps, to reset sample state
File(offlineMapPath).deleteRecursively()
enableEdgeToEdge()
setContent {
SampleAppTheme {
DownloadPreplannedMapAreaApp()
}
}
}
@Composable
private fun DownloadPreplannedMapAreaApp() {
Surface(color = MaterialTheme.colorScheme.background) {
DownloadPreplannedMapAreaScreen(
sampleName = getString(R.string.download_preplanned_map_area_app_name)
)
}
}
}