Help about ZoomControls

1532
12
09-02-2019 05:49 AM
S_MMaruf
New Contributor II

Hi , 

I am trying to develop zooControls like zoomIn and zoomOut.  i give below the code about zoomIn and ZoomOut.

public void zoomIn() {
double x, y;
x= mapView.getScaleX();
y= mapView.getScaleY();
mapView.setScaleX(x+1);
mapView.setScaleY(y+1);

}

public void zoomOut() {
double x, y;

x= mapView.getScaleX();
y= mapView.getScaleY();
mapView.setScaleX(x-1);
mapView.setScaleY(y-1);
}

but the problem is when i click zoomIn button the mapview is overlaping with other pane and when i click zoomOut , it is not working and mapview is not zoomout within its stackpane like mouse's zoomIn and zoomout. i attach some code snippet.

For my  map application, changes zoom level of map by +1 or -1 and default minimum zoom level is 0, default maximum zoom level is 18.

so , there is another way to work with directly with mapview's zoom level?? above code is not working like mouse's zooming. can you guys give recommendation how to solve this problem?

Tags (1)
12 Replies
S_MMaruf
New Contributor II

Hi , you code nicely working . i also need to disable zoomOut button disable in zoomlevel 0 . i write code under the zoomIn button disable code . my zoomOut button is not disable . am i some thing missing can you help me ?

 tiledLayer.addDoneLoadingListener(() -> {

      var lods = tiledLayer.getTileInfo().getLevelsOfDetail();

 

      lods.forEach(lod -> System.out.println(lod.getLevel() + " " + lod.getScale() + " " + lod.getResolution()));

 

      //tiledLayer.setMinScale(lods.get(0).getScale());

      //tiledLayer.setMaxScale(lods.get(18).getScale());

 

      HBox box = new HBox();

      borderPane.setBottom(box);

 

      Button zoomIn = new Button("Zoom in");

      Button zoomOut = new Button("Zoom out");

 

      zoomIn.setOnAction(a -> {

        Viewpoint current = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);

        Viewpoint zoomedIn = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() / 2.0);

      });

 

      zoomOut.setOnAction(a -> {

        Viewpoint current = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);

        Viewpoint zoomedOut = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() * 2.0);

        mapView.setViewpointAsync(zoomedOut);

      });

 

      box.getChildren().addAll(zoomIn, zoomOut);

 

      mapView.addMapScaleChangedListener(s -> zoomIn.setDisable(mapView.getMapScale() <= lods.get(18).getScale()));

mapView.addMapScaleChangedListener(s -> zoomOut.setDisable(mapView.getMapScale() >= lods.get(0).getScale()));

 

   });

 

    Basemap basemap = new Basemap();

    basemap.getBaseLayers().add(tiledLayer);

    map.setBasemap(basemap);

 

    mapView.setMap(map);

    borderPane.setCenter(mapView);

  }

0 Kudos
ColinAnderson1
Esri Contributor

The logic is good. The problem I think is that the view is not zooming out to LOD 0. If you set another LOD e.g. 5 you will see it works. Also if you make your window smaller it becomes possible to zoom to LOD 0.

0 Kudos
S_MMaruf
New Contributor II

hi

i used different way to implement your code . but it doesnt working . i am little bit confused now where i put these code . i implemented in button action event but no result. my application is following decoupled way .can you check for where and what i am missing . also i am using javafxml to create view part of my map application. in my project button action event should be in another class.

// this is my map class//

public class IJMSMap implements MapInterface {
private MapView mapView;
private Point p;
private ArcGISMap map ;

@FXML private Button zoomOut;
@FXML private Button zoomIn;

ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer("http://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Light_Gray_Base/MapServer");

public IJMSMap(MapView mapView) {
this.mapView = mapView;

// create an ArcGISMap with the default imagery basemap
this.map = new ArcGISMap(new Basemap(tiledLayer));
// display the map by setting the map on the map view
mapView.setMap(this.map);
Point envelope = new Point(0.0, 0.0, SpatialReferences.getWgs84());
mapView.setViewpointGeometryAsync(envelope);
}

// this is controller class which contains zoom  button action event//

public class MapLayOutController implements Initializable {

@FXML
private StackPane MapPane ;
//private MapView MapView;
//private IJMSMap map;
@FXML private VBox controlVbox;
@FXML private Button zoomOut;
@FXML private Button zoomIn;
private CheckBox layer;
@FXML private HBox zoomBtnHbox;

private MapView MapView = new MapView();
private IJMSMap map = new IJMSMap(this.MapView);
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer("http://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Light_Gray_Base/MapServer");

@FXML
private StackPane PanButtonContainerPane;

@Override
public void initialize(URL location, ResourceBundle resources) {
this.MapView = new MapView();
this.map = new IJMSMap(this.MapView);
}


this.PanButtonContainerPane.getChildren().add(MapView);

this.movePanNorth.toFront();

this.movePanEast.toFront();
this.MovePanSouth.toFront();
this.movePanWest.toFront();
this.zoomBtnHbox.toFront();

}

public void zoomIn(ActionEvent event) {

tiledLayer.addDoneLoadingListener(() -> {
var lods = tiledLayer.getTileInfo().getLevelsOfDetail();
zoomIn.setOnAction(a -> {
Viewpoint current = MapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);

Viewpoint zoomedIn = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() / 2.0);
MapView.setViewpointAsync(zoomedIn);
});


MapView.addMapScaleChangedListener(s -> zoomIn.setDisable(MapView.getMapScale() <= lods.get(18).getScale()));

});



}

public void zoomOut(ActionEvent event) {

tiledLayer.addDoneLoadingListener(() -> {
var lods = tiledLayer.getTileInfo().getLevelsOfDetail();
zoomIn.setOnAction(a -> {
Viewpoint current = MapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);

Viewpoint zoomedIn = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() / 2.0);
MapView.setViewpointAsync(zoomedIn);
});


MapView.addMapScaleChangedListener(s -> zoomIn.setDisable(MapView.getMapScale() >= lods.get(18).getScale()));

});


}

0 Kudos