Class UniqueValueRenderer
- java.lang.Object
-
- com.esri.arcgisruntime.symbology.Renderer
-
- com.esri.arcgisruntime.symbology.UniqueValueRenderer
-
- All Implemented Interfaces:
JsonSerializable
public final class UniqueValueRenderer extends Renderer
A UniqueValueRenderer symbolizes groups of geoelements that have matching attributes. This is most common with nominal, or string data.A UniqueValueRenderer is used for drawing multiple geoelements with different Symbols and matches field names from the UniqueValueRenderer to the values from the UniqueValues. An example: using a UniqueValueRenderer to symbolize zoning designations: yellow for "Residential", purple for "Industrial", red for "Commercial", and so on.
Properties of a UniqueValueRender:
- Field Names - what key, in a key/value pair, to look for when searching a geoelement's attributes.
- UniqueValues - tells which value, in a key/value pair, from a geoelement's attributes is assigned to what Symbol.
- Default Label - a default label that a geoelement will be given if not assigned a UniqueValue.
- Default Symbol - a default Symbol that a geoelement will be given if not assigned a UniqueValue.
Example of using a UniqueValueRenderer with a GraphicsOverlay:
// colors for symbols int BLACK = 0xFF000000; int RED = 0xFFFF0000; int BLUE = 0xFF0000FF; ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvas()); GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); mapView.getGraphicsOverlays().add(graphicsOverlay); SimpleMarkerSymbol redMarker = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, RED, 10); SimpleMarkerSymbol blueMarker = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, BLUE, 10); SimpleMarkerSymbol defaultMarker = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CROSS, BLACK, 10); UniqueValueRenderer uniqueValRenderer = new UniqueValueRenderer(null, null, null, defaultMarker); uniqueValRenderer.getFieldNames().add("COLOR"); List<Object> redValue = new ArrayList<>(); redValue.add("RED"); UniqueValueRenderer.UniqueValue redUV = new UniqueValueRenderer.UniqueValue("Color: Red", "Red", redMarker, redValue); uniqueValRenderer.getUniqueValues().add(redUV); List<Object> blueValue = new ArrayList<>(); blueValue.add("BLUE"); UniqueValueRenderer.UniqueValue blueUV = new UniqueValueRenderer.UniqueValue("Color: Blue", "Blue", blueMarker, blueValue); uniqueValRenderer.getUniqueValues().add(blueUV); graphicsOverlay.setRenderer(uniqueValRenderer); Point p1 = new Point(2000000, 2000000); Point p2 = new Point(3000000, 3000000); Graphic redGraphic = new Graphic(p1); Graphic blueGraphic = new Graphic(p2); redGraphic.getAttributes().put("COLOR", "RED"); blueGraphic.getAttributes().put("COLOR", "BLUE"); graphicsOverlay.getGraphics().add(redGraphic); graphicsOverlay.getGraphics().add(blueGraphic);
Note 1: the field name must match the key for the Graphic Attribute:uniqueValRenderer.getFieldNames().add("COLOR"); redGraphic.getAttributes().put("COLOR", "RED");
Note 2: the UniqueValue must match the value of the Graphic Attribute:List<Object> redValue = new ArrayList<>(); redValue.add("RED"); redGraphic.getAttributes().put("COLOR", "RED");
- Since:
- 100.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UniqueValueRenderer.UniqueValue
A UniqueValue object that is used in a UniqueValueRenderer.-
Nested classes/interfaces inherited from class com.esri.arcgisruntime.symbology.Renderer
Renderer.SceneProperties
-
-
Constructor Summary
Constructors Constructor Description UniqueValueRenderer()
Creates a new UniqueValueRenderer with given default properties: Field Names, an empty list. Unique Values, an empty list. Default Label, an empty string Default Symbol, nullUniqueValueRenderer(java.lang.Iterable<java.lang.String> fieldNames, java.lang.Iterable<UniqueValueRenderer.UniqueValue> uniqueValues, java.lang.String defaultLabel, Symbol defaultSymbol)
Creates a new UniqueValueRenderer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDefaultLabel()
Gets the label that is the default label for this Renderer.Symbol
getDefaultSymbol()
Gets the Symbol that is the default Symbol for this Renderer.java.util.List<java.lang.String>
getFieldNames()
Gets the names that this Renderer uses to match geoelements to their corresponding UniqueValue.Symbol
getSymbol(Feature feature)
Gets the Symbol used to display the given Feature.Symbol
getSymbol(Graphic graphic)
Gets the Symbol used to display the given Graphic.java.util.List<UniqueValueRenderer.UniqueValue>
getUniqueValues()
Gets the UniqueValues that this Renderer is using.void
setDefaultLabel(java.lang.String defaultLabel)
Sets the label that will be the default label for this Renderer.void
setDefaultSymbol(Symbol defaultSymbol)
Sets the Symbol that will be the default Symbol for this Renderer.-
Methods inherited from class com.esri.arcgisruntime.symbology.Renderer
fromJson, getRotationExpression, getRotationType, getSceneProperties, getSymbol, getSymbol, getUnknownJson, getUnsupportedJson, setRotationExpression, setRotationType, toJson
-
-
-
-
Constructor Detail
-
UniqueValueRenderer
public UniqueValueRenderer()
Creates a new UniqueValueRenderer with given default properties:- Field Names, an empty list.
- Unique Values, an empty list.
- Default Label, an empty string
- Default Symbol, null
The default Symbol can be set by itself and any geoelements that use this Renderer will be drawn with that Symbol.
- Since:
- 100.0.0
-
UniqueValueRenderer
public UniqueValueRenderer(java.lang.Iterable<java.lang.String> fieldNames, java.lang.Iterable<UniqueValueRenderer.UniqueValue> uniqueValues, java.lang.String defaultLabel, Symbol defaultSymbol)
Creates a new UniqueValueRenderer.Geoelements are rendered to the GeoView by matching their field names with the corresponding UniqueValue's value.
The default values are set to geoelements that use this Renderer if no UniqueValues are set or those geoelements that don't fall within the UniqueValues range
- Parameters:
fieldNames
- field names used to match values, can be null or emptyuniqueValues
- values to be used for matching, can be null or emptydefaultLabel
- the default label for geoelements that use this Renderer.defaultSymbol
- the default Symbol for geoelements that use this Renderer, can be null- Since:
- 100.0.0
-
-
Method Detail
-
getDefaultLabel
public java.lang.String getDefaultLabel()
Gets the label that is the default label for this Renderer.The default value is a empty string.
- Returns:
- the default label
- Since:
- 100.0.0
- See Also:
setDefaultLabel(java.lang.String)
-
setDefaultLabel
public void setDefaultLabel(java.lang.String defaultLabel)
Sets the label that will be the default label for this Renderer.This label will represent a default name for any geoelement that doesn't have a label assigned to it.
A geoelement will have this default label applied to them if no values are set or they don't fall within the UniqueValues range.
- Parameters:
defaultLabel
- the default label, can be null- Since:
- 100.0.0
-
getDefaultSymbol
public Symbol getDefaultSymbol()
Gets the Symbol that is the default Symbol for this Renderer.The default value is null.
- Returns:
- the default Symbol used by this Renderer
- Since:
- 100.0.0
- See Also:
setDefaultSymbol(com.esri.arcgisruntime.symbology.Symbol)
-
setDefaultSymbol
public void setDefaultSymbol(Symbol defaultSymbol)
Sets the Symbol that will be the default Symbol for this Renderer.A geoelement will be set to this default Symbol if no values are set or a geoelement doesn't fall within the UniqueValues range.
- Parameters:
defaultSymbol
- the default Symbol for this Renderer, can be null- Since:
- 100.0.0
-
getFieldNames
public java.util.List<java.lang.String> getFieldNames()
Gets the names that this Renderer uses to match geoelements to their corresponding UniqueValue.These names will be used as a key, in a key/value pair, to search geoelements' attributes to locate which geoelements that this name is referring to.
The returned list is modifiable. If this Renderer has no field names then an empty iterable list will be returned. The list is also returned in the same order in which the corresponding list of UniqueValues are retrieved.
- Returns:
- a list of the field names used with this Renderer
- Since:
- 100.0.0
-
getUniqueValues
public java.util.List<UniqueValueRenderer.UniqueValue> getUniqueValues()
Gets the UniqueValues that this Renderer is using.These values tell what Symbol will be applied to what value. Each UniqueValue also comes with a Label and a description of what the UniqueValue does or represents.
The returned list is modifiable. If this Renderer has no UniqueValues then an empty iterable list will be returned.
- Returns:
- a list of UniqueValues, if any
- Since:
- 100.0.0
-
getSymbol
public Symbol getSymbol(Feature feature)
Gets the Symbol used to display the given Feature.- Specified by:
getSymbol
in classRenderer
- Parameters:
feature
- the Feature to get a Symbol from, not null- Returns:
- the Symbol of the Feature that was passed
- Throws:
java.lang.IllegalArgumentException
- if feature is null- Since:
- 100.0.0
- See Also:
Renderer.getSymbol(com.esri.arcgisruntime.data.Feature)
-
getSymbol
public Symbol getSymbol(Graphic graphic)
Gets the Symbol used to display the given Graphic.- Specified by:
getSymbol
in classRenderer
- Parameters:
graphic
- the Graphic to get a Symbol from, not null- Returns:
- the Symbol of the Graphic that was passed
- Throws:
java.lang.IllegalArgumentException
- if graphic is null- Since:
- 100.0.0
- See Also:
Renderer.getSymbol(com.esri.arcgisruntime.mapping.view.Graphic)
-
-