public class

GraphicsLayer

extends Layer
java.lang.Object
   ↳ com.esri.android.map.Layer
     ↳ com.esri.android.map.GraphicsLayer
Known Direct Subclasses

Class Overview

The GraphicsLayer class represents a layer that contains one or more Graphic features. The MapView can contain one or more graphic layers.

The following is an example of how you can work with the GraphicsLayer class in Java.

Java usage:

 //GraphicsLayer class is used to define the Layer that is added to the
 //MapView object.
 MapView mv = new MapView(this);
 mv.addLayer(new GraphicsLayer());
 setContentView(mv);
 

Summary

Nested Classes
enum GraphicsLayer.MarkerRotationMode In dynamic rendering mode the rotation of marker symbols can either be around the symbol origin or the symbol can be offset and then rotated around its original origin. 
enum GraphicsLayer.RenderingMode GraphicsLayers can be rendered in two modes. 
Fields
protected GraphicsLayer.RenderingMode renderingMode
[Expand]
Inherited Fields
From class com.esri.android.map.Layer
Public Constructors
GraphicsLayer()
The constructor is used if your are instantiating an empty GraphicsLayer (see the class description for an example of this usage).By default, the graphic layer use dynamic mode.
GraphicsLayer(GraphicsLayer.RenderingMode mode)
Constructs the graphic layer with specific rendering mode.
GraphicsLayer(GraphicsLayer.MarkerRotationMode rotationMode)
Constructs a Graphic layer with specific rotation mode for marker symbol, its rendering mode is dynamic.
GraphicsLayer(SpatialReference sr, Envelope fullextent)
The constructor with spatial reference, full extent and default dynamic rendering mode.
GraphicsLayer(SpatialReference sr, Envelope fullextent, GraphicsLayer.RenderingMode mode)
The constructor with spatial reference and full extent, and rendering mode.
Protected Constructors
GraphicsLayer(boolean initLayer)
The constructor is used internally to allow more controls over the layer initialization process.
GraphicsLayer(long handle)
The constructor is used internally to allow more controls over the layer initialization process.
Public Methods
int addGraphic(Graphic graphic)
Adds a graphic into GraphicsLayer.
int[] addGraphics(Graphic[] graphics)
Adds an array of Graphic.
void bringToFront(int id)
Brings the graphic to front.
void clearSelection()
Clears the current selection.
PopupInfo createPopupInfo(Graphic graphic)
int getDrawOrder(int uid)
Returns current draw order for the given graphic.
Graphic getGraphic(int uid)
Retrives a graphic instance using a unique ID.
int[] getGraphicIDs()
Retrieves an array of unique IDs representing all graphics in this layer.
int[] getGraphicIDs(float x, float y, int tolerance)
Returns the graphics near the Point.
int[] getGraphicIDs(float x, float y, int tolerance, int numberOfResults)
Returns the graphics near the Point.
int[] getGraphicOIDs(String oidField)
Retrieves an array of object IDs from the attributes of all graphics in this layer.
int getMaxDrawOrder()
Returns the current maximum draw order of the graphics.
int getMinDrawOrder()
Returns the current minimum draw order of the graphics.
int getNumberOfGraphics()
Returns number of graphics.
Renderer getRenderer()
Gets the renderer of the GraphicsLayer.
int getSelectionColor()
Returns the color applied to a selected feature.
int[] getSelectionIDs()
Returns an array of selected graphic ids.
boolean isGraphicSelected(int id)
Returns true if the graphic with the supplied id is selected.
void removeAll()
Removes all graphics.
void removeGraphic(int id)
Removes graphic using a unique ID.
void removeGraphics(int[] ids)
Removes graphics using an array of unique IDs.
void sendToBack(int id)
Sends the graphic to back.
void setGraphicVisible(int uid, boolean visible)
Sets visibility of a graphic with a unique id.
void setRenderer(Renderer renderer)
Sets the renderer of the GraphicsLayer.
void setSelectedGraphics(int[] ids, boolean selected)
Selects the graphics with the supplied ids.
void setSelectionColor(int selectionColor)
Sets the color that is applied to a selected feature.
void setSelectionColorWidth(int highlightWidth)
Sets selection color width.
void updateGraphic(int id, int drawOrder)
Updates the draw order of the graphic.
void updateGraphic(int id, Map<String, Object> attributes)
Updates the attributes of a graphic specified by id with an attribute map.
void updateGraphic(int id, Symbol symbol)
Updates the symbol attribute of a graphic specified by id with a symbol.
void updateGraphic(int id, Graphic graphic)
Updates a graphic specified by an id with attributes of another graphic instance.
void updateGraphic(int id, Geometry geometry)
Updates the geometry of a graphic specified by id with a geometry.
void updateGraphics(int[] ids, int drawOrder)
Updates the draw order of for a group graphics.
void updateGraphics(int[] ids, Graphic[] graphics)
Updates an array of graphics specified by an array of their ids with attributes of other graphic instances.
void updateGraphics(int[] ids, int[] drawOrder)
Updates an array of graphics with the corresponding draw order.
Protected Methods
long create()
int getObjectID(int uid, String oidField)
Retrieves the Object ID field from the graphic with the specified unique id, or -1 if that attribute does not exist.
void initLayer()
Initializes the layer.
void updateGraphicsVisibility()
Updates the visibility of the graphics based on the "visible" attribute in their attribute map.
[Expand]
Inherited Methods
From class com.esri.android.map.Layer
From class java.lang.Object

