3434import com .esri .arcgisruntime .mapping .Basemap ;
3535import com .esri .arcgisruntime .mapping .Viewpoint ;
3636import com .esri .arcgisruntime .mapping .view .MapView ;
37+ import com .esri .arcgisruntime .toolkit .Compass ;
3738
3839public class MapRotationSample extends Application {
3940
@@ -85,6 +86,13 @@ public void start(Stage stage) throws Exception {
8586 mapView = new MapView ();
8687 mapView .setMap (map );
8788
89+ // create a compass to show the current heading when rotated
90+ Compass compass = new Compass (mapView );
91+
92+ // clicking the compass sets the map's heading to 0.0
93+ // add a listener to reset the slider when this happens
94+ compass .setOnMouseClicked (e -> slider .setValue (0.0 ));
95+
8896 // create a starting viewpoint for the map view
8997 SpatialReference spatialReference = SpatialReferences .getWebMercator ();
9098 Point pointBottomLeft = new Point (-13639984.0 , 4537387.0 , spatialReference );
@@ -96,9 +104,11 @@ public void start(Stage stage) throws Exception {
96104 mapView .setViewpointAsync (viewpoint );
97105
98106 // add the map view, slider, and compass to the stack pane
99- stackPane .getChildren ().addAll (mapView , slider );
107+ stackPane .getChildren ().addAll (mapView , slider , compass );
100108 StackPane .setAlignment (slider , Pos .TOP_LEFT );
109+ StackPane .setAlignment (compass , Pos .TOP_RIGHT );
101110 StackPane .setMargin (slider , new Insets (10 , 0 , 0 , 10 ));
111+ StackPane .setMargin (compass , new Insets (10 , 10 , 0 , 0 ));
102112 } catch (Exception e ) {
103113 // on any error, display the stack trace
104114 e .printStackTrace ();
0 commit comments