utils

AMD: require(["esri/renderers/support/utils"], (rendererUtils) => { /* code goes here */ });
ESM: import * as rendererUtils from "@arcgis/core/renderers/support/utils.js";
Object: esri/renderers/support/utils
Since: ArcGIS Maps SDK for JavaScript 4.28

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

Method Overview

Name Return Type Summary Object

Resolves with a FieldToValueColorMap that contains the fields and a map of values to its matched color in the renderer.

utils
Promise<Map<string, Color[]>>

Resolves with a Map of fields matched to the color that the field is represented by in the renderer.

utils

Method Details

getColorsForRendererValues

Method
getColorsForRendererValues(renderer){Promise<FieldToValueColorMap>}

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".

Parameter

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

Returns
Type Description
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);
}

getColorsFromRenderer

Method
getColorsFromRenderer(renderer){Promise<Map<string, Color[]>>}

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".

Parameter

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

Returns
Type Description
Promise<Map<string, Color[]>> 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);
}

Type Definitions

FieldToValueColorMap

Type Definition
FieldToValueColorMap Map<string, ValueToColorMap>

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

ValueToColorMap

Type Definition
ValueToColorMap Map<(string|number), Color>

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

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