View on GitHub Sample viewer app

Limit the view of a map to a particular area.

Image of set max extent

Use case

When showing map information relevant to only a certain area, you may wish to constrain the user’s ability to pan or zoom away.

How to use the sample

The application loads with a map whose maximum extent has been set to the borders of Colorado. Note that you won’t be able to pan far from the Colorado border or zoom out beyond the minimum scale set by the max extent. Use the toggle switch to disable the max extent to freely pan/zoom around the map.

How it works

  1. Create an ArcGISMap object.
  2. Create an envelop of the extent using Envelope(Point(x, y), Point(x, y))
  3. Set the maximum extent of the map with map.maxExtent = envelope.
  4. Set the map to a MapView object.
  5. Set map.maxExtent = null to disable the maximum extent of the map

Relevant API

  • ArcGISMap
  • Envelope

Additional information

This sample uses the GeoView-Compose Toolkit module to be able to implement a composable MapView.

Tags

extent, geoview-compose, limit panning, map, mapview, max extent, toolkit, zoom

Sample Code

MainActivity.kt MainActivity.kt SetMaxExtentViewModel.kt SetMaxExtentScreen.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.setmaxextent
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.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.setmaxextent.screens.SetMaxExtentScreen
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)
enableEdgeToEdge()
setContent {
SampleAppTheme {
SetMaxExtentApp()
}
}
}
@Composable
private fun SetMaxExtentApp() {
Surface(color = MaterialTheme.colorScheme.background) {
SetMaxExtentScreen(
sampleName = getString(R.string.set_max_extent_app_name)
)
}
}
}