d3 / d3-plugins

[DEPRECATED] A repository for sharing D3.js V3 plugins.

Home Page:https://github.com/d3/d3/wiki/Plugins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding a center option to geo.tile

popkinj opened this issue · 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

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.

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?

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

Ahhhh.. Thanks Mike. ☺