Browse Source

min/max lat/lon to form bbox from the input params

integration
Harish Krishna 10 years ago
parent
commit
51f25c2b01
  1. 21
      sanitiser/_geo.js
  2. 10
      test/unit/sanitiser/suggest.js

21
sanitiser/_geo.js

@ -45,23 +45,24 @@ function sanitize( req ){
clean.zoom = 10; // default
}
// bbox
// bbox
// bbox = bottom_left lat, bottom_left lon, top_right lat, top_right lon
// bbox = left,bottom,right,top
// bbox = min Longitude , min Latitude , max Longitude , max Latitude
if (params.bbox) {
var bbox = [];
var bboxArr = params.bbox.split(',');
if( Array.isArray(bboxArr) && bboxArr.length === 4 ){
bboxArr.forEach(function(latlon, index) {
if( Array.isArray(bboxArr) && bboxArr.length === 4 ) {
bbox = bboxArr.filter(function(latlon, index) {
latlon = parseFloat(latlon, 10);
if ( !(index % 2 === 0 ? is_invalid_lat(latlon) : is_invalid_lon(latlon)) ) {
bbox.push(latlon);
}
return !(index % 2 === 0 ? is_invalid_lat(latlon) : is_invalid_lon(latlon));
});
if (bbox.length === 4) {
clean.bbox = {
top : bbox[0],
right : bbox[1],
bottom: bbox[2],
left : bbox[3]
top : Math.max(bbox[0], bbox[2]),
right : Math.max(bbox[1], bbox[3]),
bottom: Math.min(bbox[0], bbox[2]),
left : Math.min(bbox[1], bbox[3])
};
} else {
return {

10
test/unit/sanitiser/suggest.js

@ -143,7 +143,7 @@ module.exports.tests.sanitize_bbox = function(test, common) {
sanitize({ input: 'test', lat: 0, lon: 0, bbox: bbox }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean ));
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly');
t.deepEqual(clean, expected, 'falling back on 50km distance from centroid');
});
});
t.end();
@ -156,10 +156,10 @@ module.exports.tests.sanitize_bbox = function(test, common) {
return parseInt(i);
});
expected.bbox = {
top : bboxArray[0],
right : bboxArray[1],
bottom: bboxArray[2],
left : bboxArray[3]
top : Math.max(bboxArray[0], bboxArray[2]),
right : Math.max(bboxArray[1], bboxArray[3]),
bottom: Math.min(bboxArray[0], bboxArray[2]),
left : Math.min(bboxArray[1], bboxArray[3])
};
t.equal(err, undefined, 'no error');
t.deepEqual(clean, expected, 'clean set correctly (' + bbox + ')');

Loading…
Cancel
Save