Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Adding a center option to geo.tile #87

Open
popkinj opened this issue Mar 13, 2014 · 4 comments
Open

Adding a center option to geo.tile #87

popkinj opened this issue Mar 13, 2014 · 4 comments

Comments

@popkinj
Copy link

popkinj commented Mar 13, 2014

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

@mbostock
Copy link
Member

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.

@popkinj
Copy link
Author

popkinj commented Mar 13, 2014

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?

@mbostock
Copy link
Member

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

@popkinj
Copy link
Author

popkinj commented Mar 13, 2014

Ahhhh.. Thanks Mike. ☺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants