From 028b2752198ccd85ad55d09e35417e1954371d59 Mon Sep 17 00:00:00 2001 From: Curran Date: Sat, 2 Jul 2016 11:38:00 +0530 Subject: [PATCH 1/3] Rename tile.x and tile.y to tile.tx and tile.ty. Closes #15 --- src/tile.js | 4 ++-- test/tile-test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tile.js b/src/tile.js index 64c06de..9969cf0 100644 --- a/src/tile.js +++ b/src/tile.js @@ -31,8 +31,8 @@ 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; + d.tx = x * 256; + d.ty = y * 256; tiles.push(d); }); }); diff --git a/test/tile-test.js b/test/tile-test.js index a29f306..284fba2 100644 --- a/test/tile-test.js +++ b/test/tile-test.js @@ -3,8 +3,8 @@ var tape = require("tape"), function tile(x, y, z, tx, ty) { var d = [x, y, z]; - d.x = tx; - d.y = ty; + d.tx = tx; + d.ty = ty; return d; } From 0b155353e042e013bf774f07e8195dc39ad90de0 Mon Sep 17 00:00:00 2001 From: Curran Date: Sat, 2 Jul 2016 11:42:50 +0530 Subject: [PATCH 2/3] Change tile representation from array to object --- src/tile.js | 11 +++++++---- test/tile-test.js | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/tile.js b/src/tile.js index 9969cf0..39a7f9d 100644 --- a/src/tile.js +++ b/src/tile.js @@ -30,10 +30,13 @@ export default function() { rows.forEach(function(y) { cols.forEach(function(x) { - var d = [(x % j + j) % j, y, z0]; - d.tx = x * 256; - d.ty = y * 256; - tiles.push(d); + tiles.push({ + x: (x % j + j) % j, + y: y, + z: z0, + tx: x * 256, + ty: y * 256 + }); }); }); diff --git a/test/tile-test.js b/test/tile-test.js index 284fba2..16ed595 100644 --- a/test/tile-test.js +++ b/test/tile-test.js @@ -2,10 +2,13 @@ var tape = require("tape"), d3 = require("../"); function tile(x, y, z, tx, ty) { - var d = [x, y, z]; - d.tx = tx; - d.ty = ty; - return d; + return { + x: x, + y: y, + z: z, + tx: tx, + ty: ty + }; } tape("tile", function(test) { From 1249b223bcc3746d2295324731a3ef40fff63921 Mon Sep 17 00:00:00 2001 From: Curran Date: Sun, 3 Jul 2016 13:21:57 +0530 Subject: [PATCH 3/3] Update documentation for tile object representation --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d7a386..ab9008d 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,15 @@ var tile = d3.tile(); # tile() -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). # tile.extent([extent])