模块:ol/Tile

ol/Tile


Tile

类型定义

LoadFunction()

该函数以瓦片的 Tile 和 URL 的 {string} 为参数。默认为

source.setTileLoadFunction(function(tile, src) {
  tile.getImage().src = src;
});

对于更细粒度的控制,加载函数可以使用 fetch 或 XMLHttpRequest 并涉及错误处理:

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}

属性:
Name Type 描述
transition number
(defaults to 250)

瓦片不透明度过渡的持续时间(毫秒)。当持续时间为 0 时,不透明度过渡将被禁用。

interpolate boolean
(defaults to false)

重采样时使用插值。默认情况下,重采样采用最近邻法。

UrlFunction()

TileSource 源使用此类函数来获取为给定瓦片坐标提供瓦片的URL。

该函数接受一个 TileCoord 作为瓦片坐标参数,一个 {number} 表示像素比,以及一个 Projection 作为投影参数,并返回一个 {string} 表示瓦片 URL;如果对于传递的瓦片坐标没有瓦片需要请求,则返回 undefined。