2

我正在尝试使用ArcGIS Runtime for Java和视图部分的 FXML 文件开发导航地图系统。我目前正面临 zoomButtons 禁用:在某些示例中,该按钮应在 时禁用,并且应在 时禁用。现在我在尝试在几个缩放级别禁用这些按钮时被卡住了。谁能帮我解决这个问题?您可以在下面找到随附的代码。zoomlevelzoomInzoomlevel = 18zoomoutzoomlevel = 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();  
}
4

1 回答 1

1

定义一个属性 ( zoomLevel) 并将disableProperty按钮的 绑定到 zoomLevel 属性,当它高于或低于某些最大值和最小值时。

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

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

缩小

缩小

放大

放大

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

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);
    }

}
于 2019-09-05T20:23:40.493 回答