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( |
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.
|
addFeature( |
this |
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
|
updateFeature( |
this |
Update the provided feature on the Feature Layer. This also updates the feature on the map.
|
deleteFeature( |
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( |
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.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);
});
Esri Leaflet is a project from the Esri PDX R&D Center and the Esri Community