mirror of https://github.com/pelias/api.git
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.
37 lines
563 B
37 lines
563 B
8 years ago
|
|
||
|
/**
|
||
|
normalize co-ordinates that lie outside of the normal ranges.
|
||
|
**/
|
||
|
|
||
|
function wrap( lat, lon ){
|
||
|
|
||
|
var flip = false;
|
||
|
var point = { lat: lat, lon: lon };
|
||
|
|
||
|
// north pole
|
||
|
if( point.lat > 90 ){
|
||
|
point.lat = 90 - point.lat % 90;
|
||
|
point.lon += 180;
|
||
|
}
|
||
|
|
||
|
// south pole
|
||
|
else if( point.lat < -90 ){
|
||
|
point.lat = -90 - point.lat % 90;
|
||
|
point.lon += 180;
|
||
|
}
|
||
|
|
||
|
// reduce lon
|
||
|
while( point.lon > 180 ){
|
||
|
point.lon -= 360;
|
||
|
}
|
||
|
|
||
|
// increase lon
|
||
|
while( point.lon < -180 ){
|
||
|
point.lon += 360;
|
||
|
}
|
||
|
|
||
|
return point;
|
||
|
}
|
||
|
|
||
|
module.exports = wrap;
|