Extends L.esri.
L.esri.
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) | 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.
accepts all L.esri.
options.
Events
L.esri.
fires all L.esri.service
events.
Methods
Method | Returns | Description |
---|---|---|
query() | this | Returns a new
|
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.
|
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.
|
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.
|
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.
|
Examples
Adding Features
var service = L.esri.featureLayerService({
url: 'https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/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://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/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://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/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);
});