Layers

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.

To learn more about how to host your data as services, visit Data hosting in the Mapping APIs and location services guide.

Workflow

The general workflow to work with the helper methods from the feature service package is to:

  1. Import your data from a CSV, XLS, GeoJSON, or Shapefile file to create a hosted feature layer. See Import data as a feature layer.
  2. Get the URL for the feature layer. See Access feature layer data.
  3. Make a request to the service.

Access feature layer data

To access feature layer data, you use the getService operation and the feature layer URL to access the metadata.

Example

Use dark colors for code blocksCopy
       
1
2
3
4
5
6
7
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);
})

To learn more, go to the Get layer metadata tutorial.

Query features

With the service URL from a published hosted feature layer, you can use the queryFeatures 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.

Use dark colors for code blocksCopy
          
1
2
3
4
5
6
7
8
9
10
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);
})

To learn more, go to the Query a feature layer (SQL) tutorial.

Edit features

You can add, update, and delete features from a feature layer using addFeatures, updateFeatures, and deleteFeatures.

Example

This example shows how to add features to a feature layer.

Use dark colors for code blocksCopy
         
1
2
3
4
5
6
7
8
9
import { addFeatures } from '@esri/arcgis-rest-feature-service';

addFeatures({
  url: featureServiceLayerUrl,
  features: [featureToAdd],
  authentication
}).then((results) => {
  console.log(results);
})

To learn more, go to the Edit feature data tutorial.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.