Class: TileGrid

ol/tilegrid/TileGrid~TileGrid


import TileGrid from 'ol/tilegrid/TileGrid';

Base class for setting the grid pattern for sources accessing tiled-image servers.

new TileGrid(options)

Name Type Description
options

Tile grid options.

Name Type Description
extent module:ol/extent~Extent

Extent for the tile grid. No tiles outside this extent will be requested by module:ol/source/Tile sources. When no origin or origins are configured, the origin will be set to the top-left corner of the extent.

minZoom number (defaults to 0)

Minimum zoom.

origin module:ol/coordinate~Coordinate

The tile grid origin, i.e. where the x and y axes meet ([z, 0, 0]). Tile coordinates increase left to right and downwards. If not specified, extent or origins must be provided.

origins Array.<module:ol/coordinate~Coordinate>

Tile grid origins, i.e. where the x and y axes meet ([z, 0, 0]), for each zoom level. If given, the array length should match the length of the resolutions array, i.e. each resolution can have a different origin. Tile coordinates increase left to right and downwards. If not specified, extent or origin must be provided.

resolutions Array.<number>

Resolutions. The array index of each resolution needs to match the zoom level. This means that even if a minZoom is configured, the resolutions array will have a length of maxZoom + 1.

sizes Array.<module:ol/size~Size>

Number of tile rows and columns of the grid for each zoom level. If specified the values define each zoom level's extent together with the origin or origins. A grid extent can be configured in addition, and will further limit the extent for which tile requests are made by sources. If the bottom-left corner of an extent is used as origin or origins, then the y value must be negative because OpenLayers tile coordinates use the top left as the origin.

tileSize number | module:ol/size~Size

Tile size. Default is [256, 256].

tileSizes Array.<module:ol/size~Size>

Tile sizes. If given, the array length should match the length of the resolutions array, i.e. each resolution can have a different tile size.

Subclasses

Methods

forEachTileCoord(extent, zoom, callback)

Call a function with each tile coordinate for a given extent and zoom level.

Name Type Description
extent module:ol/extent~Extent

Extent.

zoom number

Integer zoom level.

callback function

Function called with each tile coordinate.

Get the extent for this tile grid, if it was configured.

Returns:
Extent.

getMaxZoom(){number}

Get the maximum zoom level for the grid.

Returns:
Max zoom.

getMinZoom(){number}

Get the minimum zoom level for the grid.

Returns:
Min zoom.

Get the origin for the grid at the given zoom level.

Name Type Description
z number

Integer zoom level.

Returns:
Origin.

getResolution(z){number}

Get the resolution for the given zoom level.

Name Type Description
z number

Integer zoom level.

Returns:
Resolution.

getResolutions(){Array.<number>}

Get the list of resolutions for the tile grid.

Returns:
Resolutions.

getTileCoordExtent(tileCoord, opt_extent){module:ol/extent~Extent}

Get the extent of a tile coordinate.

Name Type Description
tileCoord module:ol/tilecoord~TileCoord

Tile coordinate.

extent module:ol/extent~Extent

Temporary extent object.

Returns:
Extent.

getTileCoordForCoordAndResolution(coordinate, resolution, opt_tileCoord){module:ol/tilecoord~TileCoord}

Get the tile coordinate for the given map coordinate and resolution. This method considers that coordinates that intersect tile boundaries should be assigned the higher tile coordinate.

Name Type Description
coordinate module:ol/coordinate~Coordinate

Coordinate.

resolution number

Resolution.

tileCoord module:ol/tilecoord~TileCoord

Destination module:ol/tilecoord~TileCoord object.

Returns:
Tile coordinate.

getTileCoordForCoordAndZ(coordinate, z, opt_tileCoord){module:ol/tilecoord~TileCoord}

Get a tile coordinate given a map coordinate and zoom level.

Name Type Description
coordinate module:ol/coordinate~Coordinate

Coordinate.

z number

Zoom level.

tileCoord module:ol/tilecoord~TileCoord

Destination module:ol/tilecoord~TileCoord object.

Returns:
Tile coordinate.

Get the tile size for a zoom level. The type of the return value matches the tileSize or tileSizes that the tile grid was configured with. To always get an module:ol/size~Size, run the result through module:ol/size~Size.toSize().

Name Type Description
z number

Z.

Returns:
Tile size.

getZForResolution(resolution, opt_direction){number}

Name Type Description
resolution number

Resolution.

direction number | module:ol/array~NearestDirectionFunction

If 0, the nearest resolution will be used. If 1, the nearest higher resolution (lower Z) will be used. If -1, the nearest lower resolution (higher Z) will be used. Default is 0. Use a module:ol/array~NearestDirectionFunction for more precise control.

For example to change tile Z at the midpoint of zoom levels

function(value, high, low) {
  return value - low * Math.sqrt(high / low);
}
Returns:
Z.