View on GitHub Sample viewer app

Use the Programmatic Reticle Tool to edit and create geometries with programmatic operations to facilitate customized workflows such as those using buttons rather than tap interactions.

EditGeometriesWithProgrammaticReticleTool

Use case

A field worker can use a button driven workflow to mark important features on a map. They can digitize features like sample or observation locations, fences, pipelines, and building footprints using point, multipoint, polyline, and polygon geometries. To create and edit geometries, workers can use a vertex-based reticle tool to specify vertex locations by panning the map to position the reticle over a feature of interest. Using a button-driven workflow they can then place new vertices or pick up, move and drop existing vertices.

How to use the sample

To create a new geometry, select the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) in the settings view. Press the button to start the geometry editor, pan the map to position the reticle then press the button to place a vertex. To edit an existing geometry, tap the geometry to be edited in the map and perform edits by positioning the reticle over a vertex and pressing the button to pick it up. The vertex can be moved by panning the map and dropped in a new position by pressing the button again.

Vertices can be selected and the viewpoint can be updated to their position by tapping them.

Vertex creation can be disabled using the switch in the settings view. When this switch is toggled off new vertex creation is prevented, existing vertices can be picked up and moved, but mid-vertices cannot be selected or picked up and will not grow when hovered. The feedback vertex and feedback lines under the reticle will also no longer be visible.

Use the buttons in the settings view to undo or redo changes made to the geometry and the cancel and done buttons to discard and save changes, respectively.

How it works

  1. Create a GeometryEditor and pass it to the MapView Composable.
  2. Start the GeometryEditor using GeometryEditor.start(GeometryType) to create a new geometry or GeometryEditor.start(Geometry) to edit an existing geometry.
    • If using the Geometry Editor to edit an existing geometry, the geometry must be retrieved from the graphics overlay being used to visualize the geometry prior to calling the start method. To do this:
      • Use MapViewProxy.identify(GraphicsOverlay, ...) to identify graphics at the location of a tap.
      • Find the desired graphic in the resulting list.
      • Access the geometry associated with the graphic using Graphic.geometry - this will be used in the GeometryEditor.start(Geometry) method.
  3. Create a ProgrammaticReticleTool and set the GeometryEditor.tool.
  4. Launch coroutines to listen to GeometryEditor.hoveredElement and GeometryEditor.pickedUpElement.
    • These events can be used to determine the effect a button press will have and set the button text accordingly.
  5. Listen to tap events when the geometry editor is active to select and navigate to tapped vertices and mid-vertices.
    • To retrieve the tapped element and update the viewpoint:
      • Use MapViewProxy.identifyGeometryEditor(...) to identify geometry editor elements at the location of the tap.
      • Find the desired element in the resulting list.
      • Depending on whether or not the element is a GeometryEditorVertex or GeometryEditorMidVertex use GeometryEditor.selectVertex(...) or GeometryEditor.selectMidVertex(...) to select it.
      • Update the viewpoint using MapViewProxy.setViewpointCenter(...).
  6. Enable and disable the vertex creation preview using ProgrammaticReticleTool.vertexCreationPreviewEnabled.
    • To prevent mid-vertex growth when hovered use ProgrammaticReticleTool.style.growEffect.applyToMidVertices.
  7. Check to see if undo and redo are possible during an editing session using GeometryEditor.canUndo and GeometryEditor.canRedo. If it’s possible, use GeometryEditor.undo() and GeometryEditor.redo().
    • A picked up element can be returned to its previous position using GeometryEditor.cancelCurrentAction(). This can be useful to undo a pick up without undoing any change to the geometry. Use the GeometryEditor.pickedUpElement property to check for a picked up element.
  8. Check whether the currently selected GeometryEditorElement can be deleted (GeometryEditor.selectedElement.canDelete). If the element can be deleted, delete using GeometryEditor.deleteSelectedElement().
  9. Call GeometryEditor.stop() to finish the editing session and store the Graphic. The GeometryEditor does not automatically handle the visualization of a geometry output from an editing session. This must be done manually by propagating the geometry returned into a Graphic added to a GraphicsOverlay.
    • To create a new Graphic in the GraphicsOverlay:
      • Using Graphic(Geometry), create a new Graphic with the geometry returned by the GeometryEditor.stop() method.
      • Append the Graphic to the GraphicsOverlay(i.e. GraphicsOverlay.graphics.add(Graphic)).
    • To update the geometry underlying an existing Graphic in the GraphicsOverlay:
      • Replace the existing Graphic’s geometry property with the geometry returned by the GeometryEditor.stop() method.

Relevant API

  • Geometry
  • GeometryEditor
  • Graphic
  • GraphicsOverlay
  • MapView
  • ProgrammaticReticleTool

Additional information

The sample demonstrates a number of workflows which can be altered depending on desired app functionality:

  • picking up a hovered element combines selection and pick up, this can be separated into two steps to require selection before pick up.

  • tapping a vertex or mid-vertex selects it and updates the viewpoint to its position. This could be changed to not update the viewpoint or also pick up the element.

With the hovered and picked up element changed events and the programmatic APIs on the ProgrammaticReticleTool a broad range of editing experiences can be implemented.

Tags

draw, edit, freehand, geometry editor, programmatic, reticle, sketch, vertex

Sample Code

MainActivity.kt MainActivity.kt EditGeometriesWithProgrammaticReticleToolViewModel.kt EditGeometriesWithProgrammaticReticleToolScreen.kt SettingsScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.editgeometrieswithprogrammaticreticletool
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.editgeometrieswithprogrammaticreticletool.screens.EditGeometriesWithProgrammaticReticleToolScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
enableEdgeToEdge()
setContent {
SampleAppTheme {
EditGeometriesWithProgrammaticReticleToolApp()
}
}
}
@Composable
private fun EditGeometriesWithProgrammaticReticleToolApp() {
Surface(color = MaterialTheme.colorScheme.background) {
EditGeometriesWithProgrammaticReticleToolScreen(
sampleName = getString(R.string.edit_geometries_with_programmatic_reticle_tool_app_name)
)
}
}
}