Edit features using feature forms

View on GitHubSample viewer app

Display and edit feature attributes using feature forms.

Image of Edit features using feature forms

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 web map using Field Maps Designer or using Map Viewer. This allows a simplified user experience to edit feature attribute data on the web map.

How to use the sample

Tap a feature on the map to open a sheet displaying the feature form. Select form elements in the list and perform edits to update the field values. Tap the submit icon to commit the changes on the web map.

How it works

  1. Add a Map to the MapView using Portal URL and item ID.
  2. When the map is tapped, perform an identify operation to check if the tapped location is an ArcGISFeature.
  3. Create a FeatureForm object using the identified ArcGISFeature.
  • Note: If the feature's FeatureLayer, ArcGISFeatureTable, or the SubtypeSublayer has an authored FeatureFormDefinition, then this definition will be used to create the FeatureForm. If such a definition is not found, a default definition is generated.
  1. Use the FeatureForm toolkit component to display the feature form configuration by providing the created featureForm object.
  2. Optionally, you can add a validationErrorVisibility option to the FeatureForm toolkit component that determines the visibility of validation errors.
  3. Once edits are added to the form fields, check if the validation errors list are empty using featureForm.validationErrors to verify that there are no errors.
  4. 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 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.
    5. If edits are not allowed on the ServiceGeodatabase, then apply edits to the ServiceFeatureTable using ServiceFeatureTable.applyEdits()

Relevant API

  • ArcGISFeature
  • FeatureForm
  • FeatureLayer
  • FieldFormElement
  • GroupFormElement
  • ServiceFeatureTable
  • ServiceGeodatabase

About the data

This sample uses a feature forms enabled Feature Form Places web map, which contains fictional places in San Diego of various hotels, restaurants, and shopping centers, with relevant reviews and ratings.

Additional information

Follow the tutorial to create your own form using the Map Viewer. This sample uses the FeatureForm and GeoViewCompose Toolkit modules to be able to implement a Composable MapView which displays a Composable FeatureForm UI.

This sample uses the feature forms toolkit component. For information about setting up the toolkit, as well as code for the underlying component, visit the toolkit repository.

Tags

compose, edits, feature, featureforms, form, geoviewcompose, jetpack, toolkit

Sample Code

MainActivity.ktMainActivity.ktMapViewModel.ktMainScreen.kt
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
            }
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.