Learn how to add, update, and delete features
Click Edit feature or Add feature in the Editor component to edit a feature.
You can add, update, and delete featuresEditor component. This component allows you to edit both geometriestrue in the feature layer’s item page
In this tutorial, you will use the Editor component to add, update, and delete features
Prerequisites
Steps
Create a feature layer to edit
Before you start the tutorial, you need to create your own feature layer
- Go to the Create a new feature layer tutorial and follow the steps to create a new My Points feature layer.
- In your portal
ArcGIS portal, also known as a portal, is a website with applications and tools that can be used to create, manage, access, and share geospatial content and data. It supports security and authentication, developer credentials, content and data service management, user and group management, and site administration. A portal can be hosted in Esri's infrastructure or your own infrastructure. , clickContentto access your layers. - Click My Points to open the feature layer property page.
- In Overview, find the Layer Id
An item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. 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 access token
- Go to the Create an API key tutorial and create an API key
An API key is a long-lived access token created using API key credentials. They are valid for up to one year and are typically embedded directly into client applications. with the following privilege(s)Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. :
- 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
API key credentials are an item that contains the parameters used to create and manage long-lived access tokens for API key authentication. They are a type of developer credential. 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 API key credentials
- 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 features
- 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
ArcGIS Maps SDK for JavaScript, previously known as ArcGIS API for JavaScript, is a developer product for building mapping and spatial analysis applications for the web. 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 feature layerlayers 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 Points feature serviceA feature service is a data service that provides access to spatial and non-spatial data in feature layers, feature layer views, and tables. 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 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
A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. 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
A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. you created and update its attributeAttributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. 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
A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. 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 features
What’s next?
Learn how to use additional SDK features and ArcGIS services in these tutorials: