Classes
Type Definitions
-
A function that takes an
module:ol/Tile
for the tile and a{string}
for the url as arguments. The default issource.setTileLoadFunction(function(tile, src) { tile.getImage().src = src; });
For more fine grained control, the load function can use fetch or XMLHttpRequest and involve error handling:
import TileState from 'ol/TileState'; source.setTileLoadFunction(function(tile, src) { var xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; xhr.addEventListener('loadend', function (evt) { var data = this.response; if (data !== undefined) { tile.getImage().src = URL.createObjectURL(data); } else { tile.setState(TileState.ERROR); } }); xhr.addEventListener('error', function () { tile.setState(TileState.ERROR); }); xhr.open('GET', src); xhr.send(); });
-
Options{Object}
-
Properties:
Name Type Argument Default Description transition
number <optional>
250 A duration for tile opacity transitions in milliseconds. A duration of 0 disables the opacity transition.
-
module:ol/source/Tile~Tile
sources use a function of this type to get the url that provides a tile for a given tile coordinate.This function takes an
module:ol/tilecoord~TileCoord
for the tile coordinate, a{number}
representing the pixel ratio and amodule:ol/proj/Projection
for the projection as arguments and returns a{string}
representing the tile URL, or undefined if no tile should be requested for the passed tile coordinate.