2

I have a topojson file created with the --bbox flag, I figured out how to get the center (where b is the bbox):

var center = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2]

Then I calculated the scale, the problem is that I calculated it for a equirectangular projection (because it's easy enough):

var wScale = width  / (Math.abs(b[0] - b[2]) / 360) / 2 / Math.PI
var hScale = height / (Math.abs(b[1] - b[3]) / 360) / 2 / Math.PI
var scale = Math.min(wScale, hScale)

equirectangular straya

I can't find a way to calculate it for a mercator projection. I've seen this answer and tried to use the projection to get the scale and directly set the new scale:

projection = d3.geo.mercator()
    .translate([width / 2, height / 2])
    .center(center)
    .scale(1)

[b0, b1] = projection([b[0], b[1]])
[b2, b3] = projection([b[2], b[3]])
scale = 1 / Math.max(Math.abs(b2 - b0) / width, Math.abs(b3 - b1) / height)

projection.scale(s)

But the result isn't perfect (poor Tasmania):

sad mercator straya

EDIT: Should I have post in https://gis.stackexchange.com/ or here is fine ?

Community
  • 1
  • 1
Calvein
  • 2,111
  • 13
  • 28
  • Have you tried getting the bounds directly from the projection as in the answer you've linked to? – Lars Kotthoff Nov 13 '14 at 09:49
  • I did but the problem is that `path.bounds` doesn't return coordinates, and I can't do it on a g, it has to be path (and I have hundreds of path with real data, not in this tiny example). – Calvein Nov 13 '14 at 22:58
  • This may help http://stackoverflow.com/questions/28141812/ – Hugolpz Feb 05 '15 at 00:20

0 Answers0