A layout for working with image-based map tiles. This can be used to create a simple slippy map, or to render standard map tiles (e.g., Mapbox, Mapzen, CloudMade, Bing) as a base layer behind a vector layer.
If you use NPM, npm install d3-tile
. Otherwise, download the latest release. You can also load directly from unpkg.com as a standalone library. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3
global is exported:
<script src="https://unpkg.com/[email protected]"></script> <script src="https://unpkg.com/[email protected]"></script> <script> var tile = d3.tile(); </script>
Constructs a layout for determining which quadtree tiles to display in a rectangular viewport.
var tile = d3.tile();
Computes the set of quadtree tiles to display given the current layout extent, scale, translate and tileSize. Returns an array of objects with the following properties:
x
The integer X coordinate of the tile address. Periodic if 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 tileSize, but without wrapping logic applied.ty
The Y translate to be applied to the tile. This is the y
value multiplied by tileSize.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.
If extent is specified, sets this tile layout’s extent to the specified array of points [[x0, y0], [x1, y1]], where [x0, y0] is the top-left corner and [x1, y1] is the bottom-right corner, and returns this tile layout. If extent is not specified, returns the current layout extent.
If size is specified, sets this tile layout’s size to the specified two-element array of numbers [width, height] and returns this tile layout. If size is not specified, returns the current layout size. This is a convenience method equivalent to setting the extent to [[0, 0], [width, height]].
If scale is specified, sets this tile layout’s scale to the specified number scale and returns this tile layout. If scale is not specified, returns the current layout scale.
If translate is specified, sets this tile layout’s translate to the specified two-element array of numbers [x, y] and returns this tile layout. If translate is not specified, returns the current layout translate.
If wrap is specified, sets this tile layout’s wrapping option to the specified boolean value and returns this tile layout. If wrap is not specified, returns the current wrapping option, which defaults to true.
wrap(true)
If wrap is true, wrapping logic will be applied to tile address x values when the layout is evaluated. This will cause map tiles to be displayed in a periodic manner, going beyond longitude values between -180 and 180.
wrap(false)
If wrap is false, wrapping logic will be disabled, limiting tiles to be within longitude values between -180 and 180.
If tileSize is specified, sets this tile layout’s individual tile widths and heights to the specified number tileSize and returns this tile layout. If tileSize is not specified, returns the current layout tile size, which defaults to 256, the most common tile size among tile service providers.
© 2010–2017 Michael Bostock
Licensed under the BSD License.
https://github.com/d3/d3-tile