当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS BingMapsLayer.fetchTile用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/layers/BingMapsLayer"], (BingMapsLayer) => { /* code goes here */ });

ESM: import BingMapsLayer from "@arcgis/core/layers/BingMapsLayer";

类: esri/layers/BingMapsLayer

继承: BingMapsLayer > BaseTileLayer > Layer > Accessor

自从:用于 JavaScript 4.8 的 ArcGIS API

用法说明

BingMapsLayer.fetchTile函数(或属性)的定义如下:

fetchTile (level, row, col, options) {Promise<(HTMLImageElement|HTMLCanvasElement)>} inherited


此方法获取视图中存在的给定级别、行和列的图块。如果从服务器返回的数据或图像需要经过处理才能显示,则覆盖此方法。

参数:

类型说明
level Number

要获取的图块的详细程度。该值由 LayerView 提供。

row Number

瓦片提取的行 (y) 位置。该值由 LayerView 提供。

col Number

要获取的图块的列 (x) 位置。该值由 LayerView 提供。

options Object
可选的

磁贴请求的可选设置。这些选项具有以下属性。

规格:
signal

AbortSignal

可选的

AbortSignal 用于中止请求。覆盖 fetchTile 时,应处理 signal,例如将其传递给 request 或中止挂起的操作。对 fetchTile 的中止调用应该使用 Error 的实例拒绝其返回的承诺。

返回:

类型 说明
Promise<(HTMLImageElement|HTMLCanvasElement)> 返回解析为 HTMLImageElementHTMLCanvasElement 的承诺。

例子:

// Process the image returned from the server before
// it is displayed.
fetchTile: function (level, row, col, options) {
  // call getTileUrl method to construct the URL for
  // the image for the given level, row and col
  let url = this.getTileUrl(level, row, col);

  // request for the tile based on the generated url.
  // the signal option ensures that obsolete requests are aborted.
  return esriRequest(url, {
    responseType: "image",
    signal: options && options.signal
  })
  .then(function (response) {
    // get the image from the response
    let image = response.data;
    let width = this.tileInfo.size[0];
    let height = this.tileInfo.size[0];

    let canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    let context = canvas.getContext("2d");

    // tint is a custom property of this layer
    // Apply the tint color provided by the application
    // to the canvas
    if (this.tint) {
      context.fillStyle = this.tint.toCss();
      context.fillRect(0, 0, width, height);

      // The pixels of the top layer are multiplied by the corresponding
      // pixel of the bottom layer. A darker picture is the result.
      context.globalCompositeOperation = "multiply";
    }
    context.drawImage(image, 0, 0, width, height);
    return canvas;
  }.bind(this));
}

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 BingMapsLayer.fetchTile。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。