Delete features (feature service)

View inJavaKotlin
View on GitHub
Sample viewer app

Delete features from an online feature service.

Image of delete features feature service

Use case

Sometimes users may want to delete features from an online feature service.

How to use the sample

Tap on a feature on the map and tap the trash icon to delete it.

How it works

  1. Create a ServiceFeatureTable object from a URL.
  2. Create a FeatureLayer object from the ServiceFeatureTable.
  3. Select features from the FeatureTable via queryFeaturesAsync(...).
  4. Remove the selected features from the ServiceFeatureTable using deleteFeaturesAsync(...).
  5. Update the table on the server using applyEditsAsync().

Relevant API

  • Feature
  • FeatureLayer
  • ServiceFeatureTable

Tags

deletion, feature, online, Service, table

Sample Code

ConfirmDeleteFeatureDialog.ktMainActivity.kt
                                                                         
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright 2019 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.arcgisruntime.samples.deletefeaturesfeatureservice

import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment

class ConfirmDeleteFeatureDialog : DialogFragment() {

  private lateinit var featureId: String

  private val onButtonClickedListener = DialogInterface.OnClickListener { _, which ->
    if (context is OnButtonClickedListener) {
      if (which == DialogInterface.BUTTON_POSITIVE) {
        (context as OnButtonClickedListener).onDeleteFeatureClicked(featureId)
      } else {
        dismiss()
      }
    }
  }

  companion object {

    private val ARG_FEATURE_ID = ConfirmDeleteFeatureDialog::class.java.simpleName + "_feature_id"

    fun newInstance(featureId: String): ConfirmDeleteFeatureDialog {
      val fragment = ConfirmDeleteFeatureDialog()
      val args = Bundle()
      args.putString(ARG_FEATURE_ID, featureId)
      fragment.arguments = args
      return fragment
    }
  }

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    arguments?.let {
      it.getString(ARG_FEATURE_ID)?.let { featureId ->
        this.featureId = featureId
      }
    }
  }

  override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    return AlertDialog.Builder(context!!)
      .setMessage(getString(R.string.dialog_confirm_delete_message, featureId))
      .setPositiveButton(R.string.dialog_confirm_delete_positive, onButtonClickedListener)
      .setNegativeButton(R.string.dialog_confirm_delete_negative, onButtonClickedListener)
      .create()
  }

  interface OnButtonClickedListener {
    fun onDeleteFeatureClicked(featureId: String)
  }

}

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