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.
44 lines
899 B
44 lines
899 B
9 years ago
|
/**
|
||
|
normalize co-ordinates that lie outside of the normal ranges.
|
||
9 years ago
|
|
||
|
longitude wrapping simply requires adding +- 360 to the value until it comes
|
||
|
in to range.
|
||
|
|
||
|
for the latitude values we need to flip the longitude whenever the latitude
|
||
|
crosses a pole.
|
||
9 years ago
|
**/
|
||
|
|
||
9 years ago
|
|
||
9 years ago
|
function wrap( lat, lon ){
|
||
|
|
||
|
var point = { lat: lat, lon: lon };
|
||
9 years ago
|
var quadrant = Math.floor( Math.abs(lat) / 90) % 4;
|
||
|
var pole = ( lat > 0 ) ? 90 : -90;
|
||
|
var offset = lat % 90;
|
||
|
|
||
|
switch( quadrant ){
|
||
|
case 0:
|
||
|
point.lat = offset;
|
||
|
break;
|
||
|
case 1:
|
||
|
point.lat = pole - offset;
|
||
|
point.lon += 180;
|
||
|
break;
|
||
|
case 2:
|
||
|
point.lat = -offset;
|
||
|
point.lon += 180;
|
||
|
break;
|
||
|
case 3:
|
||
|
point.lat = -pole + offset;
|
||
|
break;
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
if( point.lon > 180 || point.lon <= -180 ){
|
||
|
point.lon -= Math.floor(( point.lon + 180 ) / 360) * 360;
|
||
9 years ago
|
}
|
||
|
|
||
|
return point;
|
||
|
}
|
||
|
|
||
|
module.exports = wrap;
|