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


JavaScript ArcGIS BaseLayerView2D.render用法及代码示例


基本信息

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

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

ESM: import BaseLayerView2D from "@arcgis/core/views/2d/layers/BaseLayerView2D";

类: esri/views/2d/layers/BaseLayerView2D

继承: BaseLayerView2D > LayerView > Accessor

自从:用于 JavaScript 4.8 的 ArcGIS API

用法说明

BaseLayerView2D.render函数(或属性)的定义如下:

render (renderParameters)


负责绘制图层内容的实现方法。每当 MapView 的状态发生变化或调用 requestRender() 时,都会调用此方法。

参数:

规格:
类型说明
renderParameters Object
规格:

绘制内容的canvas 2D context

stationary

Boolean

MapView 的静止状态。

state

ViewState

说明视图状态的对象。

例子:

// Example of a render implementation that draws tile boundaries
render(renderParameters) {
  let tileSize = this.layer.tileInfo.size[0];
  let state = renderParameters.state;
  let pixelRatio = state.pixelRatio;
  let width = state.size[0];
  let height = state.size[1];
  let context = renderParameters.context;
  let coords = [0, 0];

  context.fillStyle = "rgba(0,0,0,0.25)";
  context.fillRect(0, 0, width * pixelRatio, height * pixelRatio);

  // apply rotation for everything that will be applied to the canvas
  if (state.rotation !== 0) {
    context.translate(width * pixelRatio * 0.5, height * pixelRatio * 0.5);
    context.rotate((state.rotation * Math.PI) / 180);
    context.translate(- width * pixelRatio * 0.5, -height * pixelRatio * 0.5);
  }

  // Set the style for all the text.
  context.font = "24px monospace";
  context.fillStyle = "black";
  context.shadowBlur = 1;

  for (const tile of this.tiles) {
    let screenScale = tile.resolution / state.resolution * pixelRatio;

    state.toScreenNoRotation(coords, tile.coords);

    // Draw the tile boundaries
    context.strokeRect(coords[0], coords[1], tileSize * screenScale, tileSize * screenScale);

    // Draw the tile information
    context.shadowColor = "white";
    context.fillText(
      tile.level + "/" + tile.row + "/" + tile.col + "/" + tile.world,
      coords[0] + 12,
      coords[1] + 24,
      tileSize * screenScale
    );
    context.shadowColor = "transparent";
  }
}

相关用法


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