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. Click the “Enable Max Extent” checkbox to disable the max extent to freely pan/zoom around the map.

How it works

  1. Create an ArcGISMap.
  2. Create a new envelope Envelope(Point(x, y), Point(x, y)) with the required max extent.
  3. Wait for the map to load, then set the maximum extent of the map with map.setMaxExtent(envelope).
  4. Create a new MapView and set the map to it.
  5. Set map.setMaxExtent(null) to disable the maximum extent of the map.

Relevant API

  • ArcGISMap
  • Envelope

Tags

extent, limit panning, map, mapview, max extent, zoom

Sample Code

module-info.java module-info.java SetMaxExtentSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.set_max_extent {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
exports com.esri.samples.set_max_extent;
}