Skip to content

This sample shows how to use the attributeTable of an ImageryLayer to mask pixels from display. The pixelFilter method of the layer allows the developer to add color to each pixel using RGB values and exclude unwanted pixels.

This layer contains land cover data. Each pixel value represents a land cover type and has attributes associated with it available via the raster attribute table in the image service. This sample shows the desert areas across the United States by only displaying pixels with values of Shrub/Scrub or Barren Land.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
const layer = new ImageryLayer({ url: landCoverServiceURL, pixelFilter: colorize });
viewElement.map.add(layer);
await viewElement.whenLayerView(layer);

// Filter desired land cover types and RGB values; store them as key-value pairs.
layer.serviceRasterInfo.attributeTable.features.forEach((item) => {
  const { ClassName, Red, Green, Blue } = item.attributes;
  if (["Barren Land", "Shrub/Scrub"].includes(ClassName)) {
    graphics[item.attributes.Value] = [Red, Green, Blue];
  }
});

Once you have the fields of interest, you can use the pixelFilter method to exclude unwanted pixels with the mask property of the pixelBlock and color the desired pixels with either the preset color scheme or any other desired color scheme.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.