Home Identifier Source Repository
import {PaletteManager} from 'leaflet-coverage/renderers/palettes.js'
public class | source

PaletteManager

Manages palettes under common names.

Palettes can have different numbers of steps. Linear palettes can be conveniently added by supplying an array of CSS color specifications. Generic palettes can be added by directly supplying the step colors as RGB arrays.

Example:


var palettes = new PaletteManager({defaultSteps: 10})
palettes.addLinear('grayscale', ['#FFFFFF', '#000000']) // has 10 steps
palettes.addLinear('grayscalehd', ['#FFFFFF', '#000000'], {steps=1000}) // high-resolution palette
palettes.add('breweroranges3', ['#fee6ce', '#fdae6b', '#e6550d']) // palette of exactly those 3 colors
palettes.add('mycustom', {red: [0,255], green: [0,0], blue: [10,20]}) // different syntax

Note that Uint8Array typed arrays should be used for custom palettes (added via add()) to avoid internal transformation.

Constructor Summary

Public Constructor
public

constructor(defaultSteps: Integer)

Member Summary

Public Members
public get

Method Summary

Public Methods
public

add(name: *, palette: *)

Store a supplied generic palette under the given name.

public

addLinear(name: String, colors: Array, steps: Integer)

Store a linear palette under the given name created with the given CSS color specifications.

public

get(name: *): *

Return the palette stored under the given name, or throws an error if not found.

Public Constructors

public constructor(defaultSteps: Integer) source

Params:

NameTypeAttributeDescription
defaultSteps Integer

The default number of steps when adding palettes with addLinear().

Public Members

public get [Symbol.iterator]: * source

Public Methods

public add(name: *, palette: *) source

Store a supplied generic palette under the given name.

Params:

NameTypeAttributeDescription
name *

The unique name of the palette.

palette *

An object with red, green, and blue properties (each an array of [0,255] values), or an array of CSS color specifications.

public addLinear(name: String, colors: Array, steps: Integer) source

Store a linear palette under the given name created with the given CSS color specifications.

Params:

NameTypeAttributeDescription
name String

The unique name of the palette

colors Array

An array of CSS color specifications

steps Integer

Use a different number of steps than the default of this manager.

public get(name: *): * source

Return the palette stored under the given name, or throws an error if not found. The palette is an object with properties steps, red, green, and blue. Each of the color arrays is an Uint8Array of length steps.

Params:

NameTypeAttributeDescription
name *

Return:

*