source: Dev/trunk/d3/src/geo/mercator.js @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 652 bytes
Line 
1d3.geo.mercator = function() {
2  var scale = 500,
3      translate = [480, 250];
4
5  function mercator(coordinates) {
6    var x = (coordinates[0]) / 360,
7        y = (-180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + coordinates[1] * Math.PI / 360))) / 360;
8    return [
9      scale * x + translate[0],
10      scale * Math.max(-.5, Math.min(.5, y)) + translate[1]
11    ];
12  }
13
14  mercator.scale = function(x) {
15    if (!arguments.length) return scale;
16    scale = +x;
17    return mercator;
18  };
19
20  mercator.translate = function(x) {
21    if (!arguments.length) return translate;
22    translate = [+x[0], +x[1]];
23    return mercator;
24  };
25
26  return mercator;
27};
Note: See TracBrowser for help on using the repository browser.