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

Sample: Edit features using feature forms #228

Merged
merged 21 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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 edit-features-using-feature-forms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions edit-features-using-feature-forms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Edit features using feature forms

Display and edit feature attributes using feature forms

![Image of edit features using feature forms](edit-features-using-feature-forms.png)

## Use case

Feature forms help enhance the accuracy, efficiency, and user experience of attribute editing in your application. Forms can be authored as part of the WebMap using Field Maps Designer or using Web Map Viewer. This allows for a simplified user experience to edit feature attribute data on the web-map.
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved

## How to use the sample

Tap a feature on the feature form map to open a bottom sheet displaying the list of form elements. Select through the list of elements to view the coded value field groups and edit elements to update the field values. Tap the submit icon to commit the changes on the web map.

## How it works

1. Add a feature form enabled web-map to the MapView using `PortalItem` URL and itemID.
2. When the map is tapped, perform an identity operation to check if the tapped location is an `ArcGISFeature` and the `FeatureLayer.featureFormDefinition` is not null, indicating the feature layer does have an associated feature form definition.
3. Create a `FeatureForm()` object using the identified `ArcGISFeature` and the `FeatureLayer.featureFormDefinition`.
4. On the screen within a bottom sheet, use the `FeatureForm` Toolkit component to display the feature form configuration by providing the created `featureForm` object.
5. Optionally, you can add a `validationErrorVisibility` option to the `FeatureForm` Toolkit component that determines the behavior of when the validation errors are visible.
6. Once edits are added to the form fields, check to verify that there are no validation errors using `featureForm.validationErrors`. The list will be empty if there are no errors.
7. To commit edits on the service geodatabase:
1. Call `featureForm.finishEditing()` to save edits to the database.
2. Retrieve the backing service feature table's geodatabase using `(featureForm.feature.featureTable as? ServiceFeatureTable)?.serviceGeodatabase`.
3. Verify the service geodatabase can commit changes back to the service using `serviceGeodatabase.serviceInfo?.canUseServiceGeodatabaseApplyEdits`
4. If apply edits are allowed, call `serviceGeodatabase.applyEdits()` to apply local edits to the online service.
shubham7109 marked this conversation as resolved.
Show resolved Hide resolved

## Relevant API

* ArcGISFeature
* FeatureForm
* FeatureLayer
* FieldFormElement
* GroupFormElement
* ServiceFeatureTable

## Additional information

This sample uses the FeatureForm and GeoViewCompose Toolkit modules to be able to implement a Composable MapView which displays a Composable FeatureForm UI.

## Tags

compose, edits, feature, featureforms, form, geoviewcompose, jetpack, toolkit
41 changes: 41 additions & 0 deletions edit-features-using-feature-forms/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"category": "Edit and Manage Data",
"description": "Display and edit feature attributes using feature forms",
"formal_name": "EditFeaturesUsingFeatureForms",
"ignore": false,
"images": [
"edit-features-using-feature-forms.png"
],
"keywords": [
"compose",
"edits",
"feature",
"featureforms",
"form",
"geoviewcompose",
"jetpack",
"toolkit",
"ArcGISFeature",
"FeatureForm",
"FeatureLayer",
"FieldFormElement",
"GroupFormElement",
"ServiceFeatureTable"
],
"language": "kotlin",
"redirect_from": "",
"relevant_apis": [
"ArcGISFeature",
"FeatureForm",
"FeatureLayer",
"FieldFormElement",
"GroupFormElement",
"ServiceFeatureTable"
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/editfeaturesusingfeatureforms/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/editfeaturesusingfeatureforms/components/MapViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/editfeaturesusingfeatureforms/screens/MainScreen.kt"
],
"title": "Edit features using feature forms"
}
55 changes: 55 additions & 0 deletions edit-features-using-feature-forms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

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

defaultConfig {
applicationId = "com.esri.arcgismaps.sample.editfeaturesusingfeatureforms"
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.editfeaturesusingfeatureforms"
}

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)
implementation(libs.arcgis.maps.kotlin.toolkit.featureforms)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions edit-features-using-feature-forms/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
24 changes: 24 additions & 0 deletions edit-features-using-feature-forms/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,40 @@
/* 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.editfeaturesusingfeatureforms

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components.MapViewModel
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.screens.MainScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ArcGISEnvironment.applicationContext = this
setContent {
SampleAppTheme {
val mapViewModel: MapViewModel = viewModel()
MainScreen(mapViewModel)
}
}
}
}
Loading
Loading