View on GitHub Sample viewer app

Display the map at an initial viewpoint representing a bounding geometry.

Image of map initial extent

Use case

Setting the initial viewpoint is useful when a user wishes to first load the map at a particular area of interest.

How to use the sample

As the application is loading, the initial view point is set and the map view opens at the given location.

How it works

  1. Create an ArcGISMap.
  2. Create a Viewpoint using an Envelope.
  3. Set the starting location of the map with setInitialViewpoint(Viewpoint).
  4. Set the map to a MapView.

Relevant API

  • ArcGISMap
  • Envelope
  • MapView
  • Point
  • Viewpoint

Tags

initial viewpoint, extent, zoom, envelope

Sample Code

module-info.java module-info.java MapInitialExtentSample.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.map_initial_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;
exports com.esri.samples.map_initial_extent;
}