Skip to content

Commit ede756d

Browse files
authored
fix/spatial-operations-reset-button (#359)
1 parent ab4b52d commit ede756d

File tree

2 files changed

+12
-45
lines changed

2 files changed

+12
-45
lines changed
37.4 KB
Loading

src/main/java/com/esri/samples/geometry/spatial_operations/SpatialOperationsSample.java

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@
2222
import javafx.geometry.Pos;
2323
import javafx.scene.Scene;
2424
import javafx.scene.control.Alert;
25-
import javafx.scene.control.Button;
2625
import javafx.scene.control.ComboBox;
27-
import javafx.scene.control.Label;
28-
import javafx.scene.layout.Background;
29-
import javafx.scene.layout.BackgroundFill;
30-
import javafx.scene.layout.CornerRadii;
3126
import javafx.scene.layout.StackPane;
32-
import javafx.scene.layout.VBox;
33-
import javafx.scene.paint.Paint;
3427
import javafx.stage.Stage;
3528

3629
import com.esri.arcgisruntime.geometry.Geometry;
@@ -59,7 +52,7 @@ public class SpatialOperationsSample extends Application {
5952

6053
// geometry operations
6154
private enum OPERATION_TYPE {
62-
UNION, DIFFERENCE, SYMMETRIC_DIFFERENCE, INTERSECTION
55+
NONE, UNION, DIFFERENCE, SYMMETRIC_DIFFERENCE, INTERSECTION
6356
}
6457

6558
// simple black (0xFF000000) line symbol
@@ -81,35 +74,18 @@ public void start(Stage stage) {
8174
stage.setScene(scene);
8275
stage.show();
8376

84-
// create a control panel
85-
VBox controlsVBox = new VBox(6);
86-
controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
87-
Insets.EMPTY)));
88-
controlsVBox.setPadding(new Insets(10.0));
89-
controlsVBox.setMaxSize(180, 120);
90-
controlsVBox.getStyleClass().add("panel-region");
91-
92-
// create section for combo box
93-
Label geomOperationLabel = new Label("Select operation:");
94-
geomOperationLabel.getStyleClass().add("panel-label");
95-
9677
// initialise comboBox items
9778
ComboBox<OPERATION_TYPE> geomOperationBox = new ComboBox<>(FXCollections.observableArrayList(OPERATION_TYPE
9879
.values()));
99-
geomOperationBox.getSelectionModel().selectLast();
100-
geomOperationBox.setMaxWidth(Double.MAX_VALUE);
80+
geomOperationBox.getSelectionModel().select(OPERATION_TYPE.NONE);
81+
geomOperationBox.setMaxWidth(180);
10182
geomOperationBox.setDisable(true);
10283

103-
// create button for reset the sample
104-
Button resetButton = new Button("Reset operation");
105-
resetButton.setMaxWidth(Double.MAX_VALUE);
106-
resetButton.setDisable(true);
107-
10884
// handle ComboBox event to perform the selected geometry operation
10985
geomOperationBox.setOnAction(e -> {
86+
resultGeomOverlay.getGraphics().clear();
11087
Geometry resultPolygon;
111-
OPERATION_TYPE operation = geomOperationBox.getSelectionModel().getSelectedItem();
112-
switch (operation) {
88+
switch (geomOperationBox.getSelectionModel().getSelectedItem()) {
11389
case UNION:
11490
resultPolygon = GeometryEngine.union(polygon1.getGeometry(), polygon2.getGeometry());
11591
break;
@@ -120,27 +96,18 @@ public void start(Stage stage) {
12096
resultPolygon = GeometryEngine.symmetricDifference(polygon1.getGeometry(), polygon2.getGeometry());
12197
break;
12298
case INTERSECTION:
123-
default:
12499
resultPolygon = GeometryEngine.intersection(polygon1.getGeometry(), polygon2.getGeometry());
100+
break;
101+
case NONE:
102+
default:
103+
return;
125104
}
126105

127106
// update result as a red (0xFFE91F1F) geometry
128107
SimpleFillSymbol redSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFFE91F1F, line);
129108
resultGeomOverlay.getGraphics().add(new Graphic(resultPolygon, redSymbol));
130-
131-
resetButton.setDisable(false);
132-
geomOperationBox.setDisable(true);
133-
});
134-
135-
// clear result layer
136-
resetButton.setOnAction(e -> {
137-
resultGeomOverlay.getGraphics().clear();
138-
geomOperationBox.setDisable(false);
139109
});
140110

141-
// add label and buttons to the control panel
142-
controlsVBox.getChildren().addAll(geomOperationLabel, geomOperationBox, resetButton);
143-
144111
// create ArcGISMap with topographic basemap
145112
ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvas());
146113

@@ -175,9 +142,9 @@ public void start(Stage stage) {
175142
geomOverlay.getGraphics().add(polygon2);
176143

177144
// add the map view and control panel to stack pane
178-
stackPane.getChildren().addAll(mapView, controlsVBox);
179-
StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);
180-
StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));
145+
stackPane.getChildren().addAll(mapView, geomOperationBox);
146+
StackPane.setAlignment(geomOperationBox, Pos.TOP_LEFT);
147+
StackPane.setMargin(geomOperationBox, new Insets(10, 0, 0, 10));
181148

182149
} catch (Exception e) {
183150
// on any error, display the stack trace

0 commit comments

Comments
 (0)