Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile array to object #20

Merged
merged 3 commits into from
Jul 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ var tile = d3.tile();

<a href="#_tile" name="_tile">#</a> <i>tile</i>()

Computes the set of 256x256 quadtree tiles to display given the current layout [extent](#tile_extent), [scale](#tile_scale) and [translate](#tile_translate). Returns an array of arrays that specify tile addresses as [*x*, *y*, *z*] where *z* is the zoom level and *x* is periodic if [wrap](#tile_wrap) is set to *true*. Each element of the returned array also has properties *x* and *y*, which represents the offset by which the tile can be positioned. These values correspond to the *x* and *y* tile address values multiplied by 256, but without wrapping logic applied to the *x* value. The returned array also has properties `scale` and `translate` that can be used to apply the correct transformation to tile images. For example usage, see [Raster & Vector III](http://bl.ocks.org/mbostock/5914438).
Computes the set of 256x256 quadtree tiles to display given the current layout [extent](#tile_extent), [scale](#tile_scale) and [translate](#tile_translate). Returns an array of objects with the following properties:

* `x` The integer X coordinate of the tile address. Periodic if [wrap](#tile_wrap) is set to *true*.
* `y` The integer Y coordinate of the tile address.
* `z` The integer Z coordinate of the tile address (zoom level).
* `tx` The X translate to be applied to the tile. This is the `x` value multiplied by 256, but without wrapping logic applied.
* `ty` The Y translate to be applied to the tile. This is the `y` value multiplied by 256.

The returned array also has properties `scale` and `translate` that can be used to apply the correct transformation to the group of tile images. For example usage, see [Raster & Vector III](http://bl.ocks.org/mbostock/5914438).

<a href="#tile_extent" name="tile_extent">#</a> <i>tile</i>.<b>extent</b>([<i>extent</i>])

Expand Down
11 changes: 7 additions & 4 deletions src/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export default function() {

rows.forEach(function(y) {
cols.forEach(function(x) {
var d = [(x % j + j) % j, y, z0];
d.x = x * 256;
d.y = y * 256;
tiles.push(d);
tiles.push({
x: (x % j + j) % j,
y: y,
z: z0,
tx: x * 256,
ty: y * 256
});
});
});

Expand Down
11 changes: 7 additions & 4 deletions test/tile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ var tape = require("tape"),
d3 = require("../");

function tile(x, y, z, tx, ty) {
var d = [x, y, z];
d.x = tx;
d.y = ty;
return d;
return {
x: x,
y: y,
z: z,
tx: tx,
ty: ty
};
}

tape("tile", function(test) {
Expand Down