Hello ,
I develop two zoom buttons for zoomIn and zoomOut , they are disabled in zoom level 18 and zoomlevel 0 respectively and on starting the application zoomOut button disabled . However at present i am trying to develop someting about mouse Wheel zooming that reach zoom level 18 and disable ZoomIn Button and samething happen when mouse wheel zooming reached zoom level 0 , zoomOut button will be disable at that certain level and activated zoomIn button while mouse wheel zoom will be going down (ZoomOut action happening). i attach the code what i have done till now . it would be great have a idea or procedure from you.
@Override
public void initialize(URL location, ResourceBundle resources) {
this.mapView = new MapView();
this.map = new IJMSMap(this.mapView);
zoomOut.setDisable(true);
Scalebar scaleBar = new Scalebar(mapView);
scaleBar.setSkinStyle(Scalebar.SkinStyle.GRADUATED_LINE);
scaleBar.setUnitSystem(UnitSystem.METRIC);
Color transparentWhite = new Color(1, 1, 1, 0.7);
scaleBar.setBackground(new Background(new BackgroundFill(transparentWhite, new CornerRadii(5), Insets.EMPTY)));
}
this.PanButtonContainerPane.getChildren().addAll(mapView,scaleBar);
this.PanButtonContainerPane.setAlignment(scaleBar, Pos.TOP_LEFT);
this.movePanNorth.toFront();
this.movePanEast.toFront();
this.MovePanSouth.toFront();
this.movePanWest.toFront();
this.zoomBtnVbox.toFront();
}
#ActionEvent for ZoomIn function
public void zoomInAction(ActionEvent event) {
zoomOut.setDisable(false);
map.zoomInFunction();
if (mapView.getMapScale() <= 2256.994353) {
zoomIn.setDisable(true);
}
}
#ActionEvent for ZoomOut function
public void zoomOutAction(ActionEvent event) {
zoomIn.setDisable(false);
map.zoomOutFunction();
if (mapView.getMapScale() >= 7.3957190948944E7) {
zoomOut.setDisable(true);
}
}
#Method for zoomIn function
public void zoomInFunction() {
Viewpoint current = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);
Viewpoint zoomedIn = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() / 2.0);
mapView.setViewpointAsync(zoomedIn);
}
#Method for zoomOut function
public void zoomOutFunction()
{
Viewpoint current = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);
Viewpoint zoomedIn = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() * 2.0);
mapView.setViewpointAsync(zoomedIn);
}
I create this logic for mouse scroll/wheel zoom but when I am mouse_ scrolling both direction it works as a zoomIn function . how can i set up opposite scrolling for zoomOut Function.
// zoomIn by using mouse wheel and zooIn Button disable at zoom level at 18 while using mouse wheel zoomIn
mapView.setOnScroll(new EventHandler<ScrollEvent>() {
public void handle(ScrollEvent se) {
zoomOut.setDisable(false);
map.zoomInFunction();
if (mapView.getMapScale() <= 2256.994353) {
zoomIn.setDisable(true);
}
}});
My guess would be that since you are using setViewpointAsync the scale is not reached until some time after the call to zoomInFunction rather than on the next line of code where you call getMapScale. Maybe try using setViewPoint which so not async to see if that helps.