GeometryEditor

Allows you to create new geometries, and change existing geometries, by interacting with a com.arcgismaps.mapping.view.MapView. To use a GeometryEditor:

When started (GeometryEditor.isStarted is true), you can interact with the different GeometryEditorElement objects that compose the representation of the GeometryEditor.geometry in the map view. Depending on what is selected, different types of GeometryEditorElement are returned from GeometryEditor.selectedElement.

The type of the current GeometryEditor.tool determines how you create and edit geometries, with the current InteractionConfiguration or ReticleInteractionConfiguration allowing you to enable or disable different interactions and capabilities of the tool.

  • The default VertexTool allows you to create and edit geometries by interacting with individual vertices. You can tap to select the different elements and drag to move them, and also tap multiple times on an element to select the different types of GeometryEditorElement representing vertices, parts, or the entire geometry. You can rotate and scale the selected element (if applicable to the selected element type), and can also create new parts in a multipart geometry (if enabled in the InteractionConfiguration).

  • The FreehandTool is ideal for creating new polygon or polyline geometries using a single freehand drag gesture. It also allows multiple taps to cycle the selected element type.

  • The ShapeTool is ideal for creating new polygon or polyline geometries with a geometric shape by using a single drag interaction. It also allows multiple taps to cycle the selected element type.

  • The ReticleVertexTool is recommended for precise, vertex-based, geometry editing on touch devices, especially when using snapping (SnapSettings). It does not support multiple taps to cycle the selected element.

Programmatic changes to the GeometryEditor.geometry or GeometryEditor.selectedElement (for example calling GeometryEditor.selectVertex or GeometryEditor.moveSelectedElement) not affected by the settings in InteractionConfiguration or ReticleInteractionConfiguration.

Change the appearance of the geometry by using the GeometryEditorStyle of the current GeometryEditor.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 GeometryEditor.snapSettings 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 GeometryEditor.geometryChanged and GeometryEditor.selectedElementChanged to be notified when a user interaction or API call has changed the GeometryEditor.selectedElement or GeometryEditor.geometry. Changing the geometry state can also change GeometryEditor.canUndo, which triggers GeometryEditor.canUndoChanged.

Since

200.1.0

Constructors

Link copied to clipboard
constructor()

Creates a default GeometryEditor.

Properties

Link copied to clipboard
val canRedo: StateFlow<Boolean>

True if there are actions that can be redone on the GeometryEditor.geometry, false otherwise. This applies to both programmatic and interactive changes to the GeometryEditor.geometry and is useful for enabling or disabling a UI control for redo actions.

Link copied to clipboard
val canUndo: StateFlow<Boolean>

True if there are actions that can be undone on the GeometryEditor.geometry, false otherwise. This applies to both programmatic and interactive changes to the GeometryEditor.geometry and is useful for enabling or disabling a UI control for undo actions.

Link copied to clipboard
val geometry: StateFlow<Geometry?>

The current geometry, updated as you interact with the view. The geometry returned depends on the state of the GeometryEditor:

Link copied to clipboard
val isStarted: StateFlow<Boolean>

True if an editing session is active, false otherwise. When true, interactions with the view can affect the state of the GeometryEditor.geometry or GeometryEditor.selectedElement.

Link copied to clipboard

True if the geometry is visible in the view, false otherwise.

Link copied to clipboard

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 GeometryEditor.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 GeometryEditor.tool.

Link copied to clipboard
val snapChanged: SharedFlow<SnapChangedInfo>

Indicates that the snap candidate used by the GeometryEditor has changed. The snap candidate may change when the pointer is moved close to or away from an existing snappable geometry or geometry guide. When this change results in a different snap candidate, or the edit position becoming unsnapped, this event fires.

Link copied to clipboard

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.

Link copied to clipboard

The tool defining how you interact with the view to create and edit the GeometryEditor.geometry. The default value is a VertexTool with all interactive operations enabled, providing a common way of editing points, multipoints, polygons, and polylines.

Functions

Link copied to clipboard

Clears the current geometry being edited. Sets GeometryEditor.geometry to an empty geometry (com.arcgismaps.geometry.Geometry.isEmpty = true). The com.arcgismaps.geometry.GeometryType is maintained - to edit a different type of geometry, restart the GeometryEditor with the required type.

