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 unique value renderer symbolizes geoelements with a distinct symbol for each unique data value in an attribute.

A unique value renderer contains a collection of UniqueValues. Each UniqueValueRenderer.UniqueValue has a Symbol and a collection of Values to define a value or combination of values.

This is typically used to visualize categories or data types. For example, you can use a unique value renderer to symbolize zoning designations: yellow for "Residential", purple for "Industrial", and green for both "Forests" and "Open land".

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(BasemapStyle.ARCGIS_LIGHT_GRAY);

 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
  • Constructor Details

    • UniqueValueRenderer

      public UniqueValueRenderer()
      Creates a new empty unique value renderer.

      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(Iterable<String> fieldNames, Iterable<UniqueValueRenderer.UniqueValue> uniqueValues, String defaultLabel, Symbol defaultSymbol)
      Creates a new unique value renderer.

      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 - a collection of the field names/attribute keys that the unique values apply to, may be null
      uniqueValues - a collection of unique values used by the renderer to select a symbol, may be null
      defaultLabel - the label used for the default symbol
      defaultSymbol - the default symbol for values that don't match any of the unique values, may be null
      Since:
      100.0.0
  • Method Details

    • getDefaultLabel

      public String getDefaultLabel()
      Gets the label used for the default symbol.

      The default value is a empty string.

      Returns:
      the default label
      Since:
      100.0.0
      See Also:
    • setDefaultLabel

      public void setDefaultLabel(String defaultLabel)
      Sets the label used for the default symbol.

      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 default symbol for values that don't match any of the unique values.

      The default value is null.

      Returns:
      the default Symbol used by this Renderer
      Since:
      100.0.0
      See Also:
    • setDefaultSymbol

      public void setDefaultSymbol(Symbol defaultSymbol)
      Sets the default symbol for values that don't match any of the unique values.

      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 List<String> getFieldNames()
      Gets a collection of the field names/attribute keys that the unique values apply to.

      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 collection of the field names/attribute keys that the unique values apply to
      Since:
      100.0.0
    • getUniqueValues

      public List<UniqueValueRenderer.UniqueValue> getUniqueValues()
      Gets a collection of unique values used by the renderer to select a symbol.

      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 collection of unique values used by the renderer to select a symbol
      Since:
      100.0.0
    • getSymbol

      public Symbol getSymbol(Feature feature)
      Returns the symbol that is used to visualize the given feature.

      If the renderer is a DictionaryRenderer and its associated DictionarySymbolStyle references a style file hosted on ArcGIS Online or an ArcGIS Enterprise portal (also referred to as a web style), this method returns null. If the layer has rendered and the symbol is already drawn on the view, this method returns a valid MultilayerSymbol. If you want to get the symbol before the layer is rendered, use DictionarySymbolStyle.getSymbolAsync(Map).

      Specified by:
      getSymbol in class Renderer
      Parameters:
      feature - the Feature to get a Symbol from, not null
      Returns:
      the Symbol of the Feature that was passed
      Throws:
      IllegalArgumentException - if feature is null
      Since:
      100.0.0
      See Also:
    • getSymbol

      public Symbol getSymbol(Graphic graphic)
      Returns the symbol that is used to visualize the given graphic.

      If the renderer is a DictionaryRenderer and its associated DictionarySymbolStyle references a style file hosted on ArcGIS Online or an ArcGIS Enterprise portal (also referred to as a web style), this method returns null. If the layer has rendered and the symbol is already drawn on the view, this method returns a valid MultilayerSymbol. If you want to get the symbol before the layer is rendered, use DictionarySymbolStyle.getSymbolAsync(Map).

      Specified by:
      getSymbol in class Renderer
      Parameters:
      graphic - the Graphic to get a Symbol from, not null
      Returns:
      the Symbol of the Graphic that was passed
      Throws:
      IllegalArgumentException - if graphic is null
      Since:
      100.0.0
      See Also: