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.
45 lines
900 B
45 lines
900 B
8 years ago
|
|
||
|
/**
|
||
|
normalize co-ordinates that lie outside of the normal ranges.
|
||
8 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.
|
||
8 years ago
|
**/
|
||
|
|
||
8 years ago
|
|
||
8 years ago
|
function wrap( lat, lon ){
|
||
|
|
||
|
var point = { lat: lat, lon: lon };
|
||
8 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;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
if( point.lon > 180 || point.lon <= -180 ){
|
||
|
point.lon -= Math.floor(( point.lon + 180 ) / 360) * 360;
|
||
8 years ago
|
}
|
||
|
|
||
|
return point;
|
||
|
}
|
||
|
|
||
|
module.exports = wrap;
|