Skip to content

Commit

Permalink
dont convert extent objects with 'NaN' coordinate values to LatLngBou…
Browse files Browse the repository at this point in the history
…nds (#885)

* add test

* better to place the logic in extentToBounds

* try caching node dependencies on travis again

* throw an error when encountering null bounds
  • Loading branch information
jgravois authored Nov 15, 2016
1 parent 707238c commit ac69bea
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ before_script:
- npm prune
before_install:
- npm i -g npm@^3.0.0
cache:
directories: # Cache dependencies
- node_modules
27 changes: 27 additions & 0 deletions spec/Tasks/QuerySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ describe('L.esri.Query', function () {
}
};

// this is how ArcGIS Server returns a null extent (for now)
var sampleNaNExtentResponse = {
'extent': {
'xmin': 'NaN',
'ymin': 'NaN',
'xmax': 'NaN',
'ymax': 'NaN'
}
};

var sampleCountResponse = {
'count': 1
};
Expand Down Expand Up @@ -619,6 +629,23 @@ describe('L.esri.Query', function () {
server.respond();
});

it('should query nullified bounds', function (done) {
server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=1%3D2&outSr=4326&outFields=*&returnExtentOnly=true&f=json', JSON.stringify(sampleNaNExtentResponse));

task.where('1=2');
var request = task.bounds(function (error, latlngbounds, raw) {
expect(error.message).to.equal('Invalid Bounds');
expect(latlngbounds).to.deep.equal(null);
expect(raw).to.deep.equal(sampleNaNExtentResponse);
done();
});

expect(request).to.be.an.instanceof(XMLHttpRequest);

server.respond();
task.where('1=1');
});

it('should query count', function (done) {
server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&returnCountOnly=true&f=json', JSON.stringify(sampleCountResponse));

Expand Down
11 changes: 9 additions & 2 deletions src/Tasks/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ export var Query = Task.extend({
}, context);
},

// only valid for Feature Services running on ArcGIS Server 10.3 or ArcGIS Online
// only valid for Feature Services running on ArcGIS Server 10.3+ or ArcGIS Online
bounds: function (callback, context) {
this._cleanParams();
this.params.returnExtentOnly = true;
return this.request(function (error, response) {
callback.call(context, error, (response && response.extent && Util.extentToBounds(response.extent)), response);
if (response && response.extent && Util.extentToBounds(response.extent)) {
callback.call(context, error, Util.extentToBounds(response.extent), response);
} else {
error = {
message: 'Invalid Bounds'
};
callback.call(context, error, null, response);
}
}, context);
},

Expand Down
11 changes: 8 additions & 3 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export function shallowClone (obj) {

// convert an extent (ArcGIS) to LatLngBounds (Leaflet)
export function extentToBounds (extent) {
var sw = L.latLng(extent.ymin, extent.xmin);
var ne = L.latLng(extent.ymax, extent.xmax);
return L.latLngBounds(sw, ne);
// "NaN" coordinates from ArcGIS Server indicate a null geometry
if (extent.xmin !== 'NaN' && extent.ymin !== 'NaN' && extent.xmax !== 'NaN' && extent.ymax !== 'NaN') {
var sw = L.latLng(extent.ymin, extent.xmin);
var ne = L.latLng(extent.ymax, extent.xmax);
return L.latLngBounds(sw, ne);
} else {
return null;
}
}

// convert an LatLngBounds (Leaflet) to extent (ArcGIS)
Expand Down

0 comments on commit ac69bea

Please sign in to comment.