java.lang.Object
com.esri.arcgisruntime.mapping.view.geometryeditor.GeometryEditor

public final class GeometryEditor extends Object
Allows you to create new geometries, and change existing geometries, by interacting with a MapView.

To use a GeometryEditor:

  • Set the MapView.geometryEditorProperty().
  • Call one of the start methods.
  • You can then edit the geometry directly on the map view using mouse or touch gestures.
    • The toolProperty() determines how you draw on the map to define the new geometry, for example by adding individual vertices or with a freehand gesture. The default tool is VertexTool.
    • If you passed in an initial geometry, it is displayed in the view, and you can interact with the geometry to make changes.
  • Call stop() to return the geometry and prevent the geometry editor from processing any more interactions.
    • Geometries are immutable, therefore a new Geometry object reflecting the updates is returned from geometryProperty() and GeometryEditor.stop() each time.

When started (startedProperty() is true), you can interact with the different GeometryEditorElement objects that compose the representation of the geometry in the map view. Depending on what is selected, different types of GeometryEditorElement are returned from the selectedElementProperty(). Tap to select the different elements and drag to move them. Tap multiple times on an element to select the different types of GeometryEditorElement representing vertices, parts, and the entire geometry. You can control which interactions are possible by changing the InteractionConfiguration of the current tool. For example, you can change the types of element you can tap to select, and whether they can create new vertices or parts by tapping or dragging on the map. Programmatic changes to the geometryProperty() or selectedElementProperty() (for example selectVertex(long, long) or moveSelectedElement(Point)) are not affected by the settings in InteractionConfiguration. The type of the current GeometryEditor.toolProperty() determines what type of interactions will add new vertices and parts to the geometry.

Change the appearance of the geometry by using the GeometryEditorStyle of the current GeometryEditor.toolProperty() tool - for example to match the symbology used by the graphic or feature being edited.

Enabling snapping can help ensure that interactive edits are more accurate, with fewer errors, by allowing you to create geometries that connect to each other and are coincident. Use snapSettingsProperty() to configure snapping behavior.

Programmatic editing methods are also provided so you can augment your interactive geometry editing to support specific user requirements. For example:

Use change listeners on geometryProperty() and selectedElementProperty() to be notified when a user interaction or API call has changed the GeometryEditor.selectedElementProperty() or GeometryEditor.geometryProperty().

Changing the geometry state can also change canUndoProperty().

