Hide Table of Contents
esri
Map
plugins
process
toolbars
workers
Class: UniqueValueRenderer
[ AMD Module Require | Legacy Module Require ]

require(["esri/renderers/UniqueValueRenderer"], function(UniqueValueRenderer) { /* code goes here */ });

Description

(Added at v1.4)
A unique value renderer symbolizes groups of graphics that have matching attributes. For more information about renderers, see Symbolizing graphics with renderers.

Samples

Search for samples that use this class.

Class hierarchy

esri/renderer/Renderer
|_esri/renderer/UniqueValueRenderer

Constructors

NameSummary
new UniqueValueRenderer(defaultSymbol, attributeField, attributeField2?, attributeField3?, fieldDelimeter?)Creates a new UniqueValueRenderer object.
new UniqueValueRenderer(json)Creates a new Unique Value Renderer

Properties

NameTypeSummary
attributeFieldStringAttribute field renderer uses to match values.
attributeField2StringIf needed, specify an additional attribute field the renderer uses to match values
attributeField3StringIf needed, specify an additional attribute field the renderer uses to match values
colorInfoObjectAn object defining a color ramp used to render the layer.
defaultLabelStringLabel for the default symbol used to draw unspecified values
defaultSymbolSymbolDefault symbol used when a value or break cannot be matched
fieldDelimiterStringString inserted between the values if multiple attribute fields are specified
infosObject[]

Each element in the array is an object that provides information about the unique values associated with the renderer.

proportionalSymbolInfoObjectDefines the proportional symbol rendering where feature size is proportional to data value.
rotationInfoObjectDefines how marker symbols are rotated.
valuesString[]Deprecated at v2.0, use infos instead. An array of values defined for the renderer

Methods

NameTypeSummary
addValue(valueOrInfo, symbol?)NoneAdds a unique value and symbol.
getColor(graphic)ColorGets the color for the Graphic.
getRotationAngle(graphic)NumberReturns the angle of rotation (in degrees) for the graphic calculated using rotationInfo.
getSize(graphic)NumberReturn the symbol size (in pixels) for the graphic, calculated using proportionalSymbolInfo.
getSymbol(graphic)SymbolGets the symbol for the Graphic
getUniqueValueInfo(graphic)ObjectReturns rendering and legend information (as defined by the renderer) associated with the given graphic
removeValue(value)NoneRemoves a unique value.
setColorInfo(info)RendererSets the colorInfo property.
setProportionalSymbolInfo(info)RendererModify proportional symbol info for the renderer.
setRotationInfo(info)RendererModifies rotation info for the renderer.
toJson()ObjectConverts object to its ArcGIS Server JSON representation.
Constructor Details

new UniqueValueRenderer(defaultSymbol, attributeField, attributeField2?, attributeField3?, fieldDelimeter?)

Creates a new UniqueValueRenderer object. Typically features are rendered based on the unique values of one attribute field. However up to three fields can be combined to generate a unique value. For example, if two fields are used which store the values A and B; and X, Y, and Z respectively, then the unique values for the renderer can be A:X, A:Y, A:Z, B:X, B:Y and B:Z, assuming ":" is the field delimiter.

Note: when using a function, do not specify values for attributeField2 and attributeField3.
Parameters:
<Symbol> defaultSymbol Required Default symbol for the renderer. This symbol is used for unmatched values. This parameter is required but can be null or an empty object.
<String | Function> attributeField Required Specify either the attribute field the renderer uses to match values or starting at version 3.3, a function that returns a value to be compared against unique values. If a function is specified the renderer will call this function once for every graphic drawn on the map. This can be used in cases where you want the unique values to be compared against a computed value that is not available via the attribute fields.
At version 3.0 the Class Breaks renderer can be used to render feature layer tracks. Specify the layer's trackIdField as the attributeField.
<String> attributeField2 Optional If needed, specify an additional attribute field the renderer uses to match values.
<String> attributeField3 Optional If needed, specify an additional attribute field the renderer uses to match values.
<String> fieldDelimeter Optional String inserted between the values of different fields. Applicable only when more than one attribute field is specifed for the renderer.
Sample:
require([
  "esri/renderers/UniqueValueRenderer", ... 
], function(UniqueValueRenderer, ... ) {
  var renderer = new UniqueValueRenderer(defaultSymbol, "SUB_REGION");
  ...
});

