Skip to content

Commit

Permalink
Fix issues #283, #284 and #285
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickarlt committed Jul 19, 2014
1 parent 919fa14 commit d0dc744
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 21 deletions.
22 changes: 11 additions & 11 deletions spec/Layers/FeatureLayer/FeatureManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should create features based on the current view of the map', function(){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [feature1, feature2],
objectIdFieldName: 'OBJECTID'
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should fire a drawlimitexceeded event when there are more features then can be requested', function(done){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [],
objectIdFieldName: 'OBJECTID',
Expand All @@ -256,7 +256,7 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should filter existing features with a single time field', function(){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [feature2, feature3],
objectIdFieldName: 'OBJECTID'
Expand All @@ -278,7 +278,7 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should load more features with a single time field', function(){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&time=1385884800000%2C1389340800000&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&time=1385884800000%2C1389340800000&f=json', JSON.stringify({
fields: fields,
features: [feature1],
objectIdFieldName: 'OBJECTID'
Expand All @@ -305,7 +305,7 @@ describe('L.esri.Layers.FeatureManager', function () {
'id': 1
}]);

server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&time=1389686400000%2C1389859200000&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&time=1389686400000%2C1389859200000&f=json', JSON.stringify({
fields: fields,
features: [feature2],
objectIdFieldName: 'OBJECTID'
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('L.esri.Layers.FeatureManager', function () {
}
});

server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [feature4, feature5],
objectIdFieldName: 'OBJECTID'
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('L.esri.Layers.FeatureManager', function () {
}
});

server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&time=1389254400000%2C1389513600000&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&time=1389254400000%2C1389513600000&f=json', JSON.stringify({
fields: fields,
features: [feature4],
objectIdFieldName: 'OBJECTID'
Expand All @@ -397,7 +397,7 @@ describe('L.esri.Layers.FeatureManager', function () {
'type': 'Feature'
}]);

server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&time=1389600000000%2C1389859200000&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&time=1389600000000%2C1389859200000&f=json', JSON.stringify({
fields: fields,
features: [feature5],
objectIdFieldName: 'OBJECTID'
Expand Down Expand Up @@ -427,13 +427,13 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should filter features with a where parameter', function(){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=Type%3D\'Active\'&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=Type%3D\'Active\'&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [feature1],
objectIdFieldName: 'OBJECTID'
}));

server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=Type%3D\'Inactive\'&outSr=4326&outFields=*&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&f=json', JSON.stringify({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=Type%3D\'Inactive\'&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&f=json', JSON.stringify({
fields: fields,
features: [feature2],
objectIdFieldName: 'OBJECTID'
Expand Down Expand Up @@ -695,7 +695,7 @@ describe('L.esri.Layers.FeatureManager', function () {
});

it('should support generalizing geometries', function(){
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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({
server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?where=1%3D1&outSr=4326&outFields=*&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&inSr=4326&geometryPrecision=6&maxAllowableOffset=0.00004291534423829546&f=json', JSON.stringify({
fields: fields,
features: [feature6],
objectIdFieldName: 'OBJECTID',
Expand Down
60 changes: 60 additions & 0 deletions spec/Services/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ describe('L.esri.Services.FeatureLayer', function () {
});
});

it('should be able to add a feature to the layer without a callback', function(){
expect(function(){
service.addFeature({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [45, -121]
},
properties: {
foo: 'bar'
}
});
}).to.not.throw(Error);

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

});

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

Expand Down Expand Up @@ -82,6 +105,30 @@ describe('L.esri.Services.FeatureLayer', function () {
});
});

it('should be able to update a feature on the layer without a callback', function(){

expect(function(){
service.updateFeature({
type: 'Feature',
id: 1,
geometry: {
type: 'Point',
coordinates: [45, -121]
},
properties: {
foo: 'bar'
}
});
}).to.not.throw(Error);

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

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

Expand All @@ -103,4 +150,17 @@ describe('L.esri.Services.FeatureLayer', function () {
'success' : true
});
});

it('should be able to remove features from the layer without a callback', function(){
expect(function(){
service.deleteFeature(1);
}).to.not.throw(Error);

requests[0].respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify({
'deleteResults' : [{
'objectId' : 1,
'success' : true
}]
}));
});
});
2 changes: 1 addition & 1 deletion spec/Tasks/QuerySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('L.esri.Tasks.Query', function () {
});

