Module: ol/Tile

ol/Tile


Classes

Tile

Type Definitions

LoadFunction()

A function that takes a Tile for the tile and a {string} for the url as arguments. The default is

source.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.js';

source.setTileLoadFunction(function(tile, src) {
  const xhr = new XMLHttpRequest();
  xhr.responseType = 'blob';
  xhr.addEventListener('loadend', function (evt) {
    const 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 Description
transition number
(defaults to 250)

A duration for tile opacity transitions in milliseconds. A duration of 0 disables the opacity transition.

interpolate boolean
(defaults to false)

Use interpolated values when resampling. By default, the nearest neighbor is used when resampling.

UrlFunction()

TileSource sources use a function of this type to get the url that provides a tile for a given tile coordinate.

This function takes a TileCoord for the tile coordinate, a {number} representing the pixel ratio and a 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.