Skip to content
import { getColorsFromRenderer, getColorsForRendererValues } from "@arcgis/core/renderers/support/utils.js";
Since
ArcGIS Maps SDK for JavaScript 4.28

Various utilities for accessing renderer colors that match to fields, Arcade expressions, or values.

Functions

getColorsFromRenderer

Function

Resolves with a Map of fields matched to the color that the field is represented by in the renderer. If the renderer has a default symbol, the string returned in the map will be "default".

Signature
getColorsFromRenderer (renderer: RendererUnion | null | undefined): Promise<Map<string, (Color | null | undefined)[]>>
Parameters
ParameterTypeDescriptionRequired
renderer

The renderer from which to extract fields and their associated matching colors.

Returns
Promise<Map<string, (Color | null | undefined)[]>>

Resolves with a Map of string fields matched to the color that the field is represented by in the renderer. If there is no color matching to a field key, the value will be null.

Example
const fieldToColorMap = await rendererUtils.getColorsFromRenderer(renderer);
// Loop through the returned fieldToColorMap to access the fields and their matching color.
for (const field in Object.fromEntries(fieldToColorMap)) {
const color = fieldToColorMap.get(field);
}

getColorsForRendererValues

Function

Resolves with a FieldToValueColorMap that contains the fields and a map of values to its matched color in the renderer. If the renderer has a default symbol, the string value in the returned FieldToValueColorMap will be "default".

Signature
getColorsForRendererValues (renderer: RendererUnion | null | undefined): Promise<FieldToValueColorMap>
Parameters
ParameterTypeDescriptionRequired
renderer

The renderer from which to match values with their associated colors.

Returns
Promise<FieldToValueColorMap>

Resolves with a FieldToValueColorMap.

Example
const fieldToValueColorMap = await rendererUtils.getColorsForRendererValues(renderer);
// Loop through the returned fieldToValueColorMap to access the fields and their matching ValueToColorMap object.
for (const expressionOrField in Object.fromEntries(fieldToValueColorMap)) {
const valueToColorMap = fieldToValueColorMap.get(expressionOrField);
}

Type definitions

ValueToColorMap

Type definition

A Map object that holds a renderer value and its corresponding color. Type definition for FieldToValueColorMap.

Supertypes
Map<string | number | null | undefined‚ Color | null | undefined>

FieldToValueColorMap

Type definition

A mapping of the field or Arcade expression to a ValueToColorMap object.

Supertypes
Map<string‚ ValueToColorMap>