View on GitHub Sample viewer app

Set the map view to a new viewpoint.

Image of change viewpoint

Use case

Programmatically navigate to a specified location in the map or scene. Use this to focus on a particular point or area of interest.

How to use the sample

The map view has several methods for setting its current viewpoint. Click one of the buttons to see the viewpoint changed to that location using the method noted in parentheses.

How it works

  1. Create a new ArcGISMap and set it to the MapView.
  2. Change the map’s Viewpoint using one of the available methods:
  • Use mapView.setViewpointAsync() to pan to a viewpoint over the specified length of time.
  • Use MapView.setViewpointCenterAsync() to center the viewpoint on a Point and set a distance from the ground using a scale.
  • Use MapView.setViewpointGeometryAsync() to set the viewpoint to a given Geometry.

Relevant API

  • ArcGISMap
  • Geometry
  • MapView
  • Point
  • Viewpoint

Additional information

Below are some other ways to set a viewpoint on the MapView:

  • setViewpoint
  • setViewpointAsync
  • setViewpointCenterAsync
  • setViewpointGeometryAsync
  • setViewpointRotationAsync
  • setViewpointScaleAsync

Tags

animate, extent, pan, rotate, scale, view, zoom

Sample Code

module-info.java module-info.java ChangeViewpointSample.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.change_viewpoint {
// 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.change_viewpoint;
}