Optionalopts: {Optionalcontinuous?: booleanOptionalmax?: numberOptionalmin?: numberOptionalmissingColor?: stringOptionalpalette?: string | string[]a PALETTES/registered name, or a custom array of >=2 hex colors
Optionalsource?: "palette" | "custom" | "gdal"Optionalstops?: {explicit stops; presence switches to explicit mode
Optionalunit?: stringIs interpolation on? A read-only flag — write it with set({ continuous }).
Resolve any value → css color string. colorFor wins; a value that isn't one resolves to
missingColor (or null); null when nothing matches.
band index (as returned by getStops())
Hot-path [r,g,b] for the render loop; null → pixel is transparent (no matching stop, or an
absent value with no missingColor).
[{ min?, max?, value?, color, label }] — explicit→stored | palette→derived | colorStops→one
{ value, color } per control point (setColorStops).
THE knob writer. One mutation idiom for every whole-object knob:
cs.set({ palette: 'viridis', min: 0, max: 46, continuous: true, unit: 'm' });
Sync and chainable (returns this) — a ColorScale is a pure value type, so nothing here awaits.
Fires onChange ONCE for the whole batch, not once per key, so a repaint hook wired via
onChange doesn't redraw N times for one logical edit.
Recognised keys: palette, min, max, continuous, unit, stops, colorStops
({values, colors}). stops/colorStops are MODE switches and remain available as the explicit
setStops()/setColorStops() methods too; the INDEX-addressed ops (setColor(i,·),
setRange(i,·), setLabel(i,·)) are not knobs and stay as their own verbs.
An unknown key throws, naming the recognised set, rather than being silently ignored.
Optionalpatch: {band index
Define a CONTINUOUS color gradient via explicit control points — arbitrary breakpoint VALUES (need not be evenly spaced, or even given in order — sorted internally), each paired with its own color. Distinct from setStops(): that's discrete, flat bands (one solid color per range/value, no interpolation); this interpolates smoothly between the nearest bracketing pair when set({continuous:true}) is set (the intended pairing) — setColorStops([-1, 0, 1], ['#015498', '#ffffff', '#21bf90']).set({ continuous: true }) gives a diverging blue→white→green gradient skewed however the control points are spaced, not an even 3-way split of some [min,max]. Values outside the outermost control point clamp to that end's color (no extrapolation). With continuous false, a value takes the NEAREST control point's color instead of interpolating — flat, but not "banded" in the setStops() sense, since these are point positions, not ranges.
set({min,max})'s domain keeps governing peripheral things (a legend axis label, a stats-classification range) but the actual color mapping is driven entirely by these control points, not by min/max — the two are complementary, not conflicting: set both if you want a labeled axis range that differs from where the color control points themselves sit.
breakpoint values; >= 2 required
one "#rrggbb" hex color per value, same length as values
band index
band index
A plain, structured-cloneable description of this scale — enough to rebuild an equivalent one
with new ColorScale(spec). It captures whichever of the three modes is active.
This is a COPY, not a handle: rebuilding from it gives an independent scale, so two layers
built from one spec can diverge. colorFor (a function) and onChange listeners are
deliberately not included — neither survives serialization.
StaticfromOptionalunit: string = ""StaticfromRebuild a scale from toJSON() output. Restores the continuous-control-point mode too, which
the constructor alone cannot express.
StaticgetThe registered GDAL legend parser, or null if nothing has registered one yet.
StaticpalettesEvery palette name available to { palette } — the built-ins plus anything registered.
StaticregisterRegister the GDAL_METADATA XML parser used to auto-detect an embedded legend. Called by layers/depthMap.js on import.
StaticregisterAdd a palette by name. colors: >= 2 hex strings.
the colour for a value that ISN'T one:
null/undefined/NaN/''.null(the default) means "no colour" — the consumer decides what absent looks like (a vector layer leaves the feature at its base style; a raster leaves the pixel transparent). Set it to render missing data explicitly, e.g. a grey "no data" swatch.