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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。