Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Sample] Snap Geometry Edits #194

Merged
merged 10 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snap-geometry-edits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
66 changes: 66 additions & 0 deletions snap-geometry-edits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Snap geometry edits

Use the Geometry Editor to edit a geometry and align it to existing geometries on a map.

![Image of Snap geometry edits](snap-geometry-edits.png)

## Use case

A field worker can create new features by editing and snapping the vertices of a geometry to existing features on a map. In a water distribution network, service line features can be represented with the polyline geometry type. By snapping the vertices of a proposed service line to existing features in the network, an exact footprint can be identified to show the path of the service line and what features in the network it connects to. The feature layer containing the service lines can then be accurately modified to include the proposed line.

## How to use the sample

To create a geometry, press the create button to choose 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.

To configure snapping, press the snap settings button to enable or disable snapping and choose which layers to snap to.

To interactively snap a vertex, ensure that snapping is enabled and move the mouse pointer or drag a vertex to nearby an existing feature. When the pointer is close to a feature, the edit position will be adjusted to coincide with (or snap to), edges and vertices of that feature. Click or release the touch pointer to place the vertex at the snapped location.

To edit a geometry, tap the geometry to be edited in the map to select it and then edit the geometry by tapping and dragging its vertices and snapping them to nearby features.

To edit a vertex using the magnifier, tap and hold on the vertex and then drag it along with the magnifier.

To undo changes made to the geometry, press the undo button.

To delete a geometry or a vertex, tap the geometry or vertex to select it and then press the delete button.

To save your edits, press the save button.

## How it works

1. Create a `Map` from the `URL` and connect it to the `MapView`.
2. Set the map's `LoadSettings.featureTilingMode` to `enabledWithFullResolutionWhenSupported`.
3. Create a `GeometryEditor` and connect it to the map view.
4. Call `syncSourceSettings` after the map's operational layers are loaded and the geometry editor connected to the map view.
5. Set `SnapSettings.isEnabled` and `SnapSourceSettings.isEnabled` to true for the `SnapSource` of interest.
6. Start the geometry editor with a `GeometryType`.

## Relevant API

* FeatureLayer
* Geometry
* GeometryEditor
* GeometryEditorStyle
* MapView
* MapView.interactionOptions.isMagnifierEnabled
* SnapSettings
* SnapSource
* SnapSourceSettings

## About the data

The [Naperville water distribution network](https://www.arcgis.com/home/item.html?id=b95fe18073bc4f7788f0375af2bb445e) is based on ArcGIS Solutions for Water Utilities and provides a realistic depiction of a theoretical stormwater network.

## Additional information

This sample uses the GeoViewCompose Toolkit module to be able to implement a Composable MapView.

Snapping is used to maintain data integrity between different sources of data when editing, so it is important that each `SnapSource` provides full resolution geometries to be valid for snapping. This means that some of the default optimizations used to improve the efficiency of data transfer and display of polygon and polyline layers based on feature services are not appropriate for use with snapping.

To snap to polygon and polyline layers, the recommended approach is to set the `FeatureLayer`'s feature tiling mode to `FeatureTilingMode.enabledWithFullResolutionWhenSupported` and use the default `ServiceFeatureTable` feature request mode `FeatureRequestMode.onInteractionCache`. Local data sources, such as geodatabases, always provide full resolution geometries.

Snapping can be used during interactive edits that move existing vertices using the `VertexTool`. Using the magnifier to perform the vertex move allows to clearly see the visual cues for snapping.

## Tags

edit, feature, geometryeditor, geoviewcompose, layers, magnify, map, snapping
49 changes: 49 additions & 0 deletions snap-geometry-edits/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"category": "Edit and Manage Data",
"description": "Use the Geometry Editor to edit a geometry and align it to existing geometries on a map.",
"formal_name": "SnapGeometryEdits",
"ignore": false,
"images": [
"snap-geometry-edits.png"
],
"keywords": [
"edit",
"feature",
"geometryeditor",
"geoviewcompose",
"layers",
"magnify",
"map",
"snapping",
"FeatureLayer",
"Geometry",
"GeometryEditor",
"GeometryEditorStyle",
"MapView",
"MapView.interactionOptions.isMagnifierEnabled",
"SnapSettings",
"SnapSource",
"SnapSourceSettings"
],
"language": "kotlin",
"redirect_from": "",
"relevant_apis": [
"FeatureLayer",
"Geometry",
"GeometryEditor",
"GeometryEditorStyle",
"MapView",
"MapView.interactionOptions.isMagnifierEnabled",
"SnapSettings",
"SnapSource",
"SnapSourceSettings"
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/snapgeometryedits/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/snapgeometryedits/screens/MainScreen.kt",
"src/main/java/com/esri/arcgismaps/sample/snapgeometryedits/components/MapViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/snapgeometryedits/components/ButtonMenu.kt",
"src/main/java/com/esri/arcgismaps/sample/snapgeometryedits/components/BottomSheetContent.kt"
],
"title": "Snap geometry edits"
}
54 changes: 54 additions & 0 deletions snap-geometry-edits/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
applicationId = "com.esri.arcgismaps.sample.snapgeometryedits"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = libs.versions.versionCode.get().toInt()
versionName = libs.versions.versionName.get()
buildConfigField("String", "API_KEY", project.properties["API_KEY"].toString())
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}

buildFeatures {
compose = true
buildConfig = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.kotlinCompilerExt.get()
}

namespace = "com.esri.arcgismaps.sample.snapgeometryedits"
}

dependencies {
// lib dependencies from rootProject build.gradle.kts
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.activity.compose)
// Jetpack Compose Bill of Materials
implementation(platform(libs.androidx.compose.bom))
// Jetpack Compose dependencies
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(project(":samples-lib"))
// Toolkit dependencies
implementation(platform(libs.arcgis.maps.kotlin.toolkit.bom))
implementation(libs.arcgis.maps.kotlin.toolkit.geoview.compose)
}
21 changes: 21 additions & 0 deletions snap-geometry-edits/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Binary file added snap-geometry-edits/snap-geometry-edits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions snap-geometry-edits/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:exported="true"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Copyright 2024 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.snapgeometryedits

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
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.snapgeometryedits.screens.MainScreen

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.API_KEY)

setContent {
SampleAppTheme {
SampleApp()
}
}
}

@Composable
private fun SampleApp() {
Surface(
color = MaterialTheme.colorScheme.background
) {
MainScreen(
sampleName = getString(R.string.app_name)
)
}
}
}
Loading
Loading