Skip to content

Instantly share code, notes, and snippets.

@raphaelsaunier
Created January 21, 2010 19:41
Show Gist options
  • Save raphaelsaunier/283124 to your computer and use it in GitHub Desktop.
Save raphaelsaunier/283124 to your computer and use it in GitHub Desktop.
var coordsToAngle = function(c){
if(typeof c == Array && c.length==3)
var deg = c[0], min = c[1], sec = c[2];
else {
var deg = c.match(/([\-]?[\d]{1,3})\°/), deg = (deg === null ? 0 : deg[1].toInt());
var min = c.match(/([\-]?[\d]{1,3})\'{1}/), min = (min === null ? 0 : min[1].toInt());
var sec = c.match(/([\-]?[\d]{1,3})\'{2}/), sec = (sec === null ? 0 : sec[1].toInt());
}
c = deg + min/60 + sec/3600;
return c;
}
var degToRadians = function(angle){
var angle = angle*Math.PI/180;
return angle;
}
var placePointOnMap = function(lon,lat,map_width,map_height){
if(arguments.length==2) var map_width = 1, map_height = 1;
function MillerCylindricalProjection(phi){
phi = (5/4)*Math.log(Math.tan((0.25*Math.PI+0.4*phi)))
return phi
}
var lon = degToRadians(coordsToAngle(lon)),
lat = degToRadians(coordsToAngle(lat)),
max_x = Math.PI;
max_y = MillerCylindricalProjection(-Math.PI/2),
pos = new Object;
pos.x = (lon+max_x)/(2*max_x)*map_width;
pos.y = (MillerCylindricalProjection(lat)+max_y)/(2*max_y)*map_height;
return pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment