Class Graphic

  • All Implemented Interfaces:
    GeoElement

    public final class Graphic
    extends Object
    implements GeoElement
    A Graphic consists of a Geometry, optional attributes, and is drawn on a map using a symbol or renderer.

    Graphics are used to represent temporary data, such as the results of a query or an analysis, or to highlight existing content in a map. They are often used to display data that changes location regularly, because they are held in memory instead of being persisted to the map. They are displayed on a map via a GraphicsOverlay.

    Each graphic must have a setGeometry(Geometry) describing the location and the shape of the graphic. The geometry of the graphic will be re-projected on the fly to the SpatialReference of the map if it has a different SpatialReference. Re-projection can be costly - ideally, the geometry should have the same SpatialReference as the map to maximize performance.

    Optionally, a Graphic can have a set of attributes providing information associated with the graphic, stored in a collection of key/value pairs returned from getAttributes(). A range of attribute data types are supported, including primitive data types (Boolean, Integer, Long, Short, Float, Double, String), dates (Calendar) and universally unique identifiers (UUID). Graphic attributes can be displayed in a Popup.

    Graphics are drawn using the Symbol set on the Graphic, or with the Renderer set on the GraphicsOverlay that contains it. If both properties are set, the Symbol of the Graphic takes precedence over any Renderer set on the GraphicsOverlay. A graphic can have any type of geometry, although the symbol type must be appropriate to the geometry type; a MarkerSymbol is used for points and multipoint, LineSymbol for polylines, and a FillSymbol for polygons or envelopes.

    A graphic can be selected or deselected using setSelected(boolean); selected graphics are drawn with a highlight halo. You can also change the visibility of a graphic using setVisible(boolean).

    Since:
    100.0.0
    See Also:
    GraphicsOverlay, SpatialReference, Symbol, Renderer
    • Constructor Detail

      • Graphic

        public Graphic()
        Creates a new graphic with a null geometry and symbol.
        Since:
        100.0.0
      • Graphic

        public Graphic​(Geometry geometry)
        Creates a new graphic with the given geometry.
        Parameters:
        geometry - the geometry
        Throws:
        IllegalArgumentException - if the geometry is null
        Since:
        100.0.0
      • Graphic

        public Graphic​(double latitude,
                       double longitude)
        Creates a new graphic with a point defined in the WGS 84 SpatialReference.
        Parameters:
        latitude - the latitude
        longitude - the longitude
        Since:
        100.0.0
      • Graphic

        public Graphic​(Geometry geometry,
                       Symbol symbol)
        Creates a new graphic with the given geometry and symbol.
        Parameters:
        geometry - the geometry
        symbol - the symbol
        Throws:
        IllegalArgumentException - if the geometry or symbol is null
        Since:
        100.0.0
      • Graphic

        public Graphic​(Geometry geometry,
                       Map<String,Object> attributes)
        Creates a new graphic with the given geometry and attributes.
        Parameters:
        geometry - the geometry
        attributes - the attributes. Note that the values are copied. To make changes use getAttributes.
        Throws:
        IllegalArgumentException - if geometry or attributes is null
        Since:
        100.0.0
      • Graphic

        public Graphic​(Geometry geometry,
                       Map<String,Object> attributes,
                       Symbol symbol)
        Creates new graphic with the given geometry, attributes, and symbol.
        Parameters:
        geometry - the geometry
        attributes - the attributes. Note that the values are copied. To make changes use getAttributes.
        symbol - the symbol
        Throws:
        IllegalArgumentException - if geometry, attributes, or symbol is null
        Since:
        100.0.0
    • Method Detail

      • getAttributes

        public Map<String,Object> getAttributes()
        Description copied from interface: GeoElement
        Gets a java.util.Map of all the available attributes as name value pairs.

        Attribute values are returned as Object instances, but the underlying value type is based on the Field.Type.

        Specified by:
        getAttributes in interface GeoElement
        Returns:
        all the available attributes as name value pairs.
      • getGeometry

        public Geometry getGeometry()
        Description copied from interface: GeoElement
        Gets the geometry of this geoelement.
        Specified by:
        getGeometry in interface GeoElement
        Returns:
        the geometry of this geoelement
      • setGeometry

        public void setGeometry​(Geometry geometry)
        Description copied from interface: GeoElement
        Sets the GeoElement's geometry.
        Specified by:
        setGeometry in interface GeoElement
        Parameters:
        geometry - the geometry to set
      • getSymbol

        public Symbol getSymbol()
        Gets the symbol. The symbol type will match with the geometry type of the graphic. The rendering of the symbol takes precedence over any Renderer that may be set already on the GraphicsOverlay.
        Returns:
        the symbol
        Since:
        100.0.0
      • setSymbol

        public void setSymbol​(Symbol symbol)
        Sets the symbol. The symbol type must match the geometry type of the graphic. The rendering of the symbol takes precedence over any Renderer that may be set already on the GraphicsOverlay.
        Parameters:
        symbol - the new symbol
        Since:
        100.0.0
      • isVisible

        public boolean isVisible()
        Checks if the graphic is visible.
        Returns:
        true if the graphic is visible; false otherwise.
        Since:
        100.0.0
      • setVisible

        public void setVisible​(boolean visible)
        Controls the visibility of the graphic.
        Parameters:
        visible - true, to make visible
        Since:
        100.0.0
      • isSelected

        public boolean isSelected()
        Checks if the graphic is selected.
        Returns:
        true, if is selected
        Since:
        100.0.0
      • setSelected

        public void setSelected​(boolean selected)
        Controls if the graphic is selected or not
        Parameters:
        selected - true, to select
        Since:
        100.0.0
      • getZIndex

        public int getZIndex()
        Gets the z index. The z index is the vertical stacking order of graphics that overlap. As in, which one appears as if it is physically closer to you. A graphic with a greater z index integer value is always visually "on top of" a graphic with a lower stack index value.
        Returns:
        the z index
        Since:
        100.0.0
      • setZIndex

        public void setZIndex​(int index)
        Sets the z index. The z index is the vertical stacking order of graphics that overlap. As in, which one appears as if it is physically closer to you. A graphic with a greater z index integer value is always visually "on top of" a graphic with a lower stack index value.
        Parameters:
        index - the new z index
        Since:
        100.0.0
      • getGraphicsOverlay

        public GraphicsOverlay getGraphicsOverlay()
        Gets the graphics overlay that contains this graphic. Will be null if the graphic is not in an overlay.
        Returns:
        the graphics overlay
        Since:
        100.0.0