Skip to content

New sample: Manage features #331

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

Merged
merged 9 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
Empty file.
42 changes: 42 additions & 0 deletions samples/manage-features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Manage features

Create, update, and delete features to manage a feature layer.

![Screenshot of manage features](manage-features.png)

## Use case

An end-user performing a survey may want to manage features on the map in various ways during the course of their work.

## How to use the sample

Pick an operation, then tap on the map to perform the operation at that location. Available feature management operations include: "Create feature", "Delete feature", "Update attribute", and "Update geometry".

## How it works

1. Create a `ServiceGeodatabase` from a URL.
2. Get a `ServiceFeatureTable` from the `ServiceGeodatabase`.
3. Create a `FeatureLayer` derived from the `ServiceFeatureTable` instance.
4. Apply the feature management operation upon tapping the map.
- Create features: create a `Feature` with attributes and a location using the `ServiceFeatureTable`.
- Delete features: delete the selected `Feature` from the `FeatureTable`.
- Update attribute: update the attribute of the selected `Feature`.
- Update geometry: update the geometry of the selected `Feature`.
5. Update the `FeatureTable` locally.
6. Update the `ServiceGeodatabase` of the `ServiceFeatureTable` by calling `applyEdits()`. This pushes the changes to the server.

## Relevant API

* Feature
* FeatureEditResult
* FeatureLayer
* ServiceFeatureTable
* ServiceGeodatabase

## Additional information

When editing feature tables that are subject to database behavior (operations on one table affecting another table), it's recommended to call these methods (apply or undo edits) on the `ServiceGeodatabase` object rather than on the `ServiceFeatureTable` object. Using the `ServiceGeodatabase` object to call these operations will prevent possible data inconsistencies and ensure transactional integrity so that all changes can be committed or rolled back.

## Tags

amend, attribute, create, delete, deletion, details, edit, editing, feature, feature layer, feature table, geodatabase, information, moving, online service, service, update, updating, value
50 changes: 50 additions & 0 deletions samples/manage-features/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"category": "Edit and Manage Data",
"description": "Create, update, and delete features to manage a feature layer.",
"formal_name": "ManageFeatures",
"ignore": false,
"images": [
"manage-features.png"
],
"keywords": [
"amend",
"attribute",
"create",
"delete",
"deletion",
"details",
"edit",
"editing",
"feature",
"feature layer",
"feature table",
"geodatabase",
"information",
"moving",
"online service",
"service",
"update",
"updating",
"value",
"Feature",
"FeatureEditResult",
"FeatureLayer",
"ServiceFeatureTable",
"ServiceGeodatabase"
],
"language": "kotlin",
"redirect_from": "",
"relevant_apis": [
"Feature",
"FeatureEditResult",
"FeatureLayer",
"ServiceFeatureTable",
"ServiceGeodatabase"
],
"snippets": [
"src/main/java/com/esri/arcgismaps/sample/managefeatures/components/ManageFeaturesViewModel.kt",
"src/main/java/com/esri/arcgismaps/sample/managefeatures/MainActivity.kt",
"src/main/java/com/esri/arcgismaps/sample/managefeatures/screens/ManageFeaturesScreen.kt"
],
"title": "Manage features"
}
22 changes: 22 additions & 0 deletions samples/manage-features/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.arcgismaps.android.library)
alias(libs.plugins.arcgismaps.android.library.compose)
alias(libs.plugins.arcgismaps.kotlin.sample)
alias(libs.plugins.gradle.secrets)
}

secrets {
// this file doesn't contain secrets, it just provides defaults which can be committed into git.
defaultPropertiesFileName = "secrets.defaults.properties"
}

android {
namespace = "com.esri.arcgismaps.sample.managefeatures"
buildFeatures {
buildConfig = true
}
}

dependencies {
// Only module specific dependencies needed here
}
Binary file added samples/manage-features/manage-features.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions samples/manage-features/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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><activity
android:exported="true"
android:name=".MainActivity"
android:label="@string/manage_features_app_name">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* 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.managefeatures

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.managefeatures.screens.ManageFeaturesScreen

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)

setContent {
SampleAppTheme {
ManageFeaturesApp()
}
}
}

@Composable
private fun ManageFeaturesApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ManageFeaturesScreen(
sampleName = getString(R.string.manage_features_app_name)
)
}
}
}
Loading
Loading