Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TileKey

The TileKey instances are used to address a tile in a quadtree.

A tile key is defined by a row, a column, and a level. The tree has a root at level 0, with one single tile. On every level, each tile is divided into four children (therefore the name quadtree).

Within each level, any particular tile is addressed with row and column. The number of rows and columns in each level is 2 to the power of the level. This means: On level 0, only one tile exists, columnsAtLevel() and rowsAtLevel() are both 1. On level 1, 4 tiles exist, in 2 rows and 2 columns. On level 2 we have 16 tiles, in 4 rows and 4 columns. And so on.

A tile key is usually created using fromRowColumnLevel() method.

TileKey instances are immutable, all members return new instances of TileKey and do not modify the original object.

Utility functions like parent(), changedLevelBy(), and changedLevelTo() allow for easy vertical navigation of the tree. The number of available rows and columns in the tile's level is given with rowCount() and columnCount().

Tile keys can be created from and converted into various alternative formats:

Note - as JavaScript's number type can hold 53 bits in its mantissa, only levels up to 26 can be represented in the number representation returned by mortonCode().

Hierarchy

  • TileKey

Index

Constructors

constructor

  • new TileKey(row: number, column: number, level: number): TileKey
  • Constructs a new immutable instance of a TileKey.

    For the better readability, TileKey.fromRowColumnLevel should be preferred.

    Note - row and column must not be greater than the maximum rows/columns for the given level.

    Parameters

    • row: number

      Represents the row in the quadtree.

    • column: number

      Represents the column in the quadtree.

    • level: number

      Represents the level in the quadtree.

    Returns TileKey

Properties

Readonly column

column: number

Represents the column in the quadtree.

Readonly level

level: number

Represents the level in the quadtree.

Readonly row

row: number

Represents the row in the quadtree.

Methods

addedSubHereTile

  • addedSubHereTile(sub: string): TileKey

addedSubKey

  • addedSubKey(sub: string): TileKey

changedLevelBy

  • changedLevelBy(delta: number): TileKey
  • Returns a new tile key at a level that differs from this tile's level by delta.

    Equivalent to changedLevelTo(level() + delta).

    Note - root key is returned if delta is smaller than the level of this tile key.

    Parameters

    • delta: number

      The numeric difference between the current level and the requested level.

    Returns TileKey

changedLevelTo

  • changedLevelTo(level: number): TileKey
  • Returns a new tile key at the requested level.

    If the requested level is smaller than the tile's level, then the key of an ancestor of this tile is returned. If the requested level is larger than the tile's level, then the key of first child or grandchild of this tile is returned, for example, the child with the lowest row and column number. If the requested level equals this tile's level, then the tile key itself is returned. If the requested level is negative, the root tile key is returned.

    Parameters

    • level: number

      The requested level.

    Returns TileKey

columnCount

  • columnCount(): number

equals

getSubHereTile

  • getSubHereTile(delta: number): string
  • Returns a sub quadkey that is relative to its parent.

    This function can be used to generate sub keys that are relative to a parent that is delta levels up in the quadtree.

    This function can be used to create shortened keys for quads on lower levels if the parent is known.

    Note - the sub quadkeys fit in a 16-bit unsigned integer if the delta is smaller than 8. If delta is smaller than 16, the sub quadkey fits into an unsigned 32-bit integer.

    Deltas larger than 16 are not supported.

    Parameters

    • delta: number

      The number of levels relative to its parent quadkey. Must be greater or equal to 0 and smaller than 16.

    Returns string

    The quadkey relative to its parent that is delta levels up the tree.

mortonCode

  • mortonCode(): number

parent

rowCount

  • rowCount(): number

toHereTile

  • toHereTile(): string

toQuadKey

  • toQuadKey(): string
  • Converts the tile key into a string for using in REST API calls.

    If the tile is the root tile, the quadkey is '-'. Otherwise the string is a number to the base of 4, but without the leading 1, with the following properties:

    1. the number of digits equals the level.
    2. removing the last digit gives the parent tile's quadkey string, i.e. appending 0,1,2,3 to a quadkey string gives the tiles's children.

    You can convert back from a quadkey string with fromQuadKey.

    Returns string

Static atCoords

  • atCoords(level: number, coordX: number, coordY: number, totalWidth: number, totalHeight: number): TileKey
  • Returns the closest matching TileKey in a cartesian coordinate system.

    Parameters

    • level: number

      The level for the tile key.

    • coordX: number

      The X coordinate.

    • coordY: number

      The Y coordinate.

    • totalWidth: number

      The maximum X coordinate.

    • totalHeight: number

      The maximum Y coordinate.

    Returns TileKey

    A new tile key at the given level that includes the given coordinates.

Static columnsAtLevel

  • columnsAtLevel(level: number): number
  • Returns the number of available columns at a given level.

    This is 2 to the power of the level.

    Parameters

    • level: number

      The level for which to return the number of columns.

    Returns number

    The available columns at the given level.

Static fromHereTile

  • fromHereTile(quadkey64: string): TileKey

Static fromMortonCode

  • fromMortonCode(quadKey64: number): TileKey

Static fromQuadKey

  • fromQuadKey(quadkey: string): TileKey

Static fromRowColumnLevel

  • fromRowColumnLevel(row: number, column: number, level: number): TileKey
  • Creates a tile key.

    Parameters

    • row: number

      The requested row. Must be less than 2 to the power of level.

    • column: number

      The requested column. Must be less than 2 to the power of level.

    • level: number

      The requested level.

    Returns TileKey

Static parentMortonCode

  • parentMortonCode(mortonCode: number): number
  • Computes the Morton code of the parent tile key of the given Morton code.

    Note: The parent key of the root key is the root key itself.

    Parameters

    • mortonCode: number

      A Morton code, for example, obtained from mortonCode.

    Returns number

    The Morton code of the parent tile.

Static rowsAtLevel

  • rowsAtLevel(level: number): number
  • Returns the number of available rows at a given level.

    This is 2 to the power of the level.

    Parameters

    • level: number

      The level for which to return the number of rows.

    Returns number

    The available rows at the given level.

Generated using TypeDoc