require([
  "esri/renderers/UniqueValueRenderer", ... 
], function(UniqueValueRenderer, ... ) {
  var renderer = new UniqueValueRenderer(defaultSymbol, function(feature){
    return feature.attributes.POP07_SQMI;
  });
  ...
});

new UniqueValueRenderer(json)

Creates a new Unique Value Renderer.
Parameters:
<Object> json Required JSON object representing the UniqueValueRenderer.
Sample:
require([
  "esri/renderers/UniqueValueRenderer", ... 
], function(UniqueValueRenderer, ... ) {
  var uvrJson = {"type": "uniqueValue",
    "field1": "SUB_REGION",
    "defaultSymbol": {
      "color": [0, 0, 0, 64],
      "outline": {
        "color": [0, 0, 0, 255],
        "width": 1,
        "type": "esriSLS",
        "style": "esriSLSNull"
      },
      "type": "esriSFS",
      "style": "esriSFSNull"
    },
    "uniqueValueInfos": [{
      "value": "Pacific",
      "symbol": {
        "color": [255, 0, 0, 128],
        "outline": {
          "color": [0, 0, 0, 255],
          "width": 1,
          "type": "esriSLS",
          "style": "esriSLSSolid"
        },
        "type": "esriSFS",
        "style": "esriSFSSolid"
      }
    }, {
      "value": "Mtn",
      "symbol": {
        "color": [0, 255, 0, 128],
        "outline": {
          "color": [0, 0, 0, 255],
          "width": 1,
          "type": "esriSLS",
          "style": "esriSLSSolid"
        },
        "type": "esriSFS",
        "style": "esriSFSSolid"
      }
    }]
  }
  var renderer = new UniqueValueRenderer(uvrJson);
  ...
});
Property Details

<String> attributeField

Attribute field renderer uses to match values. At version 3.0 the Unique Value renderer can be used to render feature layer tracks. Specify the layer's trackIdField as the attributeField

<String> attributeField2

If needed, specify an additional attribute field the renderer uses to match values. (Added at v2.0)

<String> attributeField3

If needed, specify an additional attribute field the renderer uses to match values. (Added at v2.0)

<Object> colorInfo

An object defining a color ramp used to render the layer. It has following properties:
  • <String> field: Name of the feature attribute field that contains the data value.
  • <String> normalizationField: Name of the feature attribute field by which the data value will be normalized.
  • <Number> minDataValue: Minimum data value.
  • <Number> maxDataValue: Maximum data value.
  • <Color[]> colors: An array of colors defining the color ramp. The first color will be used to render minimum data value, and the last color will be used to render maximum data value. At least two colors are required. If there are three or more colors, the intermediate colors will be placed proportionally between the first and the last to create a multi-color ramp.
  • <Object[]> stops: An array of objects defining the color ramp. Each object defines a stop on the color ramp and requires two properties: value and color. value a value in data range. color is the color used to render the value. At least two stops are required.
Specify either colors or stops to construct the color ramp. (Added at v3.8)
Sample:
renderer.setColorInfo({
  field: "M086_07",
  minDataValue: 0,
  maxDataValue: 100,
  colors: [
    new Color([255, 255, 255]),
    new Color([127, 127, 0])
  ]
});

<String> defaultLabel

Label for the default symbol used to draw unspecified values. (Added at v2.0)

<Symbol> defaultSymbol

Default symbol used when a value or break cannot be matched.

<String> fieldDelimiter

String inserted between the values if multiple attribute fields are specified. (Added at v2.0)

<Object[]> infos

Each element in the array is an object that provides information about the unique values associated with the renderer. The object has the following properties:

<String> value The unique value.
<Symbol> symbol The symbol used to display the value.
<String> label Label for the symbol used to draw the value.
<String> description Label for the symbol used to draw the value.
(Added at v2.0)

