Skip to content

Instantly share code, notes, and snippets.

@matallo
Forked from javisantana/mercator.js
Created July 4, 2017 15:23
Show Gist options
  • Save matallo/ff03af7ac32bb358e8295193e94984f9 to your computer and use it in GitHub Desktop.
Save matallo/ff03af7ac32bb358e8295193e94984f9 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