@ -1,3 +1,4 @@
var util = require ( 'util' ) ;
var isObject = require ( 'is-object' ) ;
var isObject = require ( 'is-object' ) ;
@ -46,26 +47,25 @@ function sanitize_bbox( clean, param ) {
return ;
return ;
}
}
var bbox = [ ] ;
var bboxArr = param . split ( ',' ) ;
var bboxArr = param . split ( ',' ) ;
if ( Array . isArray ( bboxArr ) && bboxArr . length === 4 ) {
if ( Array . isArray ( bboxArr ) && bboxArr . length === 4 ) {
bbox = bboxArr . filter ( function ( latlon , index ) {
var bbox = bboxArr . map ( function ( latlon ) {
latlon = parseFloat ( latlon , 10 ) ;
return parseFloat ( latlon , 10 ) ;
return ! ( lat _lon _checks [ ( index % 2 === 0 ? 'lon' : 'lat' ) ] . is _invalid ( latlon ) ) ;
} ) ;
bboxArr . forEach ( function ( latlon , index ) {
if ( index % 2 === 1 && check _lat . is _invalid ( latlon ) ) {
throw new Error ( 'Invalid lat: ' + latlon ) ;
}
} ) ;
} ) ;
if ( bbox . length === 4 ) {
clean . bbox = {
clean . bbox = {
right : Math . max ( bbox [ 0 ] , bbox [ 2 ] ) ,
right : Math . max ( bbox [ 0 ] , bbox [ 2 ] ) ,
top : Math . max ( bbox [ 1 ] , bbox [ 3 ] ) ,
top : Math . max ( bbox [ 1 ] , bbox [ 3 ] ) ,
left : Math . min ( bbox [ 0 ] , bbox [ 2 ] ) ,
left : Math . min ( bbox [ 0 ] , bbox [ 2 ] ) ,
bottom : Math . min ( bbox [ 1 ] , bbox [ 3 ] )
bottom : Math . min ( bbox [ 1 ] , bbox [ 3 ] )
} ;
} ;
} else {
throw new Error ( 'invalid bbox' ) ;
}
}
}
}
}
@ -80,13 +80,13 @@ function sanitize_bbox( clean, param ) {
function sanitize _coord ( coord , clean , param , latlon _is _required ) {
function sanitize _coord ( coord , clean , param , latlon _is _required ) {
var value = parseFloat ( param , 10 ) ;
var value = parseFloat ( param , 10 ) ;
if ( ! isNaN ( value ) ) {
if ( ! isNaN ( value ) ) {
if ( lat _lon _checks [ coord ] . is _invalid ( value ) ) {
if ( coord === 'lat' && check _lat . is _invalid ( value ) ) {
throw new Error ( 'invalid ' + lat _lon _checks [ coord ] . error _msg ) ;
throw new Error ( 'invalid ' + check _lat . error _msg ) ;
}
}
clean [ coord ] = value ;
clean [ coord ] = value ;
}
}
else if ( latlon _is _required ) {
else if ( latlon _is _required ) {
throw new Error ( 'missing ' + lat _lon _checks [ coord ] . error _msg ) ;
throw new Error ( util . format ( 'missing param \'%s\'' , coord ) ) ;
}
}
}
}
@ -97,18 +97,9 @@ function sanitize_zoom_level( clean, param ) {
}
}
}
}
var lat _lon _checks = {
var check _lat = {
lat : {
is _invalid : function is _invalid _lat ( lat ) {
is _invalid : function is _invalid _lat ( lat ) {
return isNaN ( lat ) || lat < - 90 || lat > 90 ;
return isNaN ( lat ) || lat < - 90 || lat > 90 ;
} ,
} ,
error _msg : 'param \'lat\': must be >-90 and <90'
error _msg : 'param \'lat\': must be >-90 and <90'
} ,
lon : {
is _invalid : function is _invalid _lon ( lon ) {
return isNaN ( lon ) || lon < - 180 || lon > 180 ;
} ,
error _msg : 'param \'lon\': must be >-180 and <180'
}
} ;
} ;