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


JavaScript ArcGIS ImageryLayer.pixelFilter用法及代碼示例


基本信息

以下是所在類或對象的基本信息。

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

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

類: esri/layers/ImageryLayer

繼承: ImageryLayer > Layer > Accessor

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

ImageryLayer.pixelFilter函數(或屬性)的定義如下:

pixelFilter PixelFilterFunction


處理 pixelData 的函數。 pixelData 對象包含一個pixelBlock 屬性,可讓您訪問客戶端上光柵中的所有像素。

pixelFilter 內部,您可以循環遍曆 pixelData 對象的 pixelBlock 屬性中找到的所有 pixels 並處理它們。此函數可用於從視圖中隱藏某些像素、更改它們的值以及更改它們的顏色。當圖像圖層的格式為lerctiff 時,應使用pixelFilter,因為這些格式將原始像素數據返回給客戶端。

例子:

let layer = new ImageryLayer({
  url: // url to the image service
  pixelFilter: colorize  // see the colorize() function below
});

// This function is applied to the pixelFilter property of the layer.
// It takes the original value of each pixel and converts it to an RGB
// representation to color the layer on a blue - red ramp. Blue pixels
// represent low values and red pixels represent high values. View the sample
// referenced above to see how this function works

function colorize(pixelData) {
  // If there isn't pixelData, a pixelBlock, nor pixels, exit the function
  if (pixelData === null || pixelData.pixelBlock === null || pixelData.pixelBlock.pixels === null) {
    return;
  }

  // The pixelBlock stores the values of all pixels visible in the view
  let pixelBlock = pixelData.pixelBlock;

  // Get the min and max values of the data in the current view
  let minValue = pixelBlock.statistics[0].minValue;
  let maxValue = pixelBlock.statistics[0].maxValue;

  // The mask is an array that determines which pixels are visible to the client
  let mask = pixelBlock.mask;

  // The pixels visible in the view
  let pixels = pixelBlock.pixels;

  // The number of pixels in the pixelBlock
  let numPixels = pixelBlock.width * pixelBlock.height;

  // Calculate the factor by which to determine the red and blue
  // values in the colorized version of the layer
  let factor = 255.0 / (maxValue - minValue);

  // Get the pixels containing temperature values in the only band of the data
  let band1 = pixels[0];

  // Create empty arrays for each of the RGB bands to set on the pixelBlock
  let rBand = [];
  let gBand = [];
  let bBand = [];

  // Loop through all the pixels in the view
  for (i = 0; i < numPixels; i++) {
    // Get the pixel value recorded at the pixel location
    let tempValue = band1[i];
    // Calculate the red value based on the factor
    let red = (tempValue - minValue) * factor;

    // Sets a color between blue (lowest) and red (highest) in each band
    rBand[i] = red;
    gBand[i] = 0;
    bBand[i] = 255 - red;
  }

  // Set the new pixel values on the pixelBlock (now three bands)
  pixelData.pixelBlock.pixels = [rBand, gBand, bBand];
  pixelData.pixelBlock.pixelType = "u8"; // u8 is used for color
}

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 ImageryLayer.pixelFilter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。