Learn how to add features
Features are a type of geographic data that contain a geometry
This tutorial explains how to get features from a feature service with ArcGIS REST JS, then display them in your CesiumJS application as a Geo. The tutorial uses three different feature layers, containing pointsx,y coordinates and a spatial reference.
The three layers you will use are:
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. and secure itemsAn 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. . - Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. and access resources their behalf. - Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Get a Cesium ion access token
All Cesium applications must use an access token provided through Cesium ion. This token allows you to access assets such as Cesium World Terrain in your application.
-
Go to your Cesium ion dashboard to generate an access token. Copy the key to your clipboard.
-
Create a
cesiumvariable and replaceAccess Token YOURwith the access token you copied from the Cesium ion dashboard._CESIUM _ACCESS _TOKEN Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URI", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; Cesium.ArcGisMapService.defaultAccessToken = accessToken; const cesiumAccessToken = "YOUR_CESIUM_ACCESS_TOKEN"; </script> -
Configure
Cesium.with the Cesium access token to validate the application.Ion.default Access Token Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URI", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; Cesium.ArcGisMapService.defaultAccessToken = accessToken; const cesiumAccessToken = "YOUR_CESIUM_ACCESS_TOKEN"; Cesium.Ion.defaultAccessToken = cesiumAccessToken; </script>
Add references to ArcGIS REST JS
-
In the
<headelement, reference the> feature-serviceandrequestpackages from ArcGIS REST JS.Use dark colors for code blocks <script src="https://cesium.com/downloads/cesiumjs/releases/1.140/Build/Cesium/Cesium.js"></script> <link href="https://cesium.com/downloads/cesiumjs/releases/1.140/Build/Cesium/Widgets/widgets.css" rel="stylesheet"> <script src="https://unpkg.com/@esri/arcgis-rest-request@4/dist/bundled/request.umd.js"></script> <script src="https://unpkg.com/@esri/arcgis-rest-feature-service@4/dist/bundled/feature-service.umd.js"></script> -
In the
<body, create an> arcgisusing your access token to authenticate requests to the feature serviceRest. Api Key Manager A feature service is a data service that provides access to spatial and non-spatial data in feature layers, feature layer views, and tables. .Use dark colors for code blocks /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URI", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; Cesium.ArcGisMapService.defaultAccessToken = accessToken; const authentication = arcgisRest.ApiKeyManager.fromKey(accessToken);
Add point features
Pointx,y coordinates and a spatial reference.arcgis to query the Trailheads feature service and add features to the scene as GeoJSON.
-
Go to the Trailheads URL and browse the properties of the layer. Make note of the layer's Name, Type, and Fields.
-
In CodePen, define a variable to store the URL of the feature service.
Use dark colors for code blocks const pointLayerName = "Trailheads"; const pointLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + pointLayerName + "/FeatureServer/0"; -
Call the
arcgisoperation to make an authenticated request to the Trailheads feature service. Set theRest.query Features fproperty togeojsonto format the response as GeoJSON.Use dark colors for code blocks const pointLayerName = "Trailheads"; const pointLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + pointLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: pointLayerURL, authentication, f: "geojson" }).then((response) => { }); -
Add the service response service to the scene as a
Geo. Set theJson Data Source clampproperty to clamp the features to terrain.To Ground Use dark colors for code blocks const pointLayerName = "Trailheads"; const pointLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + pointLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: pointLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, }); viewer.dataSources.add(data); }); -
Add the data attribution
Data attribution is the requirement to display the names of data source providers in all applications when accessing ArcGIS content, layers, or services. for the feature layer source.- Go to the Trailheads (Santa Monica Mountains) item
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. . - Scroll down to the Acknowledgments section and copy its value.
- Paste the copied value to the
creditproperty.Use dark colors for code blocks const pointLayerName = "Trailheads"; const pointLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + pointLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: pointLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, // Attribution text retrieved from https://arcgis.com/home/item.html?id=883cedb8c9fe4524b64d47666ed234a7 credit: new Cesium.Credit("Los Angeles GeoHub", false) }); viewer.dataSources.add(data); });
- Go to the Trailheads (Santa Monica Mountains) item
Add polyline features
Linex,y coordinates and a spatial reference.arcgis to query the Trails feature service and add features to the scene as GeoJSON.
-
Go to the Trails URL and browse the properties of the layer. Make note of the layer's Name, Type, and Fields.
-
In CodePen, define a variable to store the URL of the feature service.
Use dark colors for code blocks const lineLayerName = "Trails"; const lineLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + lineLayerName + "/FeatureServer/0"; -
Call the
arcgisoperation to make an authenticated request to the Trails feature service. Set theRest.query Features fproperty togeojsonto format the response as GeoJSON.Use dark colors for code blocks const lineLayerName = "Trails"; const lineLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + lineLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: lineLayerURL, authentication, f: "geojson" }).then((response) => { }); -
Add the service response service to your scene as a
Geo. Set theJson Data Source clampproperty to clamp the features to terrain.To Ground Use dark colors for code blocks const lineLayerName = "Trails"; const lineLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + lineLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: lineLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, }); viewer.dataSources.add(data); }); -
Add the data attribution
Data attribution is the requirement to display the names of data source providers in all applications when accessing ArcGIS content, layers, or services. for the feature layer source.- Go to the Trails item
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. . - Scroll down to the Acknowledgments section and copy its value.
- Paste the copied value to the
creditproperty.Use dark colors for code blocks const lineLayerName = "Trails"; const lineLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + lineLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: lineLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, // Attribution text retrieved from https://arcgis.com/home/item.html?id=69e12682738e467eb509d8b54dc73cbd credit: "Los Angeles GeoHub" }); viewer.dataSources.add(data); });
- Go to the Trails item
Add polygon features
Polygonx,y coordinates and a spatial reference.arcgis to query the Parks and Open Spaces feature service and add features to the scene as GeoJSON.
-
Go to the Parks and Open Spaces URL and browse the properties of the layer. Make note of the layer's Name, Type, and Fields.
-
In CodePen, define a variable to store the URL of the feature service.
Use dark colors for code blocks const polygonLayerName = "Parks_and_Open_Space"; const polygonLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + polygonLayerName + "/FeatureServer/0"; -
Call the
arcgisoperation to make an authenticated request to the Parks and Open Spaces feature service. Set theRest.query Features fproperty togeojsonto format the response as GeoJSON.Use dark colors for code blocks const polygonLayerName = "Parks_and_Open_Space"; const polygonLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + polygonLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: polygonLayerURL, authentication, f: "geojson" }).then((response) => { }); -
Add the service response service to your scene as a
Geo. Set theJson Data Source clampproperty to clamp the features to terrain.To Ground Use dark colors for code blocks const polygonLayerName = "Parks_and_Open_Space"; const polygonLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + polygonLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: polygonLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, }); viewer.dataSources.add(data); }); -
Add the data attribution
Data attribution is the requirement to display the names of data source providers in all applications when accessing ArcGIS content, layers, or services. for the feature layer source.- Go to the Parks and Open Space item
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. . - Scroll down to the Acknowledgments section and copy its value.
- Paste the copied value to the
creditproperty.Use dark colors for code blocks const polygonLayerName = "Parks_and_Open_Space"; const polygonLayerURL = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/" + polygonLayerName + "/FeatureServer/0"; arcgisRest.queryFeatures({ url: polygonLayerURL, authentication, f: "geojson" }).then((response) => { const data = Cesium.GeoJsonDataSource.load(response, { clampToGround: true, // Attribution text retrieved from https://arcgis.com/home/item.html?id=f2ea5d874dad427294641d2d45097c0e credit: "Los Angeles GeoHub" }); viewer.dataSources.add(data); });
- Go to the Parks and Open Space item
Run the app
Run the app.
Your map should display the locations of trailheads, trails, and open spaces in the Santa Monica Mountains.What's next?
Learn how to use additional location services in these tutorials:

Style features
Use data-driven styling to apply symbol colors and styles to features.

Display a pop-up (Feature)
Display feature attributes in a popup.

Query features (SQL)
Execute a SQL query to access polygon features from a feature service.

Query features (spatial)
Execute a spatial query to access polygon features from a feature service.