This content has moved to developers.arcgis.com. Please update your bookmarks!
L.esri.FeatureLayerService
Extends L.esri.Service
L.esri.FeatureLayerService
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.featureLayerService(<Object> |
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.FeatureLayerService
accepts all L.esri.Service
options.
Events
L.esri.FeatureLayerService
fires all L.esri.service
events.
Methods
Method | Returns | Description |
---|---|---|
query() |
this |
Returns a new L.esri.Query object that can be used to query this layer.
|
addFeature(<GeoJSON Feature> |
this |
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
|
updateFeature(<GeoJSON Feature> |
this |
Update the provided feature on the Feature Layer. This also updates the feature on the map.
|
deleteFeature(<String or Integer> |
this |
Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
|
deleteFeatures(<Array of String or Integers> |
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.
|
Examples
Note: These examples use a public feature service on ArcGIS Online that does not require authentication.
Adding Features
var service = L.esri.featureLayerService({
url: 'https://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.featureLayerService({
url: 'https://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.featureLayerService({
url: 'https://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.featureLayerService({
url: 'https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Pubic_Feature_Service/FeatureServer/0'
});
service.query().where("name='Hello World'").run(function (error, featureCollection, response) {
if (error) {
console.log(error);
return;
}
console.log(featureCollection.features[0].properties.name);
});