Learn how to add, update, and delete
Click Edit feature or Add feature in the Editor component to edit a feature.
You can add, update, and delete Editor component. This component allows you to edit both true in the feature layer’s
In this tutorial, you will use the Editor component to add, update, and delete
Prerequisites
Steps
Create a feature layer to edit
Before you start the tutorial, you need to create your own
- Go to the Create a new feature layer tutorial and follow the steps to create a new My Points feature layer.
- In your
portal , clickContentto access your layers. - Click My Points to open the feature layer property page.
- In Overview, find the
Layer Id and Service URL. For example:- Layer Id: 70264c2e37784a819e235d3a0129832f
- Service URL:
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer
Create a new pen
- To get started, either complete the Display a map tutorial or
.
Get an access token
You need an
- Go to the Create an API key tutorial and create an
API key with the followingprivilege(s) :
- Privileges
- Location services > Basemaps
- Item access
- Note: If you are using your own custom data layer for this tutorial, you need to grant the
API key credentials access to the layer item. Learn more in Item access privileges.
- Note: If you are using your own custom data layer for this tutorial, you need to grant the
- Privileges
- In CodePen, set the
apiKeyproperty on the globalesriConfigvariable to your access token.var esriConfig = {apiKey: "YOUR_ACCESS_TOKEN",};
To learn about other ways to get an access token, go to Types of authentication.
Display a map
- Follow the steps in the Display a map tutorial to add a map with the
arcgis/topographicbasemap layer, centered on Point Dume State Beach, Malibu, California.
Add the Editor component
The Editor component gives you the ability to add, update, and delete
- Create the Editor component inside the
arcgis-mapelement and place the component in the top-right corner of the map.
27 collapsed lines
<html>
<head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>ArcGIS Maps SDK for JavaScript Tutorials: Edit feature data</title>
<script> var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" }; </script>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.0/"></script>
<style> html, body { height: 100%; margin: 0; } </style>
</head>
<body>
<arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13">
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-editor slot="top-right"></arcgis-editor>
</arcgis-map>5 collapsed lines
</body>
</html>Add script and modules
-
In a new
<script>at the bottom of the<body>, use$arcgis.import()to add theFeatureLayermodule.The
ArcGIS Maps SDK for JavaScript is available via CDN and npm, but this tutorial is based on CDN. The$arcgis.importglobal 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.36 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Edit feature data</title><script>var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><arcgis-editor slot="top-right"></arcgis-editor></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");</script>4 collapsed lines</body></html>
Add a feature layer
Use the FeatureLayer class to access your My Points layers property.
- Use
document.querySelector()to get a reference to the Map component, then wait for it to be ready with the viewOnReady method. Next, create amyPointsFeatureLayerand set its url property to the My Pointsfeature service you created earlier.36 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Edit feature data</title><script>var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><arcgis-editor slot="top-right"></arcgis-editor></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// Add feature layer (points)const myPointsFeatureLayer = new FeatureLayer({url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer/0",});</script>4 collapsed lines</body></html> - Add
addMyPointslayer to the map.36 collapsed lines<html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><title>ArcGIS Maps SDK for JavaScript Tutorials: Edit feature data</title><script>var esriConfig = { apiKey: "YOUR_ACCESS_TOKEN" };</script><!-- Load the ArcGIS Maps SDK for JavaScript from CDN --><script type="module" src="https://js.arcgis.com/5.0/"></script><style>html,body {height: 100%;margin: 0;}</style></head><body><arcgis-map basemap="arcgis/topographic" center="-118.805, 34.020" zoom="13"><arcgis-zoom slot="top-left"></arcgis-zoom><arcgis-editor slot="top-right"></arcgis-editor></arcgis-map><script type="module">const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");const viewElement = document.querySelector("arcgis-map");await viewElement.viewOnReady();// 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>4 collapsed lines</body></html>
Edit features
Use the Editor component to add, update, and delete a
-
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:- id:
100 - name:
My Point - rating:
Good
Click Add to add the feature to the
map. Click < to return to the main window. - id:
-
In the Editor, click Edit feature. Click on the
feature you created and update itsattribute values.- id:
101 - name:
Awesome Beach - rating:
Excellent
Click Update to update the feature in the
map. Click < to return to the main window. - id:
-
In the Editor, click Edit feature. Click on the
feature you edited and then click Delete.
Run the app
In CodePen, run your code to display the map.
You should now have the ability to add, update, and delete
What’s next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: