Learn how to add, update, and delete features in a feature service.
You can add, update, and delete features in a feature layer with the Editor
component. This component allows you to edit both geometries and attributes. To use the component, you need to ensure that you have the correct credentials to access and edit the feature layer, and that the Enable Editing property is set to true
in the feature layer's item page. You can verify credentials and settings on the item property page in your ArcGIS account.
In this tutorial, you will use the Editor
component to add, update, and delete features in the My Points feature layer you had created in the Create a new feature layer tutorial.
To learn more about editing feature data, visit Data management in the Mapping and location services guide. To learn more about services, visit Feature service.
Prerequisites ArcGIS Accounts:You need an ArcGIS Location Platform or ArcGIS Online account.
Steps Create a feature layer to editBefore you start the tutorial, you need to create your own feature layer hosted in ArcGIS called My Points.
Content
to access your layers.https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer
All Layer IDs and service URLs are unique. To access the feature layer directly, you reference the layer with its url and index. In this case, the index is 0. For example: https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer/0
Create a new penYou need an access token with the correct privileges to access the location services used in this tutorial.
esriConfig.apiKey
to your access token.
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
var esriConfig = {
apiKey: "YOUR_ACCESS_TOKEN",
};
To learn about other ways to get an access token, go to Types of authentication.
Display a maparcgis/topographic
basemap layer, centered on Point Dume State Beach, Malibu, California.The Editor
component gives you the ability to add, update, and delete features interactively. The component will check the map for all editable layers and make them available automatically.
arcgis-map
element and place the component in the top-right corner of the map.Expand
Use dark colors for code blocks1
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
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.027" zoom="13">
<arcgis-zoom position="top-left"></arcgis-zoom>
<arcgis-editor position="top-right"></arcgis-editor>
</arcgis-map>
Add script and modules
In a new <script>
at the bottom of the <body>
, use $arcgis.import()
to add the FeatureLayer
module.
The ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The $arcgis.import
global function accepts a module path or array of module paths, and returns a promise that resolves with the requested modules. This function can only be used when working with the CDN; otherwise, use the standard import syntax. To learn more about the SDK's different modules, visit the References page.
Expand
Use dark colors for code blocks1
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
<script type="module">
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
</script>
Use the FeatureLayer
class to access your My Points feature layer. The feature layer will be added to the map with the layers
property.
myPointsFeatureLayer
and set its url
property to access the My Points feature service created earlier. When using the arcgis-map component, you need to add an event listener for arcgisViewReadyChange
to wait until the component is ready before adding the layer.
Expand
Use dark colors for code blocks1
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
<script type="module">
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
const viewElement = document.querySelector("arcgis-map");
viewElement.addEventListener("arcgisViewReadyChange", () => {
// Add feature layer (points)
const myPointsFeatureLayer = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer/0",
});
});
</script>
addMyPoints
layer to the map.
Expand
Use dark colors for code blocks1
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
<script type="module">
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
const viewElement = document.querySelector("arcgis-map");
viewElement.addEventListener("arcgisViewReadyChange", () => {
// Add feature layer (points)
const myPointsFeatureLayer = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer/0",
});
viewElement.map.add(myPointsFeatureLayer);
});
</script>
Use the Editor
component to add, update, and delete a feature.
If the application is not running, at the top-right click Run.
In the Editor, click Add feature. Click on the map to create a new feature with the following properties:
100
My Point
Good
Click Add to add the feature to the map
. Click < to return to the main window.
In the Editor, click Edit feature. Click on the feature you created and update its attribute values.
101
Awesome Beach
Excellent
Click Update to update the feature in the map
. Click < to return to the main window.
In the Editor, click Edit feature. Click on the feature you edited and then click Delete.
In CodePen, run your code to display the map.
You should now have the ability to add, update, and delete features from your My Points feature layer.
What's next?Learn how to use additional API features and ArcGIS services in these tutorials:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4