View on GitHub Sample viewer app

Rotate a map.

Image of map rotation

Use case

A user may wish to view the map in an orientation other than north-facing.

How to use the sample

Press the A and D keys to rotate the map. The text will update to display the map’s rotation value. If the map is not pointed north, the compass will display the current heading. Click the compass to set the map’s heading to north.

How it works

  1. Create a ArcGISMap and set it to a MapView.
  2. Use mapView.getMapRotation() to get the map’s rotation angle.
  3. Create a new Compass(mapView) to show the direction of north.

Relevant API

  • ArcGISMap
  • MapView

Tags

compass, rotate, rotation, toolkit

Sample Code

module-info.java module-info.java MapRotationSample.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_rotation {
// 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;
// require ArcGIS Maps SDK for Java Toolkit
requires com.esri.arcgisruntime.toolkit;
exports com.esri.samples.map_rotation;
}