You can import and publish data using data management tools to create hosted layers and services in ArcGIS. Once created, you can access the layers and services using the feature service package from ArcGIS REST JS to return metadata, make queries, edit features, and perform other operations.
Workflow
The general workflow to work with the helper methods from the feature service package is to:
- Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer. See Import data as a feature layer.
- Get the URL for the feature layer. See Access feature layer data.
- Make a request to the service.
Access feature layer data
To access feature layer data, you use the get
operation and the feature layer URL to access the metadata.
Example
import { getService } from '@esri/arcgis-rest-feature-service';
getService("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_Styled/FeatureServer/0", {
authentication
}).then((metadata) => {
console.log(metadata);
})
Query features
With the service URL from a published hosted feature layer, you can use the query
function to perform either SQL or spatial queries against the feature service.
Example
This example demonstrates how to perform a SQL query against a feature service.
import { queryFeatures } from '@esri/arcgis-rest-feature-service';
queryFeatures({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0",
where: "UseType = 'Residential'",
resultRecordCount: 1,
authentication
}).then((results) => {
console.log(results);
})
Edit features
You can add, update, and delete features from a feature layer using add
, update
, and delete
.
Example
This example shows how to add features to a feature layer.
import { addFeatures } from '@esri/arcgis-rest-feature-service';
addFeatures({
url: featureServiceLayerUrl,
features: [featureToAdd],
authentication
}).then((results) => {
console.log(results);
})
Tutorials
Get layer metadata
Access the name, description, type and other properties of a hosted layer.
Query a feature layer (SQL)
Access and query a hosted feature layer with a SQL where clause.
Query a feature layer (spatial)
Access and query a hosted feature layer with a geometry and spatial operator.
Edit feature data
Add, update, and delete data in a hosted feature layer.