當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。