Class UniqueValueRenderer

  • All Implemented Interfaces:
    JsonSerializable

    public final class UniqueValueRenderer
    extends Renderer
    A UniqueValueRenderer symbolizes groups of Features/Graphics that have matching attributes. This is most common with nominal, or string data.

    A UniqueValueRenderer is used for drawing multiple Features/Graphics 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 Feature/Graphic's attributes.
    • UniqueValues, tells which value, in a key/value pair, from a Feature/Graphic's attributes is assigned to what Symbol.
    • Default Label, a default label that a Feature/Graphic will be given if not assigned a UniqueValue.
    • Default Symbol, a default Symbol that a Feature/Graphic will be given if not assigned a UniqueValue.

    Example of using a UniqueValueRenderer with a GraphicsOverlay:

     // colors for symbols
     int BLACK = 0x00000000;
     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
    • 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 Features/Graphics 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 UniqueValueRenderer.

        Features/Graphics are rendered to the GeoView by matching their field names with the corresponding UniqueValue's value.

        The default values are set to Features/Graphics that use this Renderer if no UniqueValues are set or those Features/Graphics that don't fall within the UniqueValues range

        Parameters:
        fieldNames - field names used to match values, can be null or empty
        uniqueValues - values to be used for matching, can be null or empty
        defaultLabel - the default label for Features/Graphics that use this Renderer.
        defaultSymbol - the default Symbol for Features/Graphics that use this Renderer, can be null
        Since:
        100.0.0
    • Method Detail

      • getDefaultLabel

        public 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​(String defaultLabel)
        Sets the label that will be the default label for this Renderer.

        This label will represent a default name for any Feature/Graphic that doesn't have a label assigned to it.

        A Feature/Graphic 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
      • setDefaultSymbol

        public void setDefaultSymbol​(Symbol defaultSymbol)
        Sets the Symbol that will be the default Symbol for this Renderer.

        A Feature/Graphic will be set to this default Symbol if no values are set or a Feature/Graphic 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 the names that this Renderer uses to match Features/Graphics to their corresponding UniqueValue.

        These names will be used as a key, in a key/value pair, to search Features/Graphics' attributes to locate which Features/Graphics 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 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