<Object> proportionalSymbolInfo

Defines the proportional symbol rendering where feature size is proportional to data value.

proportionalSymbolInfo supports the following properties

Property Type Description
field String or Function

Name of the feature attribute field that contains the data value. Or a function that returns the data value.

This property is required

valueUnit String

Unit of measurement if the data represents a real world distance quantity. Valid values are: "unknown","inches", "feet", "yards", "miles", "nautical-miles", "millimeters", "centimeters", "decimeters", "meters", "kilometers", "decimal-degrees"

If the data value represents a non-distance quantity (e.g.: traffic count, census data) then valueUnit should be set to "unknown".

This property is required.

valueRepresentation String Specifies what the data value measures if it represents a real world distance. The following values are supported:
  • radius: Data value represents the radius of a circular feature.
  • diameter: Data value represents the diameter of a circular feature.
  • area: Data value represents the area of a feature.
  • width: Data value represents the width of a line.
  • distance: Data value represents the distance from the center line (one half of the width).

This property is required if valueUnit is not equal to "unknown".

minDataValue Number Minimum data value. This property is required if valueUnit is set to "unknown".
minSize Number Symbol size (in pixels) to use for a feature when a minimum data value. This property is required if valueUnit is set to "unknown".
maxDataValue Number Maximum data value. This property is optional.
maxSize Number Maximum symbol size (in pixels). This property is optional.
normalizationField String Name of the feature attribute field used for data normalization. The data value obtained from field is divided by the value obtained from normalizationField before calculating the symbol size.

This property is optional.

legendOptions Object An object defining a color ramp used to render the layer. It has a property customValues, which is used when customized values in the legend are needed. See the sample section below for code example.

(Added at v3.7)
Sample: Proportional symbol rendering can be applied to two types of data:
  • Data that represents a distance quantity. For example:
    • If you have tree locations defined as points and an attribute field with the radius of tree canopy, you can use proportional symbols to depict the actual ground area covered by each tree.
    • You can use proportionally sized lines to depict the width of water mains.
  • Data that represents a non-distance quantity. For example:
    • Display traffic data like roads and highways as line symbols where stroke width is proportional to the traffic count.
    • Create a census map of proportional marker symbols where the area of each symbol reflects the population of the state.

In addition, regardless of the type of data described above, you can map a range of data values to a range of symbol sizes.

For point features, maker size is varied in proportion to the data value. For line features, stroke width is varied.

Data representing distance quantity:
 {
  field: "tree_canopy",
  valueUnit: "meters",
  valueRepresentation: "diameter"
 }
 //ground area covered by trees measured in square feet. 
 {
  field: "GroundArea", 
  valueUnit: "feet",
  valueRepresentation: "area"
 }

Specify minSize and maxSize to smooth out outliers.

Data representing a non-distance quantity.

 {
  field: "avg_daily_traffic",
  valueUnit: "unknown",
  minSize: 1000,
  minDataValue: 8
 }

Specify maxSize to smooth out outliers.

Map a range of data values to a range of symbol sizes:

{
 field: "avg_daily_traffic",
 valueUnit: "unknown",
 minSize: 1,
 maxSize: 10,
 minDataValue: 1000,
 maxDataValue: 100000
}
To use legendOptions:
renderer.setProportionalSymbolInfo({
  field: "POP_PER_DOC",
  minSize: 2,
  maxSize: 20,
  minDataValue: 100,
  maxDataValue: 10000,
  valueUnit: "unknown",
  legendOptions: {
    customValues: [100, 200, 300, 10000]
  }
});

<Object> rotationInfo

Defines how marker symbols are rotated. Use rotation to depict wind direction, vehicle heading etc. Specify an object with the following properties.
Property Type Description
field String or Function

Name of the feature attribute field that contains the angle of rotation. Or a function that returns the angle of rotation.

A function is useful in cases where the angle of rotation is not available in an attribute field but needs to be computed using a mathematical expression or formula. For example, you can specify a function to compute wind or current direction when the underlying data is stored as U or V vectors. View example below.

This property is required

type String

