Skip to content

Commit

Permalink
Merge pull request Esri#510 from jgravois/delete-features
Browse files Browse the repository at this point in the history
added deleteFeatures methods
  • Loading branch information
patrickarlt committed Apr 28, 2015
2 parents 1b8c5b7 + 84b77b0 commit 5659958
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 10 deletions.
17 changes: 14 additions & 3 deletions site/source/pages/api-reference/layers/feature-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ featureLayer.query()
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Create</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires the <code>Create</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand All @@ -288,7 +288,7 @@ featureLayer.query()
Update the provided feature on the Feature Layer. This also updates the feature on the map.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand All @@ -299,7 +299,18 @@ featureLayer.query()
Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires the <code>Delete</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
<tr>
<td><code>deleteFeatures({{{param 'Array of String or Integers' 'ids'}}}, {{{param 'Function' 'callback'}}}, {{{param 'Object' 'context'}}})</code></td>
<td><code>this</code></td>
<td>
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.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Delete</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand Down
21 changes: 16 additions & 5 deletions site/source/pages/api-reference/services/feature-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Inherits from [`L.esri.Service`]({{assets}}api-reference/services/service.html)
Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Create</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires the <code>Create</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand All @@ -76,7 +76,7 @@ Inherits from [`L.esri.Service`]({{assets}}api-reference/services/service.html)
Update the provided feature on the Feature Layer. This also updates the feature on the map.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand All @@ -86,8 +86,19 @@ Inherits from [`L.esri.Service`]({{assets}}api-reference/services/service.html)
<td>
Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the srevice.</li>
<li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Delete</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
<tr>
<td><code>deleteFeatures({{{param 'Array of String or Integers' 'ids'}}}, {{{param 'Function' 'callback'}}}, {{{param 'Object' 'context'}}})</code></td>
<td><code>this</code></td>
<td>
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.
<ul>
<li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li>
<li>Requires the <code>Delete</code> capability be enabled on the service. You can check if this operation exists by checking the metadata of your service under capabilities.</li>
</ul>
</td>
</tr>
Expand All @@ -96,7 +107,7 @@ Inherits from [`L.esri.Service`]({{assets}}api-reference/services/service.html)

### Examples

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

##### Adding Features
```js
Expand Down
2 changes: 1 addition & 1 deletion spec/Layers/FeatureLayer/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('L.esri.Layers.FeatureLayer', function () {
layer.addLayers([1]);
});

it('should readd features back to a map', function(){
it('should read features back to a map', function(){
map.removeLayer(layer.getFeature(1));

layer.createLayers([{
Expand Down
24 changes: 24 additions & 0 deletions spec/Layers/FeatureLayer/FeatureManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,30 @@ describe('L.esri.Layers.FeatureManager', function () {
server.respond();
});

it('should wrap the removeFeatures method on the underlying service', function(done){
server.respondWith('POST', 'http://gis.example.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/deleteFeatures', JSON.stringify({
'deleteResults' : [{
'objectId' : 1,
'success' : true
},{
'objectId' : 2,
'success' : true
}]
}));

layer.deleteFeatures([1,2], function(error, response){
expect(layer.removeLayers).to.have.been.calledWith([1]);
expect(layer.removeLayers).to.have.been.calledWith([2]);
expect(response[1]).to.deep.equal({
'objectId': 2,
'success': true
});
done();
});

server.respond();
});

it('should support generalizing geometries', function(){
server.respondWith('GET', 'http://gis.example.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&inSr=4326&geometry=%7B%22xmin%22%3A-122.6953125%2C%22ymin%22%3A45.521743896993634%2C%22xmax%22%3A-122.6513671875%2C%22ymax%22%3A45.55252525134013%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&geometryPrecision=6&maxAllowableOffset=0.00004291534423829546&f=json', JSON.stringify({
fields: fields,
Expand Down
30 changes: 29 additions & 1 deletion spec/Services/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('L.esri.Services.FeatureLayer', function () {
}));
});

it('should be able to remove features from the layer', function(){
it('should be able to remove a feature from the layer', function(){
var callback = sinon.spy();

service.deleteFeature(1, callback);
Expand Down Expand Up @@ -163,4 +163,32 @@ describe('L.esri.Services.FeatureLayer', function () {
}]
}));
});

it('should be able to remove features from the layer', function(){
var callback = sinon.spy();

service.deleteFeatures([1,2], callback);

requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify({
'deleteResults' : [{
'objectId' : 1,
'success' : true
},{
'objectId' : 2,
'success' : true
}]
}));

var requestBody = window.decodeURIComponent(requests[0].requestBody);

expect(requestBody).to.equal('objectIds=1,2&f=json');

callback.should.have.been.calledWith(undefined, [{
'objectId' : 1,
'success' : true
},{
'objectId' : 2,
'success' : true
}]);
});
});
13 changes: 13 additions & 0 deletions src/Layers/FeatureLayer/FeatureManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@
callback.call(context, error, response);
}
}, this);
},

deleteFeatures: function(ids, callback, context){
return this._service.deleteFeatures(ids, function(error, response){
if(!error && response.length > 0){
for (var i=0; i<response.length; i++){
this.removeLayers([response[i].objectId], true);
}
}
if(callback){
callback.call(context, error, response);
}
}, this);
}

});
Expand Down
12 changes: 12 additions & 0 deletions src/Services/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ EsriLeaflet.Services.FeatureLayer = EsriLeaflet.Services.Service.extend({
callback.call(context, error || response.deleteResults[0].error, result);
}
}, context);
},

deleteFeatures: function(ids, callback, context) {
return this.post('deleteFeatures', {
objectIds: ids
}, function(error, response){
// pass back the entire array
var result = (response && response.deleteResults) ? response.deleteResults : undefined;
if(callback){
callback.call(context, error || response.deleteResults[0].error, result);
}
}, context);
}
});

Expand Down

0 comments on commit 5659958

Please sign in to comment.