Class Graphic
- java.lang.Object
-
- com.esri.arcgisruntime.mapping.view.Graphic
-
- All Implemented Interfaces:
GeoElement
public final class Graphic extends java.lang.Object implements GeoElement
A Graphic consists of aGeometry
, optionalattributes
, 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 theSpatialReference
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 aFillSymbol
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 usingsetVisible(boolean)
.- Since:
- 100.0.0
- See Also:
GraphicsOverlay
,SpatialReference
,Symbol
,Renderer
-
-
Constructor Summary
Constructors Constructor Description Graphic()
Creates a new graphic with a null geometry and symbol.Graphic(double latitude, double longitude)
Creates a new graphic with a point defined in the WGS 84 SpatialReference.Graphic(Geometry geometry)
Creates a new graphic with the given geometry.Graphic(Geometry geometry, Symbol symbol)
Creates a new graphic with the given geometry and symbol.Graphic(Geometry geometry, java.util.Map<java.lang.String,java.lang.Object> attributes)
Creates a new graphic with the given geometry and attributes.Graphic(Geometry geometry, java.util.Map<java.lang.String,java.lang.Object> attributes, Symbol symbol)
Creates new graphic with the given geometry, attributes, and symbol.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>
getAttributes()
Gets a java.util.Map of all the available attributes as name value pairs.Geometry
getGeometry()
Gets the geometry of this geoelement.GraphicsOverlay
getGraphicsOverlay()
Gets the graphics overlay that contains this graphic.Symbol
getSymbol()
Gets the symbol.int
getZIndex()
Gets the z-index.boolean
isSelected()
Checks if the graphic is selected.boolean
isVisible()
Checks if the graphic is visible.void
setGeometry(Geometry geometry)
Sets the GeoElement's geometry.void
setSelected(boolean selected)
Controls if the graphic is selected or notvoid
setSymbol(Symbol symbol)
Sets the symbol.void
setVisible(boolean visible)
Controls the visibility of the graphic.void
setZIndex(int index)
Sets the z-index.
-
-
-
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:
java.lang.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 latitudelongitude
- 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 geometrysymbol
- the symbol- Throws:
java.lang.IllegalArgumentException
- if the geometry or symbol is null- Since:
- 100.0.0
-
Graphic
public Graphic(Geometry geometry, java.util.Map<java.lang.String,java.lang.Object> attributes)
Creates a new graphic with the given geometry and attributes.- Parameters:
geometry
- the geometryattributes
- the attributes of the graphic. Note that the values are copied. To make changes use getAttributes.- Throws:
java.lang.IllegalArgumentException
- if geometry or attributes is null- Since:
- 100.0.0
-
Graphic
public Graphic(Geometry geometry, java.util.Map<java.lang.String,java.lang.Object> attributes, Symbol symbol)
Creates new graphic with the given geometry, attributes, and symbol.- Parameters:
geometry
- the geometryattributes
- the attributes of the graphic. Note that the values are copied. To make changes use getAttributes.symbol
- the symbol- Throws:
java.lang.IllegalArgumentException
- if geometry, attributes, or symbol is null- Since:
- 100.0.0
-
-
Method Detail
-
getAttributes
public java.util.Map<java.lang.String,java.lang.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 interfaceGeoElement
- 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 interfaceGeoElement
- 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 interfaceGeoElement
- 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. Graphics with higher z-index values are drawn on top of lower z-index graphics.A graphic's z-index is most relevant for display in a two dimensional map. For dynamic 3D rendering (in a scene), graphic display order is determined by the distance to the camera rather than by z-index. Z-index, however, is considered when using static rendering in a scene (draping graphics on the surface, in other words).
If z-index is not set, graphics will usually render in the order in which they were added to the graphics overlay, the first added is rendered first and subsequent ones on top. In rare cases, the rendering algorithm may change the display order to provide more efficient rendering. If ordering is important, set the z-index explicitly on graphics. You can also place graphics of the same geometry type in their own graphics overlay and manage the order of the overlays in the
MapView
orSceneView
.- Returns:
- the z-index
- Since:
- 100.0.0
-
setZIndex
public void setZIndex(int index)
Sets the z-index. Graphics with higher z-index values are drawn on top of lower z-index graphics.A graphic's z-index is most relevant for display in a two dimensional map. For dynamic 3D rendering (in a scene), graphic display order is determined by the distance to the camera rather than by z-index. z-index, however, is considered when using static rendering in a scene (draping graphics on the surface, in other words).
- 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
-
-