Skip to content

Documentation / @interstellar-tools/maps / tileBounds

Function: tileBounds() ​

ts
function tileBounds(x: number, y: number, z: number): TileBoundsInterface;

Defined in: tiles/tile-bounds.ts:48

Find the edges of a web map tile: the latitudes of its north and south edges and the longitudes of its west and east edges. The inverse of tileAt.

λ=x2z2π−π,φ=arctan⁡sinh(π(1−2y2z))

Where:

  • x and y are the tile's column and row; x+1 and y+1 give its east and south edges
  • z is the zoom level

Units

  • Inputs: integer tile indices.
  • Output: { north, south, west, east } in radians.

Notes

  • Neighbouring tiles share their edges exactly: the east edge of one tile is the west edge of the next.
  • The top row's north edge, and the bottom row's south edge, are the map's limit, ±arctan⁡sinh⁡π≈±85.0511°.
  • Tiles are square on the map, but on the sphere they are as wide as they are tall only near the equator.

Parameters ​

ParameterTypeDescription
xnumberColumn, east from 180° W (an integer in [0, 2^z)).
ynumberRow, south from the top edge of the map (an integer in [0, 2^z)).
znumberZoom level (an integer in [0, 30]).

Returns ​

TileBoundsInterface

The tile's edges, { north, south, west, east } in radians.

Throws ​

If z is not an integer in [0, 30], or x or y is not an integer in [0, 2^z).

Example ​

ts
// The single tile at zoom 0 is the whole map
tileBounds(0, 0, 0);
// { north: 85.0511°, south: −85.0511°, west: −180°, east: 180° }, in radians

See ​