d3-plugins icon indicating copy to clipboard operation
d3-plugins copied to clipboard

Adding a center option to geo.tile

Open popkinj opened this issue 10 years ago • 4 comments

I love the geo.tile plugin.

The d3 projection method has the handy dandy center() function that allows you to reset the translate values to your area of choice. What are the chances someone who's better at math then me would want to make something similar for the geo.tile plugin.

I like to think of myself as a fairly smart guy... But looking at the calculations going on here makes my brain hurt.

Jamie

popkinj avatar Mar 13 '14 01:03 popkinj

I think this is probably a duplicate of #37.

Personally, my inclination is to leave d3.geo.tile to operate only in pixel coordinates and not be tied to latitude & longitude; a better name would be d3.geom.tile. The way I intend it to be used is with a geographic projection:

var projection = d3.geo.mercator()
    .center([-76.3429, 38.7351]) // geographic center
    .scale(1 << 12) // zoom level in tile coordinates
    .translate([width / 2, height / 2]);

var tile = d3.geo.tile()
    .scale(projection.scale())
    .translate(projection([0, 0]))
    .size([width, height]);

But there’s definitely an opportunity to make this usage more obvious. Open to suggestions.

mbostock avatar Mar 13 '14 02:03 mbostock

Thanks Mike. That makes sense.

I guess I'm a little stumped on how the bitwise logic works. How does 1 << 12 convert into tile coordinates?

popkinj avatar Mar 13 '14 16:03 popkinj

1 << 12 is the same as 2^12 or Math.pow(2, 12); zoom levels are powers of two.

mbostock avatar Mar 13 '14 16:03 mbostock

Ahhhh.. Thanks Mike. ☺

popkinj avatar Mar 13 '14 16:03 popkinj