ImageryLayer - client side rendering rules

Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to apply client defined rendering rules and mosaic rules to an ImageryLayer layer.

The rendering rule uses a raster function chain to reclassify and re-render the original land cover categories into two new categories: forest and non-forest.

// Defines a Remap raster function. Remap reclassifies pixel
// values to new values. In this case we want to separate
// two landcover types: forested areas and non-forested areas

var remapRF = new RasterFunction({
  functionName: "Remap",
  functionArguments: {
    // pixel values of forest categories are 41, 42, and 43
    // according to the  raster attribute table.
    // The InputRanges property defines the ranges of intial pixel values to remap
    // Three ranges: [0, 41], [41, 44], and [44, 255] are defined to extract forest pixels.
    inputRanges: [0, 41, 41, 44, 44, 255],
    // non-forest pixels (0-41 and 44-255) are remapped to a value of 1,
    // forest pixels (41-44) are remapped to a value of 2.
    outputValues: [1, 2, 1],
    // $$(default) refers to the entire image service,
    // $2 refers to the second image of the image service
    raster: "$$"
  }
});

// The Colormap raster function adds color to each pixel
// based on its pixel value
var colorRF = new RasterFunction({
  functionName: "Colormap",
  functionArguments: {
    colormap: [
      // non-forest pixels (value of 1) are assigned
      // a yellowish color RGB = [253, 254, 152]
      [1, 253, 254, 152],
      // forest pixels (value of 2) are assigned
      // a greenish color RGB = [2, 102, 6]
      [2, 2, 102, 6]
    ],
    // Setting the previous raster function to the Raster
    // property of a new raster function allows you to chain functions
    raster: remapRF
  },
  outputPixelType: "U8"
});

var layer = new ImageryLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer",
  // apply the most recent raster function to the chain
  renderingRule: colorRF,
  mosaicRule: mosaicRule,
});

Mosaic rule changes the mosaic schema of all raster items in the referenced image service. Once set, it generates a map in which green areas represent forested while yellow areas are non-forest.

Sample search results

TitleSample
Loading...