Class: ImageTile

ol/ImageTile~ImageTile


Extends

Methods

dispatchEvent(event){boolean | undefined} inherited

分发事件并调用所有监听此类型事件的监听器。事件参数可以是一个字符串或一个 具有 type 属性的对象。

Name Type Description
event BaseEvent | string

事件对象。

返回值:
如果有人在事件对象上调用了 preventDefault 或任何监听器返回 false,则返回 false

getImage(){HTMLCanvasElement | OffscreenCanvas | HTMLImageElement | HTMLVideoElement}

获取此瓦片的 HTML 图像元素(可能是 Canvas、OffscreenCanvas、Image 或 Video)。

返回值:
图像。

getTileCoord(){TileCoord} inherited

获取此瓦片的瓦片坐标。

返回值:
瓦片坐标。

加载图像或在之前加载失败时重试。加载由瓦片队列负责,调用此方法仅用于预加载或在出错时重新加载。

要在失败的请求上重试加载瓦片,请使用自定义 tileLoad函数,检查错误状态码并仅在状态码为 408、429、500、502、503 和 504 时重新加载,且仅在尚未进行过多重试时:

const retryCodes = [408, 429, 500, 502, 503, 504];
const retries = {};
source.setTileLoad函数((tile, src) => {
  const image = tile.getImage();
  fetch(src)
    .then((response) => {
      if (retryCodes.includes(response.status)) {
        retries[src] = (retries[src] || 0) + 1;
        if (retries[src] <= 3) {
          setTimeout(() => tile.load(), retries[src] * 1000);
        }
        return Promise.reject();
      }
      return response.blob();
    })
    .then((blob) => {
      const imageUrl = URL.createObjectURL(blob);
      image.src = imageUrl;
      setTimeout(() => URL.revokeObjectURL(imageUrl), 5000);
    })
    .catch(() => tile.setState(3)); // error
});

setState(state) inherited

设置此瓦片的状态。如果您编写自己的 tileLoad函数, 当瓦片无法加载时正确将状态设置为 ERROR 非常重要。否则瓦片无法从瓦片队列中移除,将阻塞其他请求。

Name Type Description
state ol/TileState

状态。