d3.js - How to automatically get the scale for a d3.geo.mercator projection with the topojson's bbox? -
i have topojson file created --bbox
flag, figured out how center (where b
bbox):
var center = [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2]
then calculated scale, problem calculated 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)
i can't find way calculate mercator projection. i've seen this answer , tried use projection scale , directly set 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 result isn't perfect (poor tasmania):
edit: should have post in https://gis.stackexchange.com/ or here fine ?
Comments
Post a Comment