L.esri.Services.FeatureLayer

Inherits from L.esri.Service

L.esri.Services.FeatureLayer is an abstraction for interacting with Feature Layers running on ArcGIS Online and ArcGIS Server that allows you to make requests to the API, as well as query, add, update and remove features from the service.

Constructor

Constructor Description
L.esri.Services.featureLayer(<Object> options) options for configuring the ArcGIS Server or ArcGIS Online feature layer you would like to consume. Options include a url parameter which refers to the ArcGIS Server or ArcGIS Online service you would like to consume.

Options

L.esri.Services.FeatureLayer accepts all L.esri.Services.Service options.

Events

L.esri.Services.FeatureLayer fires all L.esri.Services.service events.

Methods

Method Returns Description
query() this Returns a new L.esri.Tasks.Query object that can be used to query this layer.
featureLayer.query()
  .within(latlngbounds)
  .where("Direction = 'WEST'")
  .run(function(error, featureCollection, response){
    console.log(featureCollection);
  });
addFeature(<GeoJSON Feature> feature, <Function> callback, <Object> context) this Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
  • Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.
  • Requires the Create capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities.
updateFeature(<GeoJSON Feature> feature, <Function> callback, <Object> context) this Update the provided feature on the Feature Layer. This also updates the feature on the map.
  • Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.
  • Requires the Update capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.
deleteFeature(<String or Integer> id, <Function> callback, <Object> context) this Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
  • Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.
  • Requires the Delete capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.
deleteFeatures(<Array of String or Integers> ids, <Function> callback, <Object> context) this Removes an array of features with the provided ids from the feature layer. This will also remove the features from the map if they exist.
  • Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.
  • Requires the Delete capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.

Examples

Note: These examples use a public feature service on ArcGIS Online that does not require authentication.

Adding Features
var service = L.esri.Services.featureLayer({
    url: 'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Pubic_Feature_Service/FeatureServer/0'
});

var feature = {
    type: 'Feature',
    geometry: {
        type: 'Point',
        coordinates: [-122, 45]
    },
    properties: {
        name: 'Hello World'
    }
};

service.addFeature(feature, function(error, response){
    if(error){
      console.log('error creating feature' + error.message);
    } else {
      console.log('Successfully created feature with id ' + response.objectId);
    }
});
Updating Features
var service = L.esri.Services.featureLayer({
    url:'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Pubic_Feature_Service/FeatureServer/0'
});

var feature = {
    type: 'Feature',
    id: 2,
    geometry: {
        type: 'Point',
        coordinates: [-122, 45]
    },
    properties: {
        name: 'Hi I\'m Feature 2'
    }
};

service.updateFeature(feature, function(error, response){
    if(error){
      console.log('error updating feature' + error.message);
    } else {
      console.log('Successfully updated feature ' + feature.id);
    }
});
Deleting Features
var service = L.esri.Services.featureLayer({
    url: 'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Pubic_Feature_Service/FeatureServer/0'
});

service.deleteFeature(2, function(error, response){
    if(error){
      console.log('error deleting feature' + error.message);
    } else {
      console.log('Successfully deleted feature ' + response.objectId);
    }
});
Querying Features
var service = L.esri.Services.featureLayer({
    url: 'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Pubic_Feature_Service/FeatureServer/0'
});

service.query().where("name='Hello World'").run(function(error, featureCollection, response){
    console.log(featureCollection.features[0].properties.name);
});

Edit this page on GitHub