Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate offline map with custom parameters #314

Open
wants to merge 12 commits into
base: v.next
Choose a base branch
from
63 changes: 63 additions & 0 deletions samples/generate-offline-map-with-custom-parameters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generate offline map with custom parameters

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

![Image of generate offline map with custom parameters](generate-offline-map-with-custom-parameters.png)

## 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

To modify the overrides parameters:

* Use the min/max scale input fields to adjust the level IDs to be taken offline for the streets basemap.
* Use the extent buffer distance input field to set the buffer radius for the streets basemap.
* Check the checkboxes for the feature operational layers you want to include in the offline map.
* Use the min hydrant flow rate input field to only download features with a flow rate higher than this value.
* Select the "Water Pipes" checkbox if you want to crop the water pipe features to the extent of the map.

After you have set up the overrides to your liking, tap the "Generate offline map" button to start the download. A progress bar will display. Tap the "Cancel" button if you want to stop the download. When the download is complete, the view will display the offline map. Pan around to see that it is cropped to the download area's extent.

## How it works

1. Load a web map from a `PortalItem`.
2. Create an `OfflineMapTask` with the map.
3. Generate default task parameters using the extent area you want to download with `offlineMapTask.createDefaultGenerateOfflineMapParameters(areaOfInterest)`.
4. Generate additional "override" parameters using the default parameters with `offlineMapTask.createGenerateOfflineMapParameterOverrides(generateOfflineMapParameters)`.
5. For the basemap:
* Get the parameters `OfflineMapParametersKey` for the basemap layer.
* Get the `ExportTileCacheParameters` for the basemap layer with `parameterOverrides.exportTileCacheParameters[basemapParamKey]`.
* Set the level IDs you want to download with `exportTileCacheParameters.levelIds.add(...)`.
* To buffer the extent, use `exportTileCacheParameters.areaOfInterest` where bufferedGeometry can be calculated with the `GeometryEngine`.
6. To remove operational layers from the download:
* Create a `OfflineParametersKey` with the operational layer.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Create a `OfflineParametersKey` with the operational layer.
* Create an `OfflineParametersKey` with the operational layer.

* Get the generate geodatabase layer options using the key with `parameterOverrides.generateGeodatabaseParameters[key].layerOptions`
* Using the `GenerateLayerOption` list, and remove the layer if its the layer option's ID matches the layer's ID.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Using the `GenerateLayerOption` list, and remove the layer if its the layer option's ID matches the layer's ID.
* Use the `GenerateLayerOption` list to remove the layer if the layer option's ID matches the layer's ID.

7. To filter the features downloaded in an operational layer:
* Get the layer options for the operational layer using the directions in step 6.
* For the desired layer, set the filter clause with `generateLayerOption.whereClause(...)` and set the query option with `generateLayerOption.queryOption = GenerateLayerQueryOption.UseFilter`.
8. To not crop a layer's features to the extent of the offline map (default is true):
* Set `layerOption.generateLayerOption = true`.
9. Create a `GenerateOfflineMapJob` with `offlineMapTask.createGenerateOfflineMapJob(parameters, offlineMapPath, parameterOverrides`. Start the GenerateOfflineMapJob with `offlineMapJob.start()`. You can collect on the job's progress to update a progress bar in your UI.
10. When the job is done, check `offlineMapJob.result().onSuccess { ... }` to get a reference to the `offlineMap`.

## Relevant API

* ExportTileCacheParameters
* GenerateGeodatabaseParameters
* GenerateLayerOption
* GenerateOfflineMapJob
* GenerateOfflineMapParameterOverrides
* GenerateOfflineMapParameters
* 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"category": "Edit and Manage Data",
"description": "Take a web map offline with additional options for each layer.",
"formal_name": "GenerateOfflineMapWithCustomParameters",
"ignore": false,
"images": [
"generate-offline-map-with-custom-parameters.png"
],
"keywords": [
"LOD",
"adjust",
"download",
"extent",
"filter",
"offline",
"override",
"parameters",
"reduce",
"scale range",
"setting",
"ExportTileCacheParameters",
"GenerateGeodatabaseParameters",
"GenerateLayerOption",
"GenerateOfflineMapJob",
"GenerateOfflineMapParameterOverrides",
"GenerateOfflineMapParameters",
"OfflineMapParametersKey",
"OfflineMapTask"
],
"language": "kotlin",
"redirect_from": [
""
],
"relevant_apis": [
"ExportTileCacheParameters",
"GenerateGeodatabaseParameters",
"GenerateLayerOption",
"GenerateOfflineMapJob",
"GenerateOfflineMapParameterOverrides",
"GenerateOfflineMapParameters",
"OfflineMapParametersKey",
"OfflineMapTask"
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/generateofflinemapwithcustomparameters/components/GenerateOfflineMapWithCustomParametersViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/generateofflinemapwithcustomparameters/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/generateofflinemapwithcustomparameters/screens/GenerateOfflineMapWithCustomParametersScreen.kt"
],
"title": "Generate offline map with custom parameters"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.arcgismaps.android.library)
alias(libs.plugins.arcgismaps.android.library.compose)
alias(libs.plugins.arcgismaps.kotlin.sample)
alias(libs.plugins.gradle.secrets)
}

secrets {
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
defaultPropertiesFileName = "secrets.defaults.properties"
}

android {
namespace = "com.esri.arcgismaps.sample.generateofflinemapwithcustomparameters"
buildFeatures {
buildConfig = true
}
}

dependencies {
// Only module specific dependencies needed here
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application><activity
android:exported="true"
android:name=".MainActivity"
android:label="@string/generate_offline_map_with_custom_parameters_app_name">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* 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.generateofflinemapwithcustomparameters

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
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.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.generateofflinemapwithcustomparameters.screens.GenerateOfflineMapWithCustomParametersScreen

class MainActivity : ComponentActivity() {

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)

setContent {
SampleAppTheme {
GenerateOfflineMapWithCustomParametersApp()
}
}
}

@Composable
private fun GenerateOfflineMapWithCustomParametersApp() {
Surface(color = MaterialTheme.colorScheme.background) {
GenerateOfflineMapWithCustomParametersScreen(
sampleName = getString(R.string.generate_offline_map_with_custom_parameters_app_name)
)
}
}
}
Loading
Loading