Fields

protected GraphicsLayer.RenderingMode renderingMode

Public Constructors

public GraphicsLayer ()

The constructor is used if your are instantiating an empty GraphicsLayer (see the class description for an example of this usage).By default, the graphic layer use dynamic mode.

This constructor assumes you have another layer as the bottom most layer defined for the MapView. In this instance the GraphicsLayer cannot be the bottom most layer.

public GraphicsLayer (GraphicsLayer.RenderingMode mode)

Constructs the graphic layer with specific rendering mode.

Parameters
mode GraphicsLayer.RenderingMode: - RenderingMode

public GraphicsLayer (GraphicsLayer.MarkerRotationMode rotationMode)

Constructs a Graphic layer with specific rotation mode for marker symbol, its rendering mode is dynamic.

public GraphicsLayer (SpatialReference sr, Envelope fullextent)

The constructor with spatial reference, full extent and default dynamic rendering mode.

Parameters
sr SpatialReference: The default spatial reference GraphicsLayer uses
fullextent Envelope: The full extent of GraphicsLayer

public GraphicsLayer (SpatialReference sr, Envelope fullextent, GraphicsLayer.RenderingMode mode)

The constructor with spatial reference and full extent, and rendering mode.

Parameters
sr SpatialReference: The default spatial reference GraphicsLayer uses
fullextent Envelope: The full extent of GraphicsLayer
mode GraphicsLayer.RenderingMode: RendingMode

Protected Constructors

protected GraphicsLayer (boolean initLayer)

The constructor is used internally to allow more controls over the layer initialization process.

Parameters
initLayer boolean

protected GraphicsLayer (long handle)

The constructor is used internally to allow more controls over the layer initialization process.

Parameters
handle long

Public Methods

public int addGraphic (Graphic graphic)

Adds a graphic into GraphicsLayer.

Parameters
graphic Graphic: Graphic object
Returns
int A unique ID representing the added Graphic if adding is successful. -1 if adding fails.

public int[] addGraphics (Graphic[] graphics)

Adds an array of Graphic.

Parameters
graphics Graphic: An array of Graphic.
Returns
int[] An array of unique IDs representing newly added Graphics if adding is successful.

public void bringToFront (int id)

Brings the graphic to front.

Parameters
id int: graphic id.

public void clearSelection ()

Clears the current selection.

public PopupInfo createPopupInfo (Graphic graphic)

Returns
PopupInfo

public int getDrawOrder (int uid)

Returns current draw order for the given graphic.

Parameters
uid int: graphic id.
Returns
int integer the current draw order

public Graphic getGraphic (int uid)

Retrives a graphic instance using a unique ID.

Parameters
uid int: Unique ID representing a graphic
Returns
Graphic A graphic instance if a graphic with the same UID exists, otherwise a null is returned.

public int[] getGraphicIDs ()

Retrieves an array of unique IDs representing all graphics in this layer.

Returns
int[] an array of unique IDs

public int[] getGraphicIDs (float x, float y, int tolerance)

Returns the graphics near the Point. The point is specified by the x,y in pixels.
The returned results are sorted:

  • Array returns with closest features to x & y sorted
  • Points have highest priority, then lines, then polygons. If a point, line, and polygon are equidistant to x,y the point will be the first position in the array, then the line, and finally the polygon.

Parameters
x float: the x screen coordinates of the point for searching.
y float: the y screen coordinates of the point for searching.
tolerance int: the search tolerance in DP(density independent pixels).
Returns
int[] the first 10 graphics within the search tolerance.

public int[] getGraphicIDs (float x, float y, int tolerance, int numberOfResults)

Returns the graphics near the Point. The point is specified by the x,y in pixels.
The returned results are sorted:

  • Array returns with closest features to x & y sorted
  • Points have highest priority, then lines, then polygons. If a point, line, and polygon are equidistant to x,y the point will be the first position in the array, then the line, and finally the polygon.

Parameters
x float: the x screen coordinates of the point for searching.
y float: the y screen coordinates of the point for searching.
tolerance int: the search tolerance in DP(density independent pixels).
numberOfResults int: the maximum number of result can be returned.
Returns
int[] the graphics within the search tolerance.

public int[] getGraphicOIDs (String oidField)

Retrieves an array of object IDs from the attributes of all graphics in this layer.

Parameters
oidField String: The name of the object ID field
Returns
int[] an array of object IDs