Link copied to clipboard

Clears the current selection. This sets GeometryEditor.selectedElement to null. It does not change the GeometryEditor.geometry.

Link copied to clipboard

Deletes the selected element from the current GeometryEditor.geometry. To clear the selection, but leave the state of the GeometryEditor.geometry unchanged, call GeometryEditor.clearSelection instead.

Link copied to clipboard
fun 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 GeometryEditor.geometry is empty (com.arcgismaps.geometry.Geometry.isEmpty is true), the given point is added as the initial vertex, and then selected. If nothing is selected (GeometryEditor.selectedElement is null), the point is appended to the end of the GeometryEditor.geometry, and then selected. If GeometryEditor.selectedElement is the first vertex in a part of a com.arcgismaps.geometry.Multipart, the given point is inserted before the currently selected vertex, and then selected.

Link copied to clipboard
fun moveSelectedElement(newPoint: Point)

Moves the selected element to the specified location. If GeometryEditor.selectedElement is a GeometryEditorVertex, then the location of the vertex is moved to the given point. If the GeometryEditor.selectedElement is any other type of GeometryEditorElement, then the center of the element is moved to the given point.

fun moveSelectedElement(deltaX: Double, deltaY: Double)

Moves the selected element by the specified distances along the x-axis and y-axis.

Link copied to clipboard
fun redo()

Redoes the last action undone on the GeometryEditor.geometry.

Link copied to clipboard
fun replaceGeometry(geometry: Geometry)

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

Link copied to clipboard
fun rotateSelectedElement(angle: Double, origin: Point? = null)

Rotates the GeometryEditor.selectedElement 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 the by 180 degrees. A positive value corresponds to a counterclockwise rotation.

Link copied to clipboard
fun scaleSelectedElement(scaleX: Double, scaleY: Double, origin: Point? = null)

Scales the selected element by the specified factors. If the origin com.arcgismaps.geometry.Point has a different com.arcgismaps.geometry.SpatialReference than the associated com.arcgismaps.mapping.view.MapView, the point will be reprojected before the geometry is rotated, using the default transformation.

Link copied to clipboard

Selects the entire GeometryEditor.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 GeometryEditor.moveSelectedElement or GeometryEditor.moveSelectedElement to move it programmatically.

Link copied to clipboard
fun selectMidVertex(partIndex: Int, segmentIndex: Int)

Selects the mid-vertex with the specified indices. Mid-vertices do not exist in the GeometryEditor.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.

Link copied to clipboard
fun selectPart(partIndex: Int)

Selects the part with the specified index. When a part of a polygon or polyline geometry is selected, a GeometryEditorPart is returned from GeometryEditor.selectedElement. If the polygon or polyline has only one com.arcgismaps.geometry.Part, then a GeometryEditorGeometry with a shape equivalent to the entire geometry is returned from GeometryEditor.selectedElement instead, which provides immediate access to the extent (com.arcgismaps.geometry.Geometry.extent) and can be directly used in other geometry operations. If the current GeometryEditor.geometry is a com.arcgismaps.geometry.Point or com.arcgismaps.geometry.Multipoint, the entire geometry is selected.

Link copied to clipboard
fun selectVertex(partIndex: Int, vertexIndex: Int)

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 GeometryEditor.moveSelectedElement or GeometryEditor.moveSelectedElement to move the selected vertex programmatically.

Link copied to clipboard
fun start(initialGeometry: Geometry)

Starts a geometry editing session based on the specified geometry. Use this method for data editing workflows, where you have an existing com.arcgismaps.geometry.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 GeometryEditor.tool and its InteractionConfiguration.

fun start(geometryType: GeometryType)

Starts a geometry editing session with an empty geometry of the specified com.arcgismaps.geometry.GeometryType. Use this method for data creation workflows, where you know the com.arcgismaps.geometry.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 GeometryEditor.tool.

Link copied to clipboard
fun stop(): Geometry?

Stops the editing session by making the GeometryEditor no longer respond to user interaction and clears the GeometryEditor.geometry.

Link copied to clipboard
fun undo()

Undoes the last action on the GeometryEditor.geometry.