At the 100.4 release, do you support the rubberband aoi box to zoom in (in 10.2.4 this was called ZoomBoxOverlay).

391
1
02-27-2019 09:28 PM
JerrySchultz
New Contributor III

At the 100.4 release, do you support the rubberband aoi box to zoom in (in 10.2.4 this was called ZoomBoxOverlay). This is a very useful capability and I would hope their is similar functionality at 100.4.

What is mapview.setEnableTouchZoom(true). 

0 Kudos
1 Reply
ColinAnderson1
Esri Contributor

Sorry, zoom box is currently not available for 100.4 but it is quite easy to create the functionality by creating a custom interaction listener e.g.

import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.mapping.view.MapView.DefaultInteractionListener;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Point2D;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class ZoomBoxTest extends Application {
  private MapView mapView = new MapView();

  @Override
  public void start(Stage stage) throws Exception {
    Platform.setImplicitExit(true);

    BorderPane borderPane = new BorderPane();

    javafx.scene.Scene fxScene = new javafx.scene.Scene(borderPane);

    stage.setWidth(500);
    stage.setHeight(500);
    stage.setScene(fxScene);
    stage.show();

    stage.show();

    ArcGISMap map = new ArcGISMap(Basemap.createDarkGrayCanvasVector());
    mapView.setMap(map);

    borderPane.setCenter(mapView);
    mapView.setInteractionListener(new ZoomBoxInteraction(mapView));
  }

  @Override
  public void stop() {
    if (mapView != null) {
      mapView.dispose();
    }
  }

  public static void main(String[] args) {
    Application.launch(args);
  }

  /**
   * Creates an interaction listener that allows you to zoom in by defining an envelope by dragging the mouse.
   */
  class ZoomBoxInteraction extends DefaultInteractionListener {

    private GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
    private Graphic boxGraphic;
    private Envelope box;
    Point firstPoint;
    Point lastPoint;

    ZoomBoxInteraction(MapView mapView) {
      super(mapView);
    }

    @Override
    public void onMousePressed(MouseEvent e) {
      mapView.getGraphicsOverlays().add(graphicsOverlay);
      boxGraphic = new Graphic();
      graphicsOverlay.getGraphics().add(boxGraphic);
      boxGraphic.setSymbol(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x88FF0000, null));
      firstPoint = mapView.screenToLocation(new Point2D(e.getX(), e.getY()));
      lastPoint = firstPoint;
      box = new Envelope(firstPoint, lastPoint);
      boxGraphic.setGeometry(box);
    }

    @Override
    public void onMouseReleased(MouseEvent e) {
      mapView.setViewpoint(new Viewpoint(box));
      mapView.getGraphicsOverlays().remove(graphicsOverlay);
      graphicsOverlay.getGraphics().clear();
      firstPoint = null;
      lastPoint = null;
      box = null;
      boxGraphic = null;
    }

    @Override
    public void onMouseDragged(MouseEvent e) {
      lastPoint = mapView.screenToLocation(new Point2D(e.getX(), e.getY()));
      box = new Envelope(firstPoint, lastPoint);
      boxGraphic.setGeometry(box);
    }
  }
}

What is mapview.setEnableTouchZoom(true). 

This enables/disables zooming in/out by using a pinching touch gesture on touch enabled devices.

0 Kudos