Skip to content

Commit d25c88d

Browse files
darryl-lynchTADraeseke01smito01hud10837
authored
Sample: Create and edit geometries (#330)
Co-authored-by: TADraeseke <[email protected]> Co-authored-by: Oliver Smith <[email protected]> Co-authored-by: hud10837 <[email protected]>
1 parent 00a24cd commit d25c88d

File tree

13 files changed

+989
-0
lines changed

13 files changed

+989
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Create and edit geometries
2+
3+
Use the Geometry Editor to create new point, multipoint, polyline, or polygon geometries or to edit existing geometries by interacting with a map view.
4+
5+
![CreateAndEditGeometries](create-and-edit-geometries.png)
6+
7+
## Use case
8+
9+
A field worker can mark features of interest on a map using an appropriate geometry. Features such as sample or observation locations, fences or pipelines, and building footprints can be digitized using point, multipoint, polyline, and polygon geometry types. Polyline and polygon geometries can be created and edited using a vertex-based creation and editing tool (i.e. vertex locations specified explicitly via tapping), or using a freehand tool.
10+
11+
## How to use the sample
12+
13+
To create a new geometry, press the button appropriate for the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) and interactively tap and drag on the map view to create the geometry.
14+
15+
To edit an existing geometry, tap the geometry to be edited in the map and then perform edits by tapping and dragging its elements.
16+
17+
When the whole geometry is selected, you can use the control handles to scale and rotate the geometry.
18+
19+
If creating or editing polyline or polygon geometries, choose the desired creation/editing tool (i.e. `VertexTool`, `ReticleVertexTool`, `FreehandTool`, or one of the available `ShapeTool`s).
20+
21+
When using the `ReticleVertexTool`, you can move the map position of the reticle by dragging and zooming the map. Insert a vertex under the reticle by tapping on the map. Move a vertex by tapping when the reticle is located over a vertex, drag the map to move the position of the reticle, then tap a second time to place the vertex.
22+
23+
Use the control panel to undo or redo changes made to the geometry, delete a selected element, save the geometry, stop the editing session and discard any edits, and remove all geometries from the map.
24+
25+
## How it works
26+
27+
1. Create a `MapViewProxy` for interacting with the composable `MapView`.
28+
2. Create a `GeometryEditor` for creating and editing `Geometry`s.
29+
3. Create `VertexTool`, `ReticleVertexTool`, `FreehandTool`, or `ShapeTool` objects to define how the user interacts with the view to create or edit geometries, and set the geometry editor tool using the `geometryEditor.tool` property.
30+
4. Edit a tool's `InteractionConfiguration` to set the `GeometryEditorScaleMode` to allow either uniform or stretch scale mode.
31+
5. Create a `MapView` with MapView using `MapView(mapViewProxy = MapViewProxy, geometryEditor = GeometryEditor, ...)`.
32+
6. Start the `GeometryEditor` using `GeometryEditor.start(GeometryType)` to create a new geometry or `GeometryEditor.start(Geometry)` to edit an existing geometry.
33+
* 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:
34+
* Use `MapViewProxy.identifyGraphicsOverlays(...)` to identify graphics at the location of a tap.
35+
* Find the desired `IdentifyGraphicsOverlayResult` in the list returned by `MapViewProxy.identifyGraphicsOverlays(...)`.
36+
* Find the desired graphic in the `IdentifyGraphicsOverlayResult.graphics` list.
37+
* Access the geometry associated with the `Graphic` using `Graphic.geometry` - this will be used in the `GeometryEditor.start(Geometry)` method.
38+
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()`.
39+
8. Check whether the currently selected `GeometryEditorElement` can be deleted (`GeometryEditor.selectedElement.canDelete`). If the element can be deleted, delete using `GeometryEditor.deleteSelectedElement`.
40+
9. Call `GeometryEditor.stop()` to finish the editing session. 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 by `GeometryEditor.stop()` into a `Graphic` added to a `GraphicsOverlay`.
41+
* To create a new `Graphic` in the `GraphicsOverlay`:
42+
* Using `Graphic(Geometry)`, create a new Graphic with the geometry returned by the `GeometryEditor.stop()` method.
43+
* Add the `Graphic` to the `GraphicsOverlay`'s list of `Graphic`s (i.e. `GraphicsOverlay.graphics.add(Graphic)`).
44+
* To update the geometry underlying an existing `Graphic` in the `GraphicsOverlay`:
45+
* Replace the existing `Graphic`'s `Geometry` property with the geometry returned by the `GeometryEditor.stop()`.
46+
47+
## Relevant API
48+
49+
* Geometry
50+
* GeometryEditor
51+
* Graphic
52+
* GraphicsOverlay
53+
* MapView
54+
55+
## Additional information
56+
57+
The sample opens with the ArcGIS Imagery basemap centered on the island of Inis Meáin (Aran Islands) in Ireland. Inis Meáin comprises a landscape of interlinked stone walls, roads, buildings, archaeological sites, and geological features, producing complex geometrical relationships.
58+
59+
This sample uses the GeoView-Compose Toolkit module to be able to implement a composable MapView.
60+
61+
## Tags
62+
63+
draw, edit, freehand, geometry editor, geoview-compose, sketch, toolkit, vertex
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"category": "Edit and Manage Data",
3+
"description": "Use the Geometry Editor to create new point, multipoint, polyline, or polygon geometries or to edit existing geometries by interacting with a map view.",
4+
"formal_name": "CreateAndEditGeometries",
5+
"ignore": false,
6+
"images": [
7+
"create-and-edit-geometries.png"
8+
],
9+
"keywords": [
10+
"draw",
11+
"edit",
12+
"freehand",
13+
"geometry editor",
14+
"geoview-compose",
15+
"sketch",
16+
"toolkit",
17+
"vertex",
18+
"Geometry",
19+
"GeometryEditor",
20+
"Graphic",
21+
"GraphicsOverlay",
22+
"MapView"
23+
],
24+
"language": "kotlin",
25+
"redirect_from": "",
26+
"relevant_apis": [
27+
"Geometry",
28+
"GeometryEditor",
29+
"Graphic",
30+
"GraphicsOverlay",
31+
"MapView"
32+
],
33+
"snippets": [
34+
"src/main/java/com/esri/arcgismaps/sample/createandeditgeometries/components/CreateAndEditGeometriesViewModel.kt",
35+
"src/main/java/com/esri/arcgismaps/sample/createandeditgeometries/MainActivity.kt",
36+
"src/main/java/com/esri/arcgismaps/sample/createandeditgeometries/screens/CreateAndEditGeometriesScreen.kt",
37+
"src/main/java/com/esri/arcgismaps/sample/createandeditgeometries/screens/ButtonMenu.kt"
38+
],
39+
"title": "Create and edit geometries"
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
alias(libs.plugins.arcgismaps.android.library)
3+
alias(libs.plugins.arcgismaps.android.library.compose)
4+
alias(libs.plugins.arcgismaps.kotlin.sample)
5+
alias(libs.plugins.gradle.secrets)
6+
}
7+
8+
secrets {
9+
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
10+
defaultPropertiesFileName = "secrets.defaults.properties"
11+
}
12+
13+
android {
14+
namespace = "com.esri.arcgismaps.sample.createandeditgeometries"
15+
buildFeatures {
16+
buildConfig = true
17+
}
18+
}
19+
20+
dependencies {
21+
// Only module specific dependencies needed here
22+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application><activity
7+
android:exported="true"
8+
android:name=".MainActivity"
9+
android:label="@string/create_and_edit_geometries_app_name">
10+
</activity>
11+
</application>
12+
13+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2025 Esri
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
package com.esri.arcgismaps.sample.createandeditgeometries
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.Surface
24+
import androidx.compose.runtime.Composable
25+
import com.arcgismaps.ApiKey
26+
import com.arcgismaps.ArcGISEnvironment
27+
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
28+
import com.esri.arcgismaps.sample.createandeditgeometries.screens.CreateAndEditGeometriesScreen
29+
30+
class MainActivity : ComponentActivity() {
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
// authentication with an API key or named user is
35+
// required to access basemaps and other location services
36+
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
37+
38+
setContent {
39+
SampleAppTheme {
40+
CreateAndEditGeometriesApp()
41+
}
42+
}
43+
}
44+
45+
@Composable
46+
private fun CreateAndEditGeometriesApp() {
47+
Surface(color = MaterialTheme.colorScheme.background) {
48+
CreateAndEditGeometriesScreen(
49+
sampleName = getString(R.string.create_and_edit_geometries_app_name)
50+
)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)