d3 / d3-tile

Compute the quadtree tiles to display in a rectangular viewport.

Home Page:https://observablehq.com/collection/@d3/d3-tile

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Easier tile positioning?

mbostock opened this issue · comments

It’s be nice to have a convenience method for computing tile positions. Currently I do something like:

x="${Math.round((x + tiles.translate[0]) * tiles.scale)}" y="${Math.round((y + tiles.translate[1]) * tiles.scale)}"

It’d be nice if there were a function on the tile generator that took a tile object and returned its [x, y] coordinates in screenspace as above.

https://observablehq.com/@d3/raster-tiles

I think the challenge is that the tile.tx and tile.ty are premultiplied by the tile size, whereas I expect them to be premultiplied by the tile scale (tiles.scale). Often these are the same, as when you’re clamped to an exact power-of-two zoom level, but if they’re not, then it’s awkward to divide the premultiplied values by the tile size and then multiply them by the tile scale.

A cleaner way to do this would be to not premultiply at all, and just have the wrapped and unwrapped tile indexes.

This feels like the same issue as #5.