import UniqueValueRenderer from "@arcgis/core/renderers/UniqueValueRenderer.js";const UniqueValueRenderer = await $arcgis.import("@arcgis/core/renderers/UniqueValueRenderer.js");- Since
- ArcGIS Maps SDK for JavaScript 4.0
UniqueValueRenderer allows you to symbolize features in a Layer based on one or more categorical attributes. This is typically done by using unique colors, fill styles, or images to represent features with equal values in a string field.
Supported layers
UniqueValueRenderer may only be used to create visualizations for the following layer types: FeatureLayer, SceneLayer, MapImageLayer, CSVLayer, GeoJSONLayer, OGCFeatureLayer, WFSLayer, StreamLayer, ImageryLayer, and ImageryTileLayer
At a minimum, this renderer requires you specify a field (or valueExpression) from which the unique types or categories originate. You must also specify expected values and their corresponding symbols using either uniqueValueInfos or uniqueValueGroups.
In the image below, each polyline is symbolized with a color depending on the road classification of each feature in a layer representing major highways. For example, blue features represent interstate highways (freeways), orange lines represent U.S. Highways, and pink lines represent state highways.
UniqueValueRenderer can also be used to visualize numeric data attributes in conjunction with unique values. This is accomplished with visual variables. Visual variables define the parameters for data-driven visualizations of numeric data. They allow you to easily map continuous ramps of color, size, and opacity to minimum and maximum data values from one of the layer's numeric attribute fields.
When used in a UniqueValueRenderer, the unique symbol types are typically defined with color while size and/or opacity visual variables are added to create a multivariate map. However, the SimpleFillSymbol.style of a symbol may be used as the primary representation of categories, so a color visual variable can be used for another attribute.
The example below uses a UniqueValueRenderer to shade each building feature with a color depending on its type (e.g. purple represents condominium, green represents hotels, orange is residential, etc.). A size visual variable is then added to depict the real-world height of each building.
To read more about visual variables see the visualVariables property.
Example
layer.renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "REGION", defaultSymbol: { type: "simple-fill" }, // autocasts as new SimpleFillSymbol() uniqueValueInfos: [{ // All features with value of "North" will be blue value: "North", symbol: { type: "simple-fill", // autocasts as new SimpleFillSymbol() color: "blue" } }, { // All features with value of "East" will be green value: "East", symbol: { type: "simple-fill", // autocasts as new SimpleFillSymbol() color: "green" } }, { // All features with value of "South" will be red value: "South", symbol: { type: "simple-fill", // autocasts as new SimpleFillSymbol() color: "red" } }, { // All features with value of "West" will be yellow value: "West", symbol: { type: "simple-fill", // autocasts as new SimpleFillSymbol() color: "yellow" } }], visualVariables: [{ type: "opacity", field: "POPULATION", normalizationField: "SQ_KM", // features with 30 ppl/sq km or below are assigned the first opacity value stops: [{ value: 100, opacity: 0.15 }, { value: 1000, opacity: 0.90 }] }]};Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Example
// Typical usagelet renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "fieldName", uniqueValueInfos: [ ]};Properties
| Property | Type | Class |
|---|---|---|
authoringInfo inherited | ||
FillSymbol | PolygonSymbol3D | CIMSymbol | null | undefined | | |
declaredClass readonly inherited | ||
| | ||
SymbolUnion | null | undefined | | |
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
type readonly | "unique-value" | |
UniqueValueGroup[] | null | undefined | | |
UniqueValueInfo[] | null | undefined | | |
| | ||
| | ||
visualVariables inherited | VisualVariable[] | null | undefined |
authoringInfo
- Type
- AuthoringInfo | null | undefined
Authoring metadata only included in renderers generated from one of the Smart Mapping creator methods, such as sizeRendererCreator.createContinuousRenderer() or colorRendererCreator.createContinuousRenderer(). This includes information from UI elements such as sliders and selected classification methods and themes. This allows the authoring clients to save specific overridable settings so that next time it is accessed via the UI, their selections can be remembered.
backgroundFillSymbol
- Type
- FillSymbol | PolygonSymbol3D | CIMSymbol | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.7
This property is only relevant when symbolizing polygon features with marker symbols (or IconSymbol3DLayer) in the uniqueValueInfos of this renderer. This is usually done when adding a SizeVariable to the visualVariables) in a bivariate visualization (color indicates a type-based value and size indicates the value of a separate numeric field). Use this property to set a background FillSymbol (or PolygonSymbol3D if visualizing data in 3D) to visualize the boundaries of each polygon.
Support for CIMSymbol was added at version 4.31 and is limited to 2D MapView.
Example
// this symbol will be applied to all features. It is only// necessary when visualizing polygon data with icons.renderer.backgroundFillSymbol = { type: "simple-fill", outline: { width: 1, color: "gray" }}; defaultLabel
The label used in the Legend to describe features assigned the default symbol. The default symbol is used to draw all features with values not referenced by uniqueValueInfos or uniqueValueGroups.
defaultSymbol
- Type
- SymbolUnion | null | undefined
The symbol used to draw
all features with values not referenced by uniqueValueInfos or
uniqueValueGroups. If null, unmatched features will not be assigned a symbol.
Known Limitations
SceneLayers with a mesh SceneLayer.geometryType
will display unmatching features with a generic symbol even if the defaultSymbol is
null.
field
The name of the attribute field containing types or categorical values referenced in uniqueValueInfos or uniqueValueGroups.
Example
let renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "RANK", // contains values referenced in uniqueValueInfos uniqueValueInfos: [ { value: "high", // features labeled as "high" symbol: sym1 // will be assigned sym1 }, { value: "medium", // features labeled as "medium" symbol: sym2 // will be assigned sym2 }, { value: "low", // features labeled as "low" symbol: sym3 // will be assigned sym2 } ]}; field2
Specifies the name of an additional attribute field used to categorize features.
All combinations of field and field2 values are unique categories and
may have their own symbol.
When defining a set of uniqueValueInfos, a fieldDelimiter must be specified.
- See also
Examples
// categorizes combinations of values in field and field2 with uniqueValueInfoslet renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "REGION", field2: "RANK", fieldDelimiter: ", ", // comma + space used to separate values from all fields uniqueValueInfos: [ { value: "North, 1", // features in the "North" region and a rank of 1 symbol: sym1 // will be assigned sym1 }, { value: "North, 2", // features in the "North" region and a rank of 2 symbol: sym2 // will be assigned sym2 }, { value: "South, 1", // features in the "South" region and a rank of 1 symbol: sym3 // will be assigned sym3 }, { value: "South, 2", // features in the "South" region and a rank of 2 symbol: sym4 // will be assigned sym4 } ]};// categorizes combinations of values in field and field2 with uniqueValueGroupslet renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "Obesity_prevalence", // values are either "high" or "low" field2: "Diabetes_prevalence", // values are either "high" or "low" uniqueValueGroups: [{ classes: [{ symbol: { // an object of common symbol properties ...commonProperties, color: "yellow" }, label: "Low obesity; Low diabetes", values: { value: "low", value2: "low" } }, { symbol: { ...commonProperties, color: "orange" }, label: "Low obesity; High diabetes", values: { value: "low", value2: "high" } }, { symbol: { ...commonProperties, color: "red" }, label: "High obesity; Low diabetes", values: { value: "high", value2: "low" } }, { symbol: { ...commonProperties, color: "purple" }, label: "High obesity; High diabetes", values: { value: "high", value2: "high" } }] }]}; field3
Specifies the name of a third attribute field used to categorize features.
All combinations of field, field2, and field3 values are unique categories and
may have their own symbol.
When defining a set of uniqueValueInfos, a fieldDelimiter must be specified.
- See also
Examples
// categorizes combinations of values in field, field2, and field3 with uniqueValueInfoslet renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "REGION", field2: "RANK", field3: "CLASS", fieldDelimiter: " | ", // pipe symbol padded with spaces used to separate values from all fields uniqueValueInfos: [ { value: "North | 1 | medium", // features in the "North" region, a rank of 1, and "medium" class symbol: sym1 // will be assigned sym1 }, { value: "North | 2 | medium", // features in the "North" region, a rank of 2, and a "medium class symbol: sym2 // will be assigned sym2 }, ... ]};// categorizes combinations of values in field, field2, and field3 with uniqueValueGroupslet renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "Obesity_prevalence", // values are either "high" or "low" field2: "Diabetes_prevalence", // values are either "high" or "low" field3: "Alcohol_nat_avg" // values are either "above" or "below" national average uniqueValueGroups: [{ classes: [{ symbol: { // an object of common symbol properties ...commonProperties, color: "yellow" }, label: "Low obesity; Low diabetes; Low alcohol", values: { value: "low", value2: "low", value3: "low" } }, { symbol: { ...commonProperties, color: "orange" }, label: "Low obesity; High diabetes; High alcohol", values: { value: "low", value2: "high", value3: "high" } }] }]}; fieldDelimiter
A string used as a separator between the values in the legend if multiple attribute fields are used to categorize values. This property only applies when uniqueValueInfos are used to categorize values. It does not apply for uniqueValueGroups.
By default, a comma is used as the field delimiter if field and field2 are defined (since version 4.25).
Example
let renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "REGION", field2: "RANK", fieldDelimiter: ", ", // comma + space used to separate values from all fields uniqueValueInfos: [ { value: "North, 1", // features in the "North" region and a rank of 1 symbol: sym1 // will be assigned sym1 }, { value: "North, 2", // features in the "North" region and a rank of 2 symbol: sym2 // will be assigned sym2 }, ... ]}; legendOptions
- Type
- RendererLegendOptions | null | undefined
An object providing options for displaying the renderer in the Legend.
Example
renderer.legendOptions = { title: "Classification", order: "descending-values",}; orderByClassesEnabled
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.26
Indicates whether the order of the classes or uniqueValueInfos in the renderer definition should be used for the feature drawing order of the layer. If FeatureLayer.orderBy is set on the layer, then the drawing order specified in that property will take precedence over this property.
- Default value
- false
Example
renderer.orderByClassesEnabled = true; uniqueValueGroups
- Type
- UniqueValueGroup[] | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.25
An array of objects defining groups of unique values. This is required if you want to group sets of unique values under subheadings. Unique value groups also allow you to combine or merge multiple unique values to a single class so they are represented by one symbol and one label.
This property should be used in favor of uniqueValueInfos.
Example
layer.renderer = { type: "unique-value", field: "zonecode", uniqueValueGroups: [{ heading: "Commercial", classes: [{ label: "C-2 | Community Commercial", symbol: createSymbol([255,179,219]), values: ["C-1", "C-2"] }, { label: "C-3 | Major Commercial", symbol: createSymbol([255,0,0]), values: "C-3" }] }, { heading: "Residential", classes: [{ label: "R-1 | Low-Density Residential", symbol: createSymbol([255,255,224]), values: "R-1" }, { label: "R-3 | Limited High-Density Residential", symbol: createSymbol([255,214,0]), values: "R-3" }, { label: "R-4 | High-Density Residential", symbol: createSymbol([255,166,0]), values: "R-4", }] }, { heading: "Other", classes: [{ label: "S | Special Area", symbol: createSymbol([161,237,237]), values: ["S-DW", "S-DR", "S-RP", "S-JW", "S-RN", "S-WS"] }] }]}; uniqueValueInfos
- Type
- UniqueValueInfo[] | null | undefined
Defines categories and their corresponding symbols based on a set of values expected from the provided field or valueExpression.
Example
layer.renderer = { type: "unique-value", field: "zonecode", uniqueValueInfos: [{ label: "C-2 | Community Commercial", symbol: createSymbol([255,179,219]), value: "C-2" }, { label: "C-3 | Major Commercial", symbol: createSymbol([255,0,0]), value: "C-3" }, { label: "R-1 | Low-Density Residential", symbol: createSymbol([255,255,224]), value: "R-1" }, { label: "R-3 | Limited High-Density Residential", symbol: createSymbol([255,214,0]), value: "R-3" }, { label: "R-4 | High-Density Residential", symbol: createSymbol([255,166,0]), value: "R-4" }]}; valueExpression
An Arcade expression following the specification
defined by the Arcade Visualization Profile. Expressions
in UniqueValueRenderer may reference field values using the $feature profile variable
and must return a string or a number.
The values returned from this expression should match categories defined in uniqueValueInfos or uniqueValueGroups.
This property is typically used as an alternative to field for data-driven visualizations.
- See also
Example
let renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() valueExpression: "When($feature.count < 20, 'low', $feature.count >= 20 && $feature.count < 70, 'moderate', $feature.count >=70, 'high', 'other')", uniqueValueInfos: [ ... ], // assigns symbols to features evaluating to 'low', 'moderate', or 'high'}; valueExpressionTitle
The title identifying and describing the associated Arcade
expression as defined in the valueExpression property. This is displayed
as the title of the categories or groups in the Legend
in the absence of a provided title in the legendOptions property.
Example
renderer.valueExpression = "IIF($feature.POP > 500000, 'high', 'low')";renderer.valueExpressionTitle = "Classification"; visualVariables
- Type
- VisualVariable[] | null | undefined
An array of VisualVariable objects. Each object must indicate the type of visual variable to apply (e.g. ColorVisualVariable, SizeVisualVariable, OpacityVisualVariable, RotationVisualVariable), the numeric field or expression from which to drive the visualization, and the visual values to map to the data. The following list identifies each visual variable type and provides a link to the specification table of each.
| Type | Object Specification | Legend Example |
|---|---|---|
| color | ColorVisualVariable | ![]() |
| size | SizeVisualVariable | ![]() |
| opacity | OpacityVisualVariable | ![]() |
| rotation | RotationVisualVariable | - |
Visual variables are primarily be used in two ways.
1. Thematic mapping
In most cases, visual variables are used to create visualizations based on a thematic attribute (e.g. population, education, rank, money, magnitude, etc.) in either 2D or 3D.
renderer.visualVariables = [{ type: "size", field: "POP_POVERTY", normalizationField: "TOTPOP_CY", legendOptions: { title: "% population in poverty by county" }, stops: [ { value: 0.15, size: 4, label: "<15%" }, { value: 0.25, size: 12, label: "25%" }, { value: 0.35, size: 24, label: ">35%" } ]}];You can take the visualization a step further and use multiple visual variables in the same renderer. The sample below uses three visual variables (size, color, and opacity).
2. Mapping real-world sizes
The size visual variable can be used to visualize the true sizes of features (e.g. tree canopy, road width, building height, etc.) based on their size in the real world. This can be particularly powerful when working in a 3D SceneView. The image below shows a layer of trees that uses visual variables to size each feature to the true dimensions of each tree based on data stored in multiple attribute fields.
See the Thematic visualization with realistic 3D symbols for an example of using multiple visual variables to visualize your data.
Known Limitations
Color and opacity visual variables must not have more than 8 stops and size visual variables must not have more than 6 stops. This does not apply to variables driven by view scale.
For apps where users can interactively change the field or valueExpression of a visual variable, we suggest
you include all potential fields referenced by visual variables in the FeatureLayer.outFields
of the layer. This ensures the best user experience when switching or updating fields in renderers.
- See also
Methods
| Method | Signature | Class |
|---|---|---|
fromJSON inherited static | fromJSON(json: any): any | |
addUniqueValueInfo(valueOrInfo: string | UniqueValueInfoProperties, symbol?: SymbolUnionProperties): void | | |
clone(): UniqueValueRenderer | | |
getUniqueValueInfo(graphic: Graphic): Promise<UniqueValueInfo> | | |
removeUniqueValueInfo(value: string | number): void | | |
toJSON inherited | toJSON(): any |
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
addUniqueValueInfo
- Signature
-
addUniqueValueInfo (valueOrInfo: string | UniqueValueInfoProperties, symbol?: SymbolUnionProperties): void
Adds a unique value and symbol to the renderer. You can provide the value and its associated symbol as individual arguments or as an info object.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| valueOrInfo | The value to match. The value can be provided as an individual argument or as an info object described in uniqueValueInfos. | | |
| symbol | The symbol used to represent features matching the
specified | |
- Returns
- void
Examples
let renderer = { type: "unique-value", // autocasts as new UniqueValueRenderer() field: "REGION", defaultSymbol: { type: "simple-fill" } // autocasts as new SimpleFillSymbol()};// Add a unique value info for the "North" region// using individual function argumentsrenderer.addUniqueValueInfo({ value: "North", symbol: { type: "simple-fill", // autocasts as new SimpleFillSymbol() color: "blue" }});// Add a unique value info for the "West" region// using a unique info objectrenderer.addUniqueValueInfo({ value: "West", symbol: new SimpleFillSymbol({ color: "yellow" }), label: "West region" // will display this text in legend}); clone
- Signature
-
clone (): UniqueValueRenderer
Creates a deep clone of the renderer.
- Returns
- UniqueValueRenderer
A deep clone of the object that invoked this method.
Example
// Creates a deep clone of the first layer's rendererlet renderer = view.map.layers.at(0).renderer.clone(); getUniqueValueInfo
- Signature
-
getUniqueValueInfo (graphic: Graphic): Promise<UniqueValueInfo>
Returns rendering and legend information (as defined by the renderer) associated with the given graphic.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| graphic | The graphic whose rendering and legend information will be returned. | |
- Returns
- Promise<UniqueValueInfo>
Resolves to an object describing the UniqueValueInfo object to which the input graphic belongs as defined by the renderer.
Example
view.on("click", function(event){ view.hitTest(event) .then(function(hitResponse){ const resultGraphic = hitResponse.results[0].graphic; // assumes the layer's renderer is a UniqueValueRenderer instance return layer.renderer.getUniqueValueInfo(resultGraphic); }).then(function(uniqueValueInfo){ // returns the unique value info to which the graphic belongs. });}); removeUniqueValueInfo
- Signature
-
removeUniqueValueInfo (value: string | number): void
Removes a unique value from the renderer.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| value | Value to remove from uniqueValueInfos. | |
- Returns
- void
Example
// removes the unique value info object for// features in the West region. They will now// be displayed with the default symbol and labelrenderer.removeUniqueValueInfo("West"); toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.