Defines the origin and direction of rotation depending on how the angle of rotation was measured. Can be one of the following:

  • geographic: rotates the symbol from the north in a clockwise direction.
  • arithmetic: rotates the symbol from the east in a counter-clockwise direction.

This property is optional. The default value is "geographic"

Examples:

Specify a field that contains the rotation values

{
 field: "WindDirection",
 type: "geographic"
}

Use a function to compute wind direction from wind vectors

{
 field: function(graphic){
  var U = graphic.attributes.U,
  V = graphic.attributes.V;

  //Oceanographic Convention
  return 360 + (180 / Math.PI) * Math.atan2(U,V);
 }
}
(Added at v3.7)

<String[]> values

Deprecated at v2.0, use infos instead. An array of values defined for the renderer.
Method Details

addValue(valueOrInfo, symbol?)

Adds a unique value and symbol. You can provide the value and its associated symbol as individual arguments or as an info object.
Parameters:
<String | Object> valueOrInfo Required Value to match with. The value can be provided as individual arguments or as an info object. See the object specifications table below for the structure of the info object.
<Symbol> symbol Optional Symbol used for the value.
Object Specifications:
valueOrInfos
description String Description for the symbol used to draw the value
label String Label for the symbol used to draw the value
symbol Symbol The symbol used to display the value
value String The unique value.
Sample:
require([
  "esri/renderers/UniqueValueRenderer", "esri/symbols/SimpleFillSymbol", ... 
], function(UniqueValueRenderer, SimpleFillSymbol, ... ) {
  //Specify the value and symbol as individual arguments.
  var renderer = new UniqueValueRenderer( ... );
  renderer.addValue("KS", symbol);

  //Specify the symbol and value using the info object.
  renderer.addValue({
    value: "KS",
    symbol: new SimpleFillSymbol(),
    label: "Kansas",
    description: "The Sunflower State"
  });
  ...
});

getColor(graphic)

Gets the color for the Graphic. (Added at v3.8)
Return value: Color
Parameters:
<Graphic> graphic Required Graphic to get color from.

getRotationAngle(graphic)

Returns the angle of rotation (in degrees) for the graphic calculated using rotationInfo. (Added at v3.7)
Return value: Number
Parameters:
<Graphic> graphic Required An input graphic for which you want to get the angle of rotation.

getSize(graphic)

Return the symbol size (in pixels) for the graphic, calculated using proportionalSymbolInfo. (Added at v3.7)
Return value: Number
Parameters:
<Graphic> graphic Required The graphic for which you want to calculate the symbol size.

getSymbol(graphic)

Gets the symbol for the Graphic.
Return value: Symbol
Parameters:
<Graphic> graphic Required Graphic to symbolize. Used when creating a custom renderer.

getUniqueValueInfo(graphic)

Returns rendering and legend information (as defined by the renderer) associated with the given graphic. (Added at v3.7)
Return value: Object
Parameters:
<Graphic> graphic Required The graphic whose rendering and legend information will be returned.

removeValue(value)

Removes a unique value. After making changes, you must refresh the graphic.
Parameters:
<String> value Required Value to remove.

setColorInfo(info)

Sets the colorInfo property. (Added at v3.8)
Return value: Renderer
Parameters:
<Object> info Required An info object that defines the color. It has the same properties as colorInfo.

setProportionalSymbolInfo(info)

Modify proportional symbol info for the renderer. The info object has the same properties as proportionalSymbolInfo.

For changes to take effect call the GraphicsLayer redraw method after calling this method.

(Added at v3.7)
Return value: Renderer
Parameters:
<Object> info Required An info object that defines the proportional symbol. The info argument has the same properties as proportionalSymbolInfo.

setRotationInfo(info)

Modifies rotation info for the renderer. The info argument has the same properties as rotationInfo.

For the changes to take effect, you need to call GraphicsLayer.redraw after calling this method. (Added at v3.7)

Return value: Renderer
Parameters:
<Object> info Required An object with the same properties as rotationInfo.

toJson()

Converts object to its ArcGIS Server JSON representation. Not supported for the TemporalRenderer. (Added at v2.1)
Return value: Object