Considering this:
xy = d3.geo.mercator().scale(someScale).translate([0, 0]);
someScale pixel width of the whole world when projected using the projection of the mercator. So, if your json data was outlined for the whole world - from lat / lng -180.90 to latLng 180, -90 - and if someScale is 1024, then the world will be drawn in such a way that it exactly matches 1024x1024 pixels. This is what you see on this Google Maps (well ... sort of ... not really ... read on ...).
But this is not enough. When the world is drawn at 1024px without translation, lat / lng 0,0 (ie the “Medium” of the world) will sit on the 0,0 pixels of the projected map (ie, Top left). Under these conditions, the entire northern hemisphere and the western hemisphere have negative x or y values and, therefore, go beyond the elongated region. In addition, under these conditions, the lower right edge of the world (i.e. lat / lng -90, 180) will be located in the exact middle of the square 1024x1024 (that is, at 512 512 pixels).
So, to center the world on the square described here, you need to translate display half its width in the X and Y directions. That is, you need
xy = d3.geo.mercator().scale(1024).translate([512, 512]);
This will give you exactly the kind of Google Map I am associated with.
If your json data has only part of the world (e.g. nyc or New York State), drawing it with this xy projection will display the outlines in the correct geographic position with respect to the entire 1024x1024 circumferential range. So it looks pretty small with a lot of spaces.
The challenge is how to scale and translate the projection so that the area in question fills the 1024x1024 square. And ... until I answered this question, but I hope that this explanation points you in the right direction to understand this math. I will also try to continue the answer later when I have more time.: /
meetamit
source share