import { getColorsFromRenderer, getColorsForRendererValues } from "@arcgis/core/renderers/support/utils.js";const { getColorsFromRenderer, getColorsForRendererValues } = await $arcgis.import("@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
| Name | Return Type | Object |
|---|---|---|
| | ||
| | |
| | |
| |
getColorsFromRenderer
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
| Parameter | Type | Description | Required |
|---|---|---|---|
| renderer | The renderer from which to extract fields and their associated matching colors. | |
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
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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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
A Map object that holds a renderer value and its corresponding color. Type definition for FieldToValueColorMap.
FieldToValueColorMap
A mapping of the field or Arcade expression to a ValueToColorMap object.
- Supertypes
- Map<string‚ ValueToColorMap>