0

In every D3 map example I can find, the scale parameter of the Mercator projection is set to equal width / 2 / Math.PI. Is this unique to the Mercator projection? What is scale doing that it needs to rely on pi? I'd love to have a more intuitive understanding of what's going on here, but the docs are pretty sparse.

"If scale is specified, sets the projection’s scale factor to the specified value and returns the projection. If scale is not specified, returns the current scale factor which defaults to 150. The scale factor corresponds linearly to the distance between projected points. However, scale factors are not consistent across projections."

jefflovejapan
  • 2,047
  • 3
  • 20
  • 34
  • Not sure what examples you're referring to. There's certainly no need for it to be specified in terms of pi. – Lars Kotthoff Feb 11 '14 at 16:45
  • Here's one: http://techslides.com/demos/d3/d3-worldmap-boilerplate.html – jefflovejapan Feb 11 '14 at 17:29
  • [This question](http://stackoverflow.com/questions/14492284/center-a-map-in-d3-given-a-geojson-object) shows how to fit a given object within the container and doesn't rely on pi to compute the scale. – Lars Kotthoff Feb 11 '14 at 18:38

1 Answers1

1

The Mercator projection code uses a lot of trig to convert between angular lat/long coordinates and cartesian x/y coordinates. I'm pretty sure that the width/2/Math.PI just makes sure that the entire globe fits within a width. (Within the code, your input scale factor gets multiplied by pi.) If you're not mapping the entire globe, you'll need to figure out an appropriate scale factor yourself.

AmeliaBR
  • 27,344
  • 6
  • 86
  • 119