L.esri.Services.FeatureLayer

Inherits from L.esri.Service

L.esri.Services.FeatureLayer is an abstraction 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
new L.esri.Services.FeatureLayer(<String> url, <Object> options)

L.esri.Services.featureLayer(<String> url, <Object> options)
The url parameter is the URL to the ArcGIS Server or ArcGIS Online feature layer 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);
            });
createFeature(<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 in the metadata.
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 creation exists by checking the metadata of your service under capabilities in the metadata.
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 srevice.
  • Requires the Update capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.

Examples

Note: These examples use a public feature service on ArcGIS Online that required no authentication.

Adding Features
var service = L.esri.Services.featureLayer('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('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('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 Feautres
var service = L.esri.Services.featureLayer('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