You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
// validate inputs, convert types and apply defaults
|
|
|
|
function sanitize( req ){
|
|
|
|
|
|
|
|
var clean = req.clean || {};
|
|
|
|
var params= req.query;
|
|
|
|
|
|
|
|
// ensure the input params are a valid object
|
|
|
|
if( Object.prototype.toString.call( params ) !== '[object Object]' ){
|
|
|
|
params = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// lat
|
|
|
|
var lat = parseFloat( params.lat, 10 );
|
|
|
|
if( isNaN( lat ) || lat < -90 || lat > 90 ){
|
|
|
|
return {
|
|
|
|
'error': true,
|
|
|
|
'message': 'invalid param \'lat\': must be >-90 and <90'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
clean.lat = lat;
|
|
|
|
|
|
|
|
// lon
|
|
|
|
var lon = parseFloat( params.lon, 10 );
|
|
|
|
if( isNaN( lon ) || lon < -180 || lon > 180 ){
|
|
|
|
return {
|
|
|
|
'error': true,
|
|
|
|
'message': 'invalid param \'lon\': must be >-180 and <180'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
clean.lon = lon;
|
|
|
|
|
|
|
|
// zoom level
|
|
|
|
var zoom = parseInt( params.zoom, 10 );
|
|
|
|
if( !isNaN( zoom ) ){
|
|
|
|
clean.zoom = Math.min( Math.max( zoom, 1 ), 18 ); // max
|
|
|
|
} else {
|
|
|
|
clean.zoom = 10; // default
|
|
|
|
}
|
|
|
|
|
|
|
|
req.clean = clean;
|
|
|
|
|
|
|
|
return { 'error': false };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// export function
|
|
|
|
module.exports = sanitize;
|