Represents a 1D color gradient bounded by a min and max values.

Whenever a color map is associated with a grayscale texture, the color intensity of the texture is used a a parameter to sample the color gradient.

Important: since this color map owns a texture, it is disposable. Don't forget to call dispose() to free texture memory, when you're finished using the colormap.

The mode property describes how the intensity of the pixel is interpreted:

Elevation simply takes the intensity value of the pixel, Slope gets the slope of the pixel (assuming it is an elevation texture), and Aspect gets the aspect (orientation from the north) of the pixel (assuming it is an elevation texture).

The min and max properties describe how the colormap is applied relative to the intensity of the sampled pixel.

Pixel intensities outside of those bounds will take the color of the bound that is the closest (i.e if the intensity is greater than max, the color will be the rightmost color of the color ramp).

The colors property takes an array of colors. To create this array, you can use libraries such as colormap or chroma-js to generate the color ramp.

To obtain a "discrete" color map, you should use a small number of colors in the ramp. Conversely, to obtain a "linear", continuous color map, you should use a high number of colors, typically 256 values.

// Create a color map for elevations between 0 and 2500 meters.
const colors = makeColorRamp(); // Use whatever library to generate the ramp.
const colorMap = new ColorMap(colors, 0, 2500, ColorMapMode.Elevation);

const texture = colorMap.getTexture();

// Disable the color map.
colorMap.active = false;

// When finished with this color map, dispose it.
colorMap.dispose();

Hierarchy (view full)

Constructors

Accessors

  • get mode(): ColorMapMode
  • Gets or sets the color map mode.

    Returns ColorMapMode

    // Start with an elevation gradient, ranging from 100 to 1500 meters.
    const colorMap = new ColorMap(colors, 100, 1500, ColorMapMode.Elevation);

    // Change mode to slope, and set min and max to 0-90 degrees.
    colorMap.mode = ColorMapMode.Slope;
    colorMap.min = 0;
    colorMap.max = 90;
  • set mode(v): void
  • Parameters

    Returns void

  • get opacity(): null | number[]
  • Gets or sets the opacity values of the color map.

    Note: if the provided array does not have the same length as the colors array, an exception is raised.

    Returns null | number[]

    null
    
  • set opacity(v): void
  • Parameters

    • v: null | number[]

    Returns void

Methods

  • Adds a listener to an event type.

    Type Parameters

    • T extends "updated"

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<ColorMapEvents[T], T, ColorMap>

      The function that gets called when the event is fired.

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void

  • Fire an event type.

    Type Parameters

    • T extends "updated"

    Parameters

    • event: BaseEvent<T> & ColorMapEvents[T]

      The event that gets fired.

    Returns void

  • Checks if listener is added to an event type.

    Type Parameters

    • T extends "updated"

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<ColorMapEvents[T], T, ColorMap>

      The function that gets called when the event is fired.

    Returns boolean

  • Type Parameters

    • T extends string

    Parameters

    Returns boolean

  • Removes a listener from an event type.

    Type Parameters

    • T extends "updated"

    Parameters

    • type: T

      The type of the listener that gets removed.

    • listener: EventListener<ColorMapEvents[T], T, ColorMap>

      The listener function that gets removed.

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void

  • Samples the colormap for the given value.

    Parameters

    • value: number

      The value to sample.

    Returns Color

    The color at the specified value.

  • Samples the transparency for the given value.

    Parameters

    • value: number

      The value to sample.

    Returns number

    The color at the specified value.