Update SketchOnMapSample.java
If sketch editor is capable of enabling redo or undo, enable those buttons. Otherwise, disable them.
@@ -139,7 +139,6 @@ public class SketchOnMapSample extends Application {
selectGraphic();
graphicsOverlay.clearSelection();
clearButton.setDisable(false);
- undoButton.setDisable(true);
redoButton.setDisable(true);
editButton.setDisable(true);
cancelButton.setDisable(true);
@@ -156,13 +155,16 @@ public class SketchOnMapSample extends Application {
undoButton.setOnAction(event -> {
if (sketchEditor.canUndo()) {
sketchEditor.undo();
- };
+ //undoButton.setDisable(false);
+ }
+ ;
});
// redo the last change made whilst sketching graphic
redoButton.setOnAction(event -> {
if (sketchEditor.canRedo()) {
sketchEditor.redo();
+ //redoButton.setDisable(false);
}
});
@@ -178,8 +180,9 @@ public class SketchOnMapSample extends Application {
sketchEditor.start(graphic.getGeometry());
// remove the underlying graphic to live update. This clears the graphic.
graphicsOverlay.getGraphics().remove(graphic);
-
}
+
+
});
cancelButton.setOnAction(event -> {
@@ -206,9 +209,10 @@ public class SketchOnMapSample extends Application {
graphicsOverlay.clearSelection();
// create a graphics draw option based on source type
- resetButtons(false);
- editButton.setDisable(true);
- cancelButton.setDisable(true);
+ resetButtons(true);
+
+ saveButton.setDisable(false);
+
SketchCreationMode sketchCreationMode = sketchOptionsDropDown.getSelectionModel().getSelectedItem();
try {
@@ -237,9 +241,21 @@ public class SketchOnMapSample extends Application {
// add a listener for when geometry is changed, to enable cancelling the button
sketchEditor.addGeometryChangedListener(SketchGeometryChangedListener -> {
+ // if the geometry being listened to is not empty, then enable the cancel button
if (!SketchGeometryChangedListener.getGeometry().isEmpty()) {
cancelButton.setDisable(false);
}
+
+ // if the sketch editor can undo, enable the undo button otherwise disable it
+ if (sketchEditor.canUndo()) {
+ undoButton.setDisable(false);
+ } else {undoButton.setDisable(true);}
+
+ // if the sketch editor can redo, enable the redo button otherwise disable it
+ if (sketchEditor.canRedo()) {
+ redoButton.setDisable(false);
+ } else {redoButton.setDisable(true);}
+
});
} catch (Exception e) {
@@ -278,15 +294,25 @@ public class SketchOnMapSample extends Application {
sketchEditor.start(SketchCreationMode.POLYLINE);
}
- private void createPolygon() { sketchEditor.start(SketchCreationMode.POLYGON); }
+ private void createPolygon() {
+ sketchEditor.start(SketchCreationMode.POLYGON);
+ }
- private void createPoint() { sketchEditor.start(SketchCreationMode.POINT); }
+ private void createPoint() {
+ sketchEditor.start(SketchCreationMode.POINT);
+ }
- private void createMultiPoint() { sketchEditor.start(SketchCreationMode.MULTIPOINT); }
+ private void createMultiPoint() {
+ sketchEditor.start(SketchCreationMode.MULTIPOINT);
+ }
- private void createFreeHandLine() { sketchEditor.start(SketchCreationMode.FREEHAND_LINE); }
+ private void createFreeHandLine() {
+ sketchEditor.start(SketchCreationMode.FREEHAND_LINE);
+ }
- private void createFreeHandPolygon() { sketchEditor.start(SketchCreationMode.FREEHAND_POLYGON); }
+ private void createFreeHandPolygon() {
+ sketchEditor.start(SketchCreationMode.FREEHAND_POLYGON);
+ }
/**
