public class

Graphic

extends Object
implements Serializable Feature
java.lang.Object
   ↳ com.esri.core.map.Graphic
Known Direct Subclasses

Class Overview

The Graphic class is used to represent a feature that can have any of the following:

Graphic objects are immutable, which means a Graphic's state cannot change after construction. Graphic objects can be displayed, altered and removed using a GraphicsLayer (see the GraphicsLayer class for more details). When a Graphic object is added to a GraphicsLayer via the addGraphic(Graphic) method, this method returns a unique ID (UID) which you can then use to reference the added graphic for subsequent operations, such as making updates to the Graphic in the layer. A new Graphic object will be created in the update process. Graphic objects are stateless so there is no guarantee that a feature in the GraphicsLayer exists after the request for the Graphic object is completed.

A Graphic's attributes are stored in a Map. Supported value types are restricted to the following list:

  • Short
  • Integer
  • Long
  • Float
  • Double
  • Boolean
  • String
  • Date
  • Calendar
  • null

Summary

Fields
protected final Map<String, Object> attributes Name-value pairs of fields and their connected field values that are associated with the graphic.
Public Constructors
Graphic(Geometry geometry, Symbol symbol)
Instantiates a new Graphic object from the specified geometry and symbol.
Graphic(Geometry geometry, Symbol symbol, int drawOrder)
Instantiates a new Graphic object from the specified geometry, symbol, and draw order.
Graphic(Geometry geometry, Symbol symbol, Map<String, Object> attributes)
Instantiates a new Graphic object from the specified geometry, symbol, and attributes.
Graphic(Geometry geometry, Symbol symbol, Map<String, Object> attributes, int drawOrder)
Instantiates a new Graphic object from the specified geometry, symbol, attributes, and draw order.
Public Methods
static Graphic fromJson(JsonParser parser)
Convenience method which parses the JSON representation of a graphic into a Graphic object.
String[] getAttributeNames()
Gets the name of all the attributes.
Object getAttributeValue(String key)
Gets the attribute value by the given name.
Map<String, Object> getAttributes()
Returns all attributes of the graphic as a read-only collection.
int getDrawOrder()
Returns the draw order.
Geometry getGeometry()
Gets the geometry that defines the graphic.
long getId()
Gets the unique ID of the feature.
SpatialReference getSpatialReference()
Returns the spatial reference.
Symbol getSymbol()
Gets the symbol for the graphic.
int getUid()
Gets unique ID.
static String toJson(Graphic graphic)
Convenience method to serialize the graphic into a string.
String toString()
Returns a string representation of the class.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.esri.core.map.Feature

Fields

protected final Map<String, Object> attributes

Name-value pairs of fields and their connected field values that are associated with the graphic.

Public Constructors

public Graphic (Geometry geometry, Symbol symbol)

Instantiates a new Graphic object from the specified geometry and symbol.

Parameters
geometry Geometry: the geometry to draw;
symbol Symbol: the symbol to draw the geometry with.

public Graphic (Geometry geometry, Symbol symbol, int drawOrder)

Instantiates a new Graphic object from the specified geometry, symbol, and draw order.

Parameters
geometry Geometry: the geometry to draw;
symbol Symbol: the symbol to draw the geometry with.
drawOrder int: the draw order; higher valued graphics appear on top of lower valued graphics.

public Graphic (Geometry geometry, Symbol symbol, Map<String, Object> attributes)

Instantiates a new Graphic object from the specified geometry, symbol, and attributes. The uid defaults to -1.

Parameters
geometry Geometry: The geometry to draw.
symbol Symbol: The symbol to draw the geometry with.
attributes Map: The name-value pairs of fields and their connected field values that are associated with the graphic.

public Graphic (Geometry geometry, Symbol symbol, Map<String, Object> attributes, int drawOrder)

Instantiates a new Graphic object from the specified geometry, symbol, attributes, and draw order. The uid defaults to -1.

Parameters
geometry Geometry: The geometry to draw.
symbol Symbol: The symbol to draw the geometry with.
attributes Map: The name-value pairs of fields and their connected field values that are associated with the graphic.
drawOrder int: the draw order; higher valued graphics appear on top of lower valued graphics.

Public Methods

public static Graphic fromJson (JsonParser parser)

Convenience method which parses the JSON representation of a graphic into a Graphic object.

Parameters
parser JsonParser: Parser initialized with a graphic JSON String.
Returns
Graphic Graphic object.
Throws
Exception Exception if parsing fails.

public String[] getAttributeNames ()

Gets the name of all the attributes. Attributes are name-value pairs of fields and field values associated with the graphic.

Returns
String[] the attribute names

public Object getAttributeValue (String key)

Gets the attribute value by the given name.

Parameters
key String: the key
Returns
Object the attribute value

public Map<String, Object> getAttributes ()

Returns all attributes of the graphic as a read-only collection.

Returns
Map<String, Object> the attributes

public int getDrawOrder ()

Returns the draw order.

Returns
int the draw order of this graphic.

public Geometry getGeometry ()

Gets the geometry that defines the graphic.

Returns
Geometry the geometry

public long getId ()

Gets the unique ID of the feature.

Returns
long the feature's ID

public SpatialReference getSpatialReference ()

Returns the spatial reference.

Returns
SpatialReference the spatial reference of this graphic.

public Symbol getSymbol ()

Gets the symbol for the graphic.

Returns
Symbol the symbol

public int getUid ()

Gets unique ID.

Returns
int the uid

public static String toJson (Graphic graphic)

Convenience method to serialize the graphic into a string.

Parameters
graphic Graphic: a Graphic object
Returns
String a json string
Throws
Exception exception thrown if the Graphic data member fails to be converted into string.

public String toString ()

Returns a string representation of the class. The format and content of the returned string is not part of the contract of the method and is subject to change in any future release or patch without further notice.

Returns
String