<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: View rotation (setViewpointRotationAsync) in Java Maps SDK Questions</title>
    <link>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1019747#M2293</link>
    <description>&lt;P&gt;Thank you Mark! That works like a charm!&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2021 18:58:23 GMT</pubDate>
    <dc:creator>JohnCartse</dc:creator>
    <dc:date>2021-01-25T18:58:23Z</dc:date>
    <item>
      <title>View rotation (setViewpointRotationAsync)</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1017670#M2291</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I have loaded a map like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MapView mapView = new MapView();
ArcGISMap map = new ArcGISMap(SpatialReferences.getWebMercator());
map.setBasemap(Basemap.createImagery());
map.setMaxScale(...);
mapView.setMap(map);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, with this &lt;STRONG&gt;mapView&lt;/STRONG&gt; object, I would like to rotate the map using the mouse (dragging the mouse).&lt;/P&gt;&lt;P&gt;(note: I don't want to rotate the map itself, just the 'view' or camera, if you will).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I managed to achieve it by doing this when I drag the mouse:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; mapView.setViewpointRotationAsync(mousePosDiffX);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#999999"&gt;&lt;EM&gt;(note: this method returns a &lt;STRONG&gt;ListenableFuture&amp;lt;Boolean&amp;gt;&lt;/STRONG&gt; to tell when it is done.)&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;However, it is very laggy.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="map_rotate3.gif" style="width: 504px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/4006iA11E2212D2944F4B/image-size/large?v=v2&amp;amp;px=999" role="button" title="map_rotate3.gif" alt="map_rotate3.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My first solution would be to avoid calling to much &lt;STRONG&gt;setViewpointRotationAsync &lt;/STRONG&gt;by checking the &lt;STRONG&gt;CompletableFuture&lt;/STRONG&gt; and call it only when the rotation is it complete using some kind of mutex/lock.. but it is not very successful.&lt;/P&gt;&lt;P&gt;Any help appreciated!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 13:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1017670#M2291</guid>
      <dc:creator>JohnCartse</dc:creator>
      <dc:date>2021-01-18T13:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: View rotation (setViewpointRotationAsync)</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1019091#M2292</link>
      <description>&lt;P&gt;I can see how this would not be very pleasing to the user.&amp;nbsp; I tried it myself and it feels pretty bad.&lt;/P&gt;&lt;P&gt;You'll be glad to hear there is a better way and it's not that complicated.&lt;/P&gt;&lt;P&gt;The laggy experience you have here is happening because you are calling an animated change of viewpoint over and over again.&amp;nbsp; The approach here is to change the viewpoint without animation.&lt;/P&gt;&lt;P&gt;I've written a method to show how this is done:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;  private void rotateMapView(double angle) {
    Viewpoint v = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);
    if (angle &amp;lt; 0) {
      angle += 360.0f;
    }
    v = new Viewpoint((Point) v.getTargetGeometry(), v.getTargetScale(), angle);
    mapView.setViewpoint(v);
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step is to wire this up to the custom interaction you are creating.&amp;nbsp; The best approach is to make your own InteractionListener which you can conveniently create by overriding the DefaultInteractionListener.&lt;/P&gt;&lt;P&gt;I started to put one together here to show how it works, but it needs more work as it is not that robust yet.&amp;nbsp; It was created as a class within the application class:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;  private class rotationInteractionListener extends MapView.DefaultInteractionListener {

    private double initialX;

    protected rotationInteractionListener(MapView mapView) {
      super(mapView);
    }

    @Override
    public void onMousePressed(MouseEvent e) {
      initialX = e.getX();
      System.out.println("custom pressed");
      super.onMousePressed(e);
    }

    @Override
    public void onMouseDragged(MouseEvent e) {

      double xDiff = initialX - e.getX();
      rotateMapView(xDiff);
      System.out.println("custom pan " + xDiff);

      e.consume();
      //super.onMouseDragged(e);
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To attach the new listener to your mapview you need to add this:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;// create a map view and set its map&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;mapView &lt;/SPAN&gt;= &lt;SPAN&gt;new &lt;/SPAN&gt;MapView()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;mapView&lt;/SPAN&gt;.setMap(map)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;//Instantiate custom interaction listener and assign it to the mapview&lt;BR /&gt;&lt;/SPAN&gt;InteractionListener interactionListener = &lt;SPAN&gt;new &lt;/SPAN&gt;rotationInteractionListener(&lt;SPAN&gt;mapView&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;mapView&lt;/SPAN&gt;.setInteractionListener(interactionListener)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;You should this solution much less laggy.&lt;/P&gt;&lt;P&gt;Does this help?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 14:27:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1019091#M2292</guid>
      <dc:creator>MarkBaird</dc:creator>
      <dc:date>2021-01-22T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: View rotation (setViewpointRotationAsync)</title>
      <link>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1019747#M2293</link>
      <description>&lt;P&gt;Thank you Mark! That works like a charm!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 18:58:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/java-maps-sdk-questions/view-rotation-setviewpointrotationasync/m-p/1019747#M2293</guid>
      <dc:creator>JohnCartse</dc:creator>
      <dc:date>2021-01-25T18:58:23Z</dc:date>
    </item>
  </channel>
</rss>