public int getMaxDrawOrder ()

Returns the current maximum draw order of the graphics.

Returns
int integer the current maximum draw order.

public int getMinDrawOrder ()

Returns the current minimum draw order of the graphics.

Returns
int integer the current minimum draw order.

public int getNumberOfGraphics ()

Returns number of graphics.

Returns
int number of graphics

public Renderer getRenderer ()

Gets the renderer of the GraphicsLayer.

Returns
Renderer Returns the renderer.

public int getSelectionColor ()

Returns the color applied to a selected feature.

Returns
int the color applied to a selected feature.

public int[] getSelectionIDs ()

Returns an array of selected graphic ids.

Returns
int[] an integer array of graphic ids.

public boolean isGraphicSelected (int id)

Returns true if the graphic with the supplied id is selected.

Parameters
id int: the id
Returns
boolean true if the graphic with the supplied id is selected; false otherwise.

public void removeAll ()

Removes all graphics.

public void removeGraphic (int id)

Removes graphic using a unique ID.

Parameters
id int: Unique ID representing a Graphic.

public void removeGraphics (int[] ids)

Removes graphics using an array of unique IDs.

Parameters
ids int: An array of unique IDs representing the Graphics.

public void sendToBack (int id)

Sends the graphic to back.

Parameters
id int: graphic id.

public void setGraphicVisible (int uid, boolean visible)

Sets visibility of a graphic with a unique id.

Parameters
uid int: Unique ID representing an existing graphic.
visible boolean: False if graphic is invisible.

public void setRenderer (Renderer renderer)

Sets the renderer of the GraphicsLayer.

Parameters
renderer Renderer: The renderer to set.

public void setSelectedGraphics (int[] ids, boolean selected)

Selects the graphics with the supplied ids.

Parameters
ids int: the ids
selected boolean: if true the graphic will be added to current selections, otherwise it will be unselected from current selection.

public void setSelectionColor (int selectionColor)

Sets the color that is applied to a selected feature.

Parameters
selectionColor int: color that is applied to a selected feature.

public void setSelectionColorWidth (int highlightWidth)

Sets selection color width.

Parameters
highlightWidth int: integer in DP(density independent pixels).

public void updateGraphic (int id, int drawOrder)

Updates the draw order of the graphic. Higher valued graphics are drawn on top of those with lower value.

Parameters
id int: id Unique ID representing an existing graphic.
drawOrder int: an integer for drawing order

public void updateGraphic (int id, Map<String, Object> attributes)

Updates the attributes of a graphic specified by id with an attribute map.

Parameters
id int: Unique ID representing an existing graphic.
attributes Map: Attribute map used for update.

public void updateGraphic (int id, Symbol symbol)

Updates the symbol attribute of a graphic specified by id with a symbol.

Parameters
id int: Unique ID representing an existing graphic.
symbol Symbol: Symbol instance used for update.

public void updateGraphic (int id, Graphic graphic)

Updates a graphic specified by an id with attributes of another graphic instance. Its graphic order is updated also.

Parameters
id int: Unique ID representing an existing graphic.
graphic Graphic: Graphic instance whose attributes is used in update.

public void updateGraphic (int id, Geometry geometry)

Updates the geometry of a graphic specified by id with a geometry.

Parameters
id int: Unique ID representing an existing graphic.
geometry Geometry: Geometry instance used for update.

public void updateGraphics (int[] ids, int drawOrder)

Updates the draw order of for a group graphics. Higher valued graphics are drawn on top of those with lower value.

Parameters
ids int: array of graphic IDs.
drawOrder int: draw order.

public void updateGraphics (int[] ids, Graphic[] graphics)

Updates an array of graphics specified by an array of their ids with attributes of other graphic instances. Its graphic order is updated also.

Parameters
ids int: Array of unique IDs representing existing graphics.
graphics Graphic: Array of graphic instance whose attributes is used in update.

public void updateGraphics (int[] ids, int[] drawOrder)

Updates an array of graphics with the corresponding draw order. Higher valued graphics are drawn on top of those with lower value.

Parameters
ids int: graphic ids.
drawOrder int: draw order corresponding to corresponding graphic id.

Protected Methods

protected long create ()

Returns
long

protected int getObjectID (int uid, String oidField)

Retrieves the Object ID field from the graphic with the specified unique id, or -1 if that attribute does not exist. This can be used for efficiency when you do not need all of the attributes.

Parameters
uid int: The unique id of the graphic
oidField String: The name of the OID field
Returns
int The OID for that graphic, or null if it doesn't have one

protected void initLayer ()

Initializes the layer. The implementation should submit the OnStatusChangedListener.STATUS event accordingly.

protected void updateGraphicsVisibility ()

Updates the visibility of the graphics based on the "visible" attribute in their attribute map. Iterates over all graphics in the layer, and if they have a "visible" attribute set to 0, it will set the graphic to invisible. Otherwise, it will set the graphic to visible.