gpt4 book ai didi

java - 如何在某些缩放级别禁用放大/缩小按钮,例如 : respectively zoomlevel 18 and zoomlevel 0

转载 作者:行者123 更新时间:2023-11-30 10:00:52 27 4
gpt4 key购买 nike

我正在尝试使用 ArcGIS Runtime for Java 和 View 部分的 FXML 文件开发一个导航 map 系统。我目前面临 zoomButtons 禁用:在一些 zoomlevel例如,zoomIn按钮应在 zoomlevel = 18 处禁用和 zoomout应在 zoomlevel = 0 处禁用.现在,我在尝试以多个缩放级别禁用这些按钮时遇到了困难。谁能帮我解决这个问题?您可以在下面找到附加的代码。

我已经开发了 zoomInzoomOut方法,它们工作正常。

//ZoomIn Function is created 
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);
}

//ZoomOut Function is created
public void zoomOutFunction() {
Viewpoint current = mapView.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE);
Viewpoint zoomedOut = new Viewpoint((Point) current.getTargetGeometry(), current.getTargetScale() * 2.0);
mapView.setViewpointAsync(zoomedOut);
}

// Create action event for ZoomIn Function
public void zoomInAction(ActionEvent event) {
map.zoomInFunction();
}

// Create action event for ZoomOut Function
public void zoomOutAction(ActionEvent event) {
map.zoomOutFunction();
}

最佳答案

定义一个属性 (zoomLevel),当按钮超过或低于特定的最大值和最小值时,将按钮的 disableProperty 绑定(bind)到 zoomLevel 属性。

在最小值和最大值之间缩放

zoom between min and max

缩小

zoomed out

放大

zoomed in

实现非常简单。下面提供了一个示例应用来演示所涉及的概念。

import javafx.application.Application;
import javafx.beans.property.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;

public class BoundedZoom extends Application {

private static final int MIN_ZOOM_LEVEL = 1;
private static final int MAX_ZOOM_LEVEL = 5;
private static final int DEFAULT_ZOOM_LEVEL = 3;

private IntegerProperty zoomLevel = new SimpleIntegerProperty(DEFAULT_ZOOM_LEVEL);

public int getZoomLevel() {
return zoomLevel.get();
}

public IntegerProperty zoomLevelProperty() {
return zoomLevel;
}

public void setZoomLevel(int zoomLevel) {
this.zoomLevel.set(zoomLevel);
}

@Override
public void start(Stage stage) throws Exception {
Button zoomIn = new Button("Zoom In");
zoomIn.setOnAction(event -> setZoomLevel(getZoomLevel() + 1));
zoomIn.setDisable(getZoomLevel() >= MAX_ZOOM_LEVEL);
zoomIn.disableProperty().bind(zoomLevel.greaterThanOrEqualTo(MAX_ZOOM_LEVEL));

Button zoomOut = new Button("Zoom Out");
zoomOut.setOnAction(event -> setZoomLevel(getZoomLevel() - 1));
zoomOut.setDisable(getZoomLevel() <= MIN_ZOOM_LEVEL);
zoomOut.disableProperty().bind(zoomLevel.lessThanOrEqualTo(MIN_ZOOM_LEVEL));

Label zoomLevelDescLabel = new Label("Zoom level (min " + MIN_ZOOM_LEVEL + ", max " + MAX_ZOOM_LEVEL + "): ");
Label zoomLevelValueLabel = new Label("" + getZoomLevel());
zoomLevelValueLabel.textProperty().bind(zoomLevel.asString());

Pane zoomLevelDisplay = new HBox(10, zoomLevelDescLabel, zoomLevelValueLabel);
Pane controlPane = new HBox(10, zoomIn, zoomOut);

Pane layout = new VBox(10, zoomLevelDisplay, controlPane);
layout.setPadding(new Insets(10));

stage.setScene(new Scene(layout));
stage.show();
}

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

}

关于java - 如何在某些缩放级别禁用放大/缩小按钮,例如 : respectively zoomlevel 18 and zoomlevel 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57808013/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com