it('should query features within bounds', function(done){
server.respondWith('GET', url + 'query?where=1%3D1&outSr=4326&outFields=*&geometry=%7B%22xmin%22%3A-122.66%2C%22ymin%22%3A45.5%2C%22xmax%22%3A-122.65%2C%22ymax%22%3A45.51%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&f=json', JSON.stringify(sampleQueryResponse));
server.respondWith('GET', url + 'query?where=1%3D1&outSr=4326&outFields=*&geometry=%7B%22xmin%22%3A-122.66%2C%22ymin%22%3A45.5%2C%22xmax%22%3A-122.65%2C%22ymax%22%3A45.51%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&inSr=4326&f=json', JSON.stringify(sampleQueryResponse));

task.within(bounds).run(function(error, featureCollection, raw){
expect(featureCollection).to.deep.equal(sampleFeatureCollection);
Expand Down
27 changes: 21 additions & 6 deletions src/Layers/FeatureLayer/FeatureManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,38 @@

addFeature: function(feature, callback, context){
this._service.addFeature(feature, function(error, response){
this.refresh();
callback.call(context, error, response);
if(!error){
this.refresh();
}
if(callback){
callback.call(context, error, response);
}
}, this);
return this;
},

updateFeature: function(feature, callback, context){
return this._service.updateFeature(feature, function(error, response){
this.refresh();
callback.call(context, error, response);
if(!error){
this.refresh();
}
if(callback){
callback.call(context, error, response);
}
}, this);
},

deleteFeature: function(id, callback, context){
return this._service.deleteFeature(id, function(error, response){
this.removeLayers([response.objectId]);
callback.call(context, error, response);
if(!error && response.objectId){
this.removeLayers([response.objectId]);
if(this._layers){
delete this._layers[id];
}
}
if(callback){
callback.call(context, error, response);
}
}, this);
}
});
Expand Down
15 changes: 12 additions & 3 deletions src/Services/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ L.esri.Services.FeatureLayer = L.esri.Services.Service.extend({
return this.post('addFeatures', {
features: [feature]
}, function(error, response){
callback.call(this, error || response.addResults[0].error, response.addResults[0]);
var result = (response && response.addResults) ? response.addResults[0] : undefined;
if(callback){
callback.call(this, error || response.addResults[0].error, result);
}
}, context);
},

Expand All @@ -25,15 +28,21 @@ L.esri.Services.FeatureLayer = L.esri.Services.Service.extend({
return this.post('updateFeatures', {
features: [feature]
}, function(error, response){
callback.call(context, error || response.updateResults[0].error, response.updateResults[0]);
var result = (response && response.updateResults) ? response.updateResults[0] : undefined;
if(callback){
callback.call(context, error || response.updateResults[0].error, result);
}
}, context);
},

deleteFeature: function(id, callback, context) {
return this.post('deleteFeatures', {
objectIds: id
}, function(error, response){
callback.call(context, error || response.deleteResults[0].error, response.deleteResults[0]);
var result = (response && response.deleteResults) ? response.deleteResults[0] : undefined;
if(callback){
callback.call(context, error || response.deleteResults[0].error, result);
}
}, context);
}

Expand Down
1 change: 1 addition & 0 deletions src/Tasks/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ L.esri.Tasks.Query = L.Class.extend({
this._params.geometry = L.esri.Util.boundsToExtent(bounds);
this._params.geometryType = 'esriGeometryEnvelope';
this._params.spatialRel = 'esriSpatialRelIntersects';
this._params.inSr = 4326;
return this;
},

Expand Down

0 comments on commit d0dc744

Please sign in to comment.