Class: XYZ


import XYZ from 'ol/source/XYZ';

Layer source for tile data with URLs in a set XYZ format that are defined in a URL template. By default, this follows the widely-used Google grid where x 0 and y 0 are in the top left. Grids like TMS where x 0 and y 0 are in the bottom left can be used by using the {-y} placeholder in the URL template, so long as the source does not have a custom tile grid. In this case, module:ol/source/TileImage can be used with a tileUrlFunction such as:

tileUrlFunction: function(coordinate) { return '' + coordinate[0] + '/' + coordinate[1] + '/' + coordinate[2] + '.png'; }

new XYZ(opt_options)

source/XYZ.js, line 66
Name Type Description

XYZ options.

Name Type Default Description
attributions module:ol/source/Source~AttributionLike


attributionsCollapsible boolean true

Attributions are collapsible.

cacheSize number 2048

Cache size.

crossOrigin null | string

The crossOrigin attribute for loaded images. Note that you must provide a crossOrigin value if you are using the WebGL renderer or if you want to access pixel data with the Canvas renderer. See for more detail.

opaque boolean true

Whether the layer is opaque.

projection module:ol/proj~ProjectionLike 'EPSG:3857'


reprojectionErrorThreshold number 0.5

Maximum allowed reprojection error (in pixels). Higher values can increase reprojection performance, but decrease precision.

maxZoom number 18

Optional max zoom level.

minZoom number 0

Optional min zoom level.

tileGrid module:ol/tilegrid/TileGrid~TileGrid

Tile grid.

tileLoadFunction module:ol/Tile~LoadFunction

Optional function to load a tile given a URL. The default is

function(imageTile, src) {
  imageTile.getImage().src = src;
tilePixelRatio number 1

The pixel ratio used by the tile service. For example, if the tile service advertizes 256px by 256px tiles but actually sends 512px by 512px images (for retina/hidpi devices) then tilePixelRatio should be set to 2.

tileSize number | module:ol/size~Size [256, 256]

The tile size used by the tile service.

tileUrlFunction module:ol/Tile~UrlFunction

Optional function to get tile URL given a tile coordinate and the projection. Required if url or urls are not provided.

url string

URL template. Must include {x}, {y} or {-y}, and {z} placeholders. A {?-?} template pattern, for example subdomain{a-f}, may be used instead of defining each one separately in the urls option.

urls Array.<string>

An array of URL templates.

wrapX boolean true

Whether to wrap the world horizontally.

transition number

Duration of the opacity transition for rendering. To disable the opacity transition, pass transition: 0.





getTileLoadFunction(){module:ol/Tile~LoadFunction} inherited

source/UrlTile.js, line 104

Return the tile load function of the source.


getTileUrlFunction(){module:ol/Tile~UrlFunction} inherited

source/UrlTile.js, line 113

Return the tile URL function of the source.


getUrls(){!Array.<string>|null} inherited

source/UrlTile.js, line 124

Return the URLs used for this source. When a tileUrlFunction is used instead of url or urls, null will be returned.


setRenderReprojectionEdges(render) inherited

source/TileImage.js, line 356

Sets whether to render reprojection edges or not (usually for debugging).

Name Type Description
render boolean

Render the edges.

setTileGridForProjection(projection, tilegrid) inherited

source/TileImage.js, line 380

Sets the tile grid to use when reprojecting the tiles to the given projection instead of the default tile grid for the projection.

This can be useful when the default tile grid cannot be created (e.g. projection has no extent defined) or for optimization reasons (custom tile size, resolutions, ...).

Name Type Description
projection module:ol/proj~ProjectionLike


tilegrid module:ol/tilegrid/TileGrid~TileGrid

Tile grid to use for the projection.

setTileLoadFunction(tileLoadFunction) inherited

source/UrlTile.js, line 157

Set the tile load function of the source.

Name Type Description
tileLoadFunction module:ol/Tile~LoadFunction

Tile load function.

setTileUrlFunction(tileUrlFunction, key) inherited

source/UrlTile.js, line 169

Set the tile URL function of the source.

Name Type Description
tileUrlFunction module:ol/Tile~UrlFunction

Tile URL function.

key string

Optional new tile key for the source.

setUrl(url) inherited

source/UrlTile.js, line 184

Set the URL to use for requests.

Name Type Description
url string


setUrls(urls) inherited

source/UrlTile.js, line 194

Set the URLs to use for requests.

Name Type Description
urls Array.<string>