require(["esri/renderers/UniqueValueRenderer"], function(UniqueValueRenderer) { /* code goes here */ });
esri/renderer/Renderer |_esri/renderer/UniqueValueRenderer
Name | Summary |
---|---|
new UniqueValueRenderer(defaultSymbol, attributeField, attributeField2?, attributeField3?, fieldDelimeter?) | Creates a new UniqueValueRenderer object. |
new UniqueValueRenderer(json) | Creates a new Unique Value Renderer |
Name | Type | Summary |
---|---|---|
attributeField | String | Attribute field renderer uses to match values. |
attributeField2 | String | If needed, specify an additional attribute field the renderer uses to match values |
attributeField3 | String | If needed, specify an additional attribute field the renderer uses to match values |
colorInfo | Object | An object defining a color ramp used to render the layer. |
defaultLabel | String | Label for the default symbol used to draw unspecified values |
defaultSymbol | Symbol | Default symbol used when a value or break cannot be matched |
fieldDelimiter | String | String inserted between the values if multiple attribute fields are specified |
infos | Object[] | Each element in the array is an object that provides information about the unique values associated with the renderer. |
proportionalSymbolInfo | Object | Defines the proportional symbol rendering where feature size is proportional to data value. |
rotationInfo | Object | Defines how marker symbols are rotated. |
values | String[] | Deprecated at v2.0, use infos instead. An array of values defined for the renderer |
Name | Type | Summary |
---|---|---|
addValue(valueOrInfo, symbol?) | None | Adds a unique value and symbol. |
getColor(graphic) | Color | Gets the color for the Graphic. |
getRotationAngle(graphic) | Number | Returns the angle of rotation (in degrees) for the graphic calculated using rotationInfo. |
getSize(graphic) | Number | Return the symbol size (in pixels) for the graphic, calculated using proportionalSymbolInfo . |
getSymbol(graphic) | Symbol | Gets the symbol for the Graphic |
getUniqueValueInfo(graphic) | Object | Returns rendering and legend information (as defined by the renderer) associated with the given graphic |
removeValue(value) | None | Removes a unique value. |
setColorInfo(info) | Renderer | Sets the colorInfo property. |
setProportionalSymbolInfo(info) | Renderer | Modify proportional symbol info for the renderer. |
setRotationInfo(info) | Renderer | Modifies rotation info for the renderer. |
toJson() | Object | Converts object to its ArcGIS Server JSON representation. |
attributeField2
and attributeField3
.<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. |
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; }); ... });
<Object> json | Required | JSON object representing the UniqueValueRenderer. |
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); ... });
attributeField
value
and color
. value
a value in data range. color
is the color used to render the value. At least two stops are required.renderer.setColorInfo({ field: "M086_07", minDataValue: 0, maxDataValue: 100, colors: [ new Color([255, 255, 255]), new Color([127, 127, 0]) ] });
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. |
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:
If the data value represents a non-distance quantity (e.g.: traffic count, census data) then This property is required. |
valueRepresentation | String | Specifies what the data value measures if it represents a real world distance. The following values are supported:
This property is required if |
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. |
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] } });
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:
This property is optional. The default value is "geographic" |
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 | 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. |
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. |
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" }); ... });
<Graphic> graphic | Required | Graphic to get color from. |
<Graphic> graphic | Required | An input graphic for which you want to get the angle of rotation. |
proportionalSymbolInfo
. (Added at v3.7)<Graphic> graphic | Required | The graphic for which you want to calculate the symbol size. |
<Graphic> graphic | Required | Graphic to symbolize. Used when creating a custom renderer. |
<Graphic> graphic | Required | The graphic whose rendering and legend information will be returned. |
<String> value | Required | Value to remove. |
colorInfo
property. (Added at v3.8)<Object> info | Required | An info object that defines the color. It has the same properties as colorInfo . |
info
object has the same properties as proportionalSymbolInfo
.
For changes to take effect call the GraphicsLayer redraw
method after calling this method.
<Object> info | Required | An info object that defines the proportional symbol. The info argument has the same properties as proportionalSymbolInfo . |
rotationInfo
.
For the changes to take effect, you need to call GraphicsLayer.redraw
after calling this method. (Added at v3.7)
<Object> info | Required | An object with the same properties as rotationInfo . |