Since:
200.1.0
  • Property Details

  • Constructor Details

    • GeometryEditor

      public GeometryEditor()
      Creates a default GeometryEditor.
      Since:
      200.1.0
  • Method Details

    • canRedoProperty

      public ReadOnlyBooleanProperty canRedoProperty()
      True if there are actions that can be redone on the geometry, false otherwise.

      This applies to both programmatic and interactive changes to the geometry and is useful for enabling or disabling a UI control for redo actions.

      The value of the canRedoProperty() changes when:

      • an initial action that can be redone is performed in the GeometryEditor, or
      • the last remaining action that can be redone was redone.
      Returns:
      the canRedo property
      Since:
      200.1.0
      See Also:
    • getCanRedo

      public boolean getCanRedo()
      Gets the value of the canRedo property.
      Property description:
      True if there are actions that can be redone on the geometry, false otherwise.

      This applies to both programmatic and interactive changes to the geometry and is useful for enabling or disabling a UI control for redo actions.

      The value of the canRedoProperty() changes when:

      • an initial action that can be redone is performed in the GeometryEditor, or
      • the last remaining action that can be redone was redone.
      Returns:
      the value of the canRedo property
      Since:
      200.1.0
      See Also:
    • canUndoProperty

      public ReadOnlyBooleanProperty canUndoProperty()
      True if there are actions that can be undone on the geometry, false otherwise.

      This applies to both programmatic and interactive changes to the geometry and is useful for enabling or disabling a UI control for undo actions.

      The value of the canUndoProperty() changes when:

      • an initial action that can be undone is performed in the GeometryEditor, or
      • the last remaining action that can be undone was undone.
      Returns:
      the canUndo property
      Since:
      200.1.0
      See Also:
    • getCanUndo

      public boolean getCanUndo()
      Gets the value of the canUndo property.
      Property description:
      True if there are actions that can be undone on the geometry, false otherwise.

      This applies to both programmatic and interactive changes to the geometry and is useful for enabling or disabling a UI control for undo actions.

      The value of the canUndoProperty() changes when:

      • an initial action that can be undone is performed in the GeometryEditor, or
      • the last remaining action that can be undone was undone.
      Returns:
      the value of the canUndo property
      Since:
      200.1.0
      See Also:
    • geometryProperty

      public ReadOnlyObjectProperty<Geometry> geometryProperty()
      The current geometry, updated as you interact with the view.

      The geometry returned depends on the state of the GeometryEditor:

      If the GeometryEditor was started by calling GeometryEditor.start(Geometry), then the geometry is returned in the same SpatialReference as the input geometry. If the input geometry spatial reference is null, or the editor was started using GeometryEditor.start(GeometryType), then the geometry is returned in the spatial reference of the associated MapView. If no spatial reference is set on either input geometry or via an associated map view, then the spatial reference of the geometry will be null.

      Editing feature data that is reprojected on the fly can introduce spatial errors into the data. When accuracy is important, best practice is to use a spatial reference for the map view which matches the feature layer geometry you are editing. The ArcGIS Pro editing help topic Introduction to projection on the fly contains further advice.

      The value of the geometryProperty() changes when:

      Returns:
      the geometry property
      Since:
      200.1.0
      See Also:
    • getGeometry

      public Geometry getGeometry()
      Gets the value of the geometry property.
      Property description:
      The current geometry, updated as you interact with the view.

      The geometry returned depends on the state of the GeometryEditor:

      If the GeometryEditor was started by calling GeometryEditor.start(Geometry), then the geometry is returned in the same SpatialReference as the input geometry. If the input geometry spatial reference is null, or the editor was started using GeometryEditor.start(GeometryType), then the geometry is returned in the spatial reference of the associated MapView. If no spatial reference is set on either input geometry or via an associated map view, then the spatial reference of the geometry will be null.

      Editing feature data that is reprojected on the fly can introduce spatial errors into the data. When accuracy is important, best practice is to use a spatial reference for the map view which matches the feature layer geometry you are editing. The ArcGIS Pro editing help topic Introduction to projection on the fly contains further advice.

      The value of the geometryProperty() changes when:

      Returns:
      the value of the geometry property
      Since:
      200.1.0
      See Also:
    • startedProperty

      public ReadOnlyBooleanProperty startedProperty()
      True if an editing session is active, false otherwise.

      When true, interactions with the view can affect the state of the geometryProperty() or selectedElementProperty().

      Returns:
      the started property
      Since:
      200.1.0
      See Also:
    • isStarted

      public boolean isStarted()
      Gets the value of the started property.
      Property description:
      True if an editing session is active, false otherwise.

      When true, interactions with the view can affect the state of the geometryProperty() or selectedElementProperty().

      Returns:
      the value of the started property
      Since:
      200.1.0
      See Also:
    • visibleProperty

      public BooleanProperty visibleProperty()
      True if the geometry is visible in the view, false otherwise.
      Returns:
      the visible property
      Since:
      200.1.0
      See Also:
    • isVisible

      public boolean isVisible()
      Gets the value of the visible property.
      Property description:
      True if the geometry is visible in the view, false otherwise.
      Returns:
      the value of the visible property
      Since:
      200.1.0
      See Also:
    • setVisible

      public void setVisible(boolean isVisible)
      Sets the value of the visible property.
      Property description:
      True if the geometry is visible in the view, false otherwise.
      Parameters:
      isVisible - the value for the visible property
      Since:
      200.1.0
      See Also:
    • selectedElementProperty

      public ReadOnlyObjectProperty<GeometryEditorElement> selectedElementProperty()
      The element that is currently selected in the GeometryEditor, or null if nothing is selected.

      Clicking or tapping on the different visible elements of a geometry in a view allows you to select and unselect them. This property returns a different type of GeometryEditorElement depending on what is selected - a vertex (GeometryEditorVertex), a mid-vertex (GeometryEditorMidVertex), a part of a polygon or polyline (GeometryEditorPart), or the entire geometry (GeometryEditorGeometry). You can change which selection interactions are allowed by using the InteractionConfiguration of the tool.

      You can also programmatically select specific vertices (selectVertex(long, long)), mid-vertices (selectMidVertex(long, long)), parts of polygons or polylines (selectPart(long)), or the entire geometry (selectGeometry()). You can clear the selection using clearSelection().

      The value of selectedElementProperty() changes when:

      • Performing programmatic selection - for example using selectGeometry() or selectVertex(long, long)
      • Performing interactive selection - for example selecting or unselecting a GeometryEditorElement
      • The location of the selected element changes - for example moving the selected element programmatically or interactively
      • Performing edits - for example inserting a vertex interactively or deleting the selected element programmatically
      It may also change when:
      • Undoing or redoing edits - using undo() or redo()
      • Stopping the geometry editor using stop().
      Returns:
      the selectedElement property
      Since:
      200.1.0
      See Also:
    • getSelectedElement

      public GeometryEditorElement getSelectedElement()
      Gets the value of the selectedElement property.
      Property description:
      The element that is currently selected in the GeometryEditor, or null if nothing is selected.

      Clicking or tapping on the different visible elements of a geometry in a view allows you to select and unselect them. This property returns a different type of GeometryEditorElement depending on what is selected - a vertex (GeometryEditorVertex), a mid-vertex (GeometryEditorMidVertex), a part of a polygon or polyline (GeometryEditorPart), or the entire geometry (GeometryEditorGeometry). You can change which selection interactions are allowed by using the InteractionConfiguration of the tool.

      You can also programmatically select specific vertices (selectVertex(long, long)), mid-vertices (selectMidVertex(long, long)), parts of polygons or polylines (selectPart(long)), or the entire geometry (selectGeometry()). You can clear the selection using clearSelection().

      The value of selectedElementProperty() changes when:

      • Performing programmatic selection - for example using selectGeometry() or selectVertex(long, long)
      • Performing interactive selection - for example selecting or unselecting a GeometryEditorElement
      • The location of the selected element changes - for example moving the selected element programmatically or interactively
      • Performing edits - for example inserting a vertex interactively or deleting the selected element programmatically
      It may also change when:
      • Undoing or redoing edits - using undo() or redo()
      • Stopping the geometry editor using stop().
      Returns:
      the value of the selectedElement property
      Since:
      200.1.0
      See Also:
    • snapSettingsProperty

      public ObjectProperty<SnapSettings> snapSettingsProperty()
      Configurable options for interactive snapping.

      Snapping allows you to create geometries that connect to each other and are coincident, so that interactive edits are more accurate, with fewer errors. Snapping is disabled by default - see SnapSettings for information about setting up snapping workflows.

      Attempting to set the value to null will throw a NullPointerException exception.

      Returns:
      the snapSettings property
      Since:
      200.4.0
      See Also:
    • getSnapSettings

      public SnapSettings getSnapSettings()
      Gets the value of the snapSettings property.
      Property description:
      Configurable options for interactive snapping.

      Snapping allows you to create geometries that connect to each other and are coincident, so that interactive edits are more accurate, with fewer errors. Snapping is disabled by default - see SnapSettings for information about setting up snapping workflows.

      Attempting to set the value to null will throw a NullPointerException exception.

      Returns:
      the value of the snapSettings property
      Since:
      200.4.0
      See Also:
    • setSnapSettings

      public void setSnapSettings(SnapSettings snapSettings)
      Sets the value of the snapSettings property.
      Property description:
      Configurable options for interactive snapping.

      Snapping allows you to create geometries that connect to each other and are coincident, so that interactive edits are more accurate, with fewer errors. Snapping is disabled by default - see SnapSettings for information about setting up snapping workflows.

      Attempting to set the value to null will throw a NullPointerException exception.

      Parameters:
      snapSettings - the value for the snapSettings property
      Since:
      200.4.0
      See Also:
    • toolProperty

      public ObjectProperty<GeometryEditorTool> toolProperty()
      The tool defining how you interact with the view to create and edit the geometry.

      The default value is a VertexTool with all interactive operations enabled, providing a common way of editing points, multipoints, polygons, and polylines.

      The tool can be replaced while a GeometryEditor is started (isStarted() = true), enabling a combination of tools to be used to edit a geometry.

      Attempting to set the value to null will throw a NullPointerException.

      Returns:
      the tool property
      Since:
      200.1.0
      See Also:
    • getTool

      public GeometryEditorTool getTool()
      Gets the value of the tool property.
      Property description:
      The tool defining how you interact with the view to create and edit the geometry.

      The default value is a VertexTool with all interactive operations enabled, providing a common way of editing points, multipoints, polygons, and polylines.

      The tool can be replaced while a GeometryEditor is started (isStarted() = true), enabling a combination of tools to be used to edit a geometry.

      Attempting to set the value to null will throw a NullPointerException.

      Returns:
      the value of the tool property
      Since:
      200.1.0
      See Also:
    • setTool

      public void setTool(GeometryEditorTool tool)
      Sets the value of the tool property.
      Property description:
      The tool defining how you interact with the view to create and edit the geometry.

      The default value is a VertexTool with all interactive operations enabled, providing a common way of editing points, multipoints, polygons, and polylines.

      The tool can be replaced while a GeometryEditor is started (isStarted() = true), enabling a combination of tools to be used to edit a geometry.

      Attempting to set the value to null will throw a NullPointerException.

      Parameters:
      tool - the value for the tool property
      Since:
      200.1.0
      See Also:
    • clearGeometry

      public void clearGeometry()
      Clears the current geometry being edited.

      The GeometryType is maintained - to edit a different type of geometry, restart the GeometryEditor with the required type.

      Since:
      200.1.0
      See Also:
    • clearSelection

      public void clearSelection()
      Clears the current selection.

      This sets selectedElementProperty() to null. It does not change the geometryProperty().

      Since:
      200.1.0
      See Also:
    • deleteSelectedElement

      public void deleteSelectedElement()
      Deletes the selected element from the current geometry.

      To clear the selection, but leave the state of the geometry unchanged, call clearSelection() instead.

      Since:
      200.1.0
      See Also:
    • insertVertex

      public void insertVertex(Point point)
      Creates a new vertex at the specified location and inserts it after the currently selected element, or appends the point if there is nothing selected.

      If the geometry is empty (Geometry.isEmpty() is true), the given point is added as the initial vertex, and then selected. If nothing is selected (selectedElementProperty() is null), the point is appended to the end of the geometry, and then selected. If the selected element is the first vertex in a part of a Multipart, the given point is inserted before the currently selected vertex, and then selected.

      If the geometry is a non-empty Point, this method replaces the existing point with the given point and selects it.

      Parameters:
      point - the location of the new vertex
      Throws:
      NullPointerException - if point is null
      Since:
      200.1.0
      See Also:
    • moveSelectedElement

      public void moveSelectedElement(double deltaX, double deltaY)
      Moves the selected element by the specified distances along the x-axis and y-axis.
      Parameters:
      deltaX - the distance to move the selected element along the x-axis, in the units of the associated MapView spatial reference.
      deltaY - the distance to move the selected element along the y-axis, in the units of the associated MapView spatial reference.
      Since:
      200.1.0
      See Also:
    • moveSelectedElement

      public void moveSelectedElement(Point newPoint)
      Moves the selected element to the specified location.

      If selectedElementProperty() is a GeometryEditorVertex, then the location of the vertex is moved to the given point. If the GeometryEditor.selectedElementProperty() is any other type of GeometryEditorElement, then the center of the element is moved to the given point.

      Parameters:
      newPoint - the new location for the selected element
      Throws:
      NullPointerException - if newPoint is null
      Since:
      200.1.0
      See Also:
    • redo

      public void redo()
      Redoes the last action undone on the geometry.
      Since:
      200.1.0
      See Also:
    • replaceGeometry

      public void replaceGeometry(Geometry geometry)
      Replaces the current geometry with the specified geometry.

      Use this method to make changes to the geometry that are not directly supported using other GeometryEditor methods. For example, to start a new part in a Polygon or Polyline geometry, get the current geometry, use a MultipartBuilder to add the required part, and then pass the updated GeometryBuilder.toGeometry() to this method.

      Parameters:
      geometry - the new geometry to replace the current geometry. The GeometryType of these geometries must match.
      Throws:
      NullPointerException - if geometry is null
      Since:
      200.1.0
    • rotateSelectedElement

      public void rotateSelectedElement(double angle, Point origin)
      Rotates the selectedElementProperty() by the specified angle.

      The angle of rotation is used in the form of the modulo of 360 degrees; for example rotating by 540 degrees is equivalent to rotating by 180 degrees. A positive value corresponds to a counterclockwise rotation.

      If the origin Point has a different SpatialReference than the associated MapView, the point will be reprojected before the geometry is rotated, using the default transformation.

      If GeometryEditor.selectedElementProperty() is a GeometryEditorVertex, or a GeometryEditorGeometry of type Point, and the origin parameter is null (or is at the same location as the selected element), then rotating the selected element has no effect.

      Parameters:
      angle - the angle by which to rotate the selected element, counterclockwise, in degrees
      origin - the center of rotation. If null, the center of the extent of the GeometryEditor.selectedElementProperty() is used.
      Since:
      200.2.0
      See Also:
    • scaleSelectedElement

      public void scaleSelectedElement(double scaleX, double scaleY, Point origin)
      Scales the selected element by the specified factors.

      If the origin Point has a different SpatialReference than the associated MapView, the point will be reprojected before the geometry is rotated, using the default transformation.

      Positive scale factors greater than 1 increase the size of the geometryProperty(), and positive factors between 0 and 1 reduce the size of the geometry. Negative scale factors produce a geometry reflected across the axes of the origin point. Negative factors less than -1 both reflect and increase the size of the geometry, and negative factors between -1 and 0 both reflect and reduce the size of the geometry.

      Parameters:
      scaleX - the scale factor along the x-axis. It can be positive or negative. It cannot be 0, or a non-numeric value.
      scaleY - the scale factor along the y-axis. It can be positive or negative. It cannot be 0, or a non-numeric value.
      origin - the point relative to which the geometry will be scaled. If null, or Geometry.isEmpty() is true, the center of the extent of the selectedElementProperty() is used.
      Since:
      200.2.0
      See Also:
    • selectGeometry

      public void selectGeometry()
      Selects the entire geometry.

      When the entire geometry is selected it can be edited interactively and programmatically. For example you can move the entire geometry interactively by dragging, or call moveSelectedElement(Point) or moveSelectedElement(double, double) to move it programmatically.

      When the entire geometry is selected, the GeometryEditorGeometry returned from the selectedElementProperty() has a geometry equal to geometryProperty(). If the geometry is a Point, then a GeometryEditorVertex is returned from the selectedElementProperty() instead, which is equivalent to the entire geometry and provides immediate access to the x,y coordinates of the selected point geometry.

      Since:
      200.1.0
      See Also:
    • selectMidVertex

      public void selectMidVertex(long partIndex, long segmentIndex)
      Selects the mid-vertex with the specified indices.

      Mid-vertices do not exist in the geometry. They exist only in the display to serve as a visual cue that new vertices can be inserted between existing vertices. Since they do not exist in the geometry, mid-vertices cannot be programmatically moved or deleted. They can be used to insert a new vertex interactively.

      When a mid-vertex is selected, a GeometryEditorMidVertex is returned from the selectedElementProperty().

      Parameters:
      partIndex - the index of the part in the geometry editor's Multipart geometry that contains the mid-vertex to be selected. Use a value of 0 for non-multipart geometry types - Point and Multipoint.
      segmentIndex - the index of segment that the mid-vertex to be selected lies on, within the given part of the geometry editor's Multipart geometry, or within the Multipoint geometry. Use a value of 0 for Point geometries.
      Since:
      200.1.0
      See Also:
    • selectPart

      public void selectPart(long partIndex)
      Selects the part with the specified index.

      When a part of a polygon or polyline geometry is selected, a GeometryEditorPart is returned from the selectedElementProperty(). If the polygon or polyline has only one part, then a GeometryEditorGeometry with a shape equivalent to the entire geometry is returned as the selected element instead, which provides immediate access to the extent (Geometry.getExtent()) and can be directly used in other geometry operations. If the current geometry is a Point or Multipoint, the entire geometry is selected.

      When a part of a Polygon or Polyline (Multipart) geometry is selected it can be edited separately from the other parts of the geometry. For example, you can move only the selected part interactively by dragging, or call moveSelectedElement(Point) or moveSelectedElement(double, double) to move only the selected part programmatically.

      Parameters:
      partIndex - the index of the part in the geometry editor's Multipart geometry to be selected. Use a value of 0 for Multipoint geometries.
      Since:
      200.1.0
      See Also:
    • selectVertex

      public void selectVertex(long partIndex, long vertexIndex)
      Selects the vertex with the specified indices.

      When a vertex is selected it can be edited while all other vertices of the geometry are unchanged. For example, you can move only the selected vertex interactively by dragging, or call moveSelectedElement(Point) or moveSelectedElement(double, double) to move the selected vertex programmatically.

      When a vertex is selected, the selectedElementProperty() is a GeometryEditorVertex.

      Parameters:
      partIndex - the index of the part that contains the vertex (point) to be selected, within the geometry editor's Multipart geometry. Use a value of 0 for Point and Multipoint (non-multipart geometries).
      vertexIndex - the index of the vertex (point) to be selected, within the given part of the geometry editor's Multipart geometry, or within the Multipoint geometry. Use a value of 0 for Point geometries.
      Since:
      200.1.0
      See Also:
    • start

      public void start(Geometry initialGeometry)
      Starts a geometry editing session based on the specified geometry.

      Use this method for data editing workflows, where you have an existing Geometry to be updated. After calling this method, the geometry is drawn in the map view, and interactions with the map view will select and edit the geometry, depending on the current toolProperty() and its InteractionConfiguration.

      When the SpatialReference of the initial geometry differs from that of the map view, the display will project the geometry to the SpatialReference of the map view, using the default DatumTransformation, for display and user interactions. Editing feature data that is reprojected on the fly can introduce spatial errors into data. When accuracy is important, best practice is to use a spatial reference for the map view which matches the feature layer geometry you are editing. The ArcGIS Pro editing help topic Introduction to projection on the fly contains further advice.

      Parameters:
      initialGeometry - the initial geometry to start the editing session with.
      Throws:
      NullPointerException - if initialGeometry is null
      Since:
      200.1.0
    • start

      public void start(GeometryType geometryType)
      Starts a geometry editing session with an empty geometry of the specified GeometryType.

      Use this method for data creation workflows, where you know the GeometryType required but do not have an existing geometry to edit. After calling this method, nothing is drawn on the map view initially - user interactions on the map view will define and edit the geometry, depending on the current toolProperty().

      GeometryEditor can be used to create Point, Multipoint, Polygon, and Polyline geometries - however FreehandTool, and ShapeTool are suitable for creating Polygon, and Polyline geometries only.

      The new geometry will have the SpatialReference of the map view. You can use GeometryEngine.project(Geometry, SpatialReference) or GeometryEngine.project(Geometry, SpatialReference, DatumTransformation) to project the final result geometryProperty() to a different spatial reference if required, for example when editing feature geometry. When accuracy is important, best practice is to use a spatial reference for the map view which matches the feature layer geometry you are creating. The ArcGIS Pro editing help topic Introduction to projection on the fly contains further advice.

      Parameters:
      geometryType - the type of geometry to edit, must be one of: GeometryType.MULTIPOINT, GeometryType.POINT, GeometryType.POLYGON or GeometryType.POLYLINE.
      Throws:
      NullPointerException - if geometryType is null
      Since:
      200.1.0
    • stop

      public Geometry stop()
      Stops the editing session by making the GeometryEditor no longer respond to user interaction and clears the geometry.
      Returns:
      the final geometry before it is cleared. Null if the geometry editor is not started. Returns null if none.
      Since:
      200.1.0
      See Also:
    • undo

      public void undo()
      Undoes the last action on the geometry.
      Since:
      200.1.0
      See Also: