Skip to content

Instantly share code, notes, and snippets.

@javisantana
Created July 4, 2017 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save javisantana/06d6c42a33ddac56b6ae8acd458a7e76 to your computer and use it in GitHub Desktop.
Save javisantana/06d6c42a33ddac56b6ae8acd458a7e76 to your computer and use it in GitHub Desktop.
// license: BSD3
const WEBMERCATOR_R = 6378137.0;
const DIAMETER = WEBMERCATOR_R * 2 * Math.PI;
class Mercator {
static project(lon, lat) {
var x = DIAMETER * lon/360.0;
var sinlat = Math.sin(lat * Math.PI/180.0);
var y = DIAMETER *Math.log((1+sinlat)/(1-sinlat)) / (4*Math.PI);
return { x, y };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment