com.esri.map
Class GraphicsLayer

java.lang.Object
  extended by com.esri.map.Layer
      extended by com.esri.map.GraphicsLayer
Direct Known Subclasses:
ArcGISFeatureLayer, GPSLayer

public class GraphicsLayer
extends Layer

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

The following are examples of how you might work with the GraphicsLayer class. You can initialize a GraphicsLayer through Java source code.

Java usage:

 JMap map;
 .
 .
 .
 GraphicsLayer graphicsLayer = new GraphicsLayer();
 map.getLayers().add(graphicsLayer);
 


Nested Class Summary
 
Nested classes/interfaces inherited from class com.esri.map.Layer
Layer.LayerStatus
 
Field Summary
 
Fields inherited from class com.esri.map.Layer
_credentials, _progress, _resolutionList, serviceInfo
 
Constructor Summary
  GraphicsLayer()
          This constructs an empty GraphicsLayer (see the class description for an example of this usage).
protected GraphicsLayer(boolean init)
          The constructor is used internally to allow more control over the layer initialization process.
 
Method Summary
 int addGraphic(Graphic graphic)
          Adds a graphic to the layer.
 int[] addGraphics(Graphic[] graphics)
          Adds graphics to the layer.
protected  String attributesToJson(Map<String,Object> attributes)
           
 void bringToFront(int id)
          Brings the graphic to front.
 void clearSelection()
          Deselects all selected graphics.
 void createNativeLayer()
           
 BufferedImage createSymbolImage(Symbol symbol, Geometry geometry, int width, int height, Color color)
          Returns a swatch image of the given geometry rendered with the specified symbol.
 BufferedImage[] createSymbolImages(Symbol[] symbols, Geometry[] geometries, int width, int height, Color color)
          Returns a swatch image array of for the given geometries rendered with the symbols.
 LayerLegendInfoCollection generateLegendInfo(ArrayList<com.esri.map.GraphicsLayer.LegendData> legendData)
           
 Graphic getGraphic(int id)
          Gets the graphic with the supplied id.
 int[] getGraphicIDs()
          Gets all graphic ids from the layer.
 int[] getGraphicIDs(float x, float y, int tolerance)
          Finds the graphics near the supplied x,y in pixels.
 int[] getGraphicIDs(float x, float y, int tolerance, int numberOfResults)
           
protected  String getLayerType()
           
 LayerLegendInfoCollection getLegend()
           
protected  Geometry getLegendImageGeometry()
           
protected  Geometry getLegendImageGeometryByType(Geometry.Type type)
           
 MapTip getMapTip()
          Returns the maptip.
 int getMaxDrawOrder()
          Returns the current maximum draw order of the graphics.
 double getMaxScale()
          Gets the maximum scale at which this layer will be displayed.
 int getMinDrawOrder()
          Returns the current minimum draw order of the graphics.
 double getMinScale()
          Gets the minimum scale at which this layer will be displayed.
 int getNumberOfGraphics()
          Gets the number of graphics in the layer.
 Renderer<Graphic> getRenderer()
          Gets the renderer of the GraphicsLayer.
 Color getSelectionColor()
          Returns the color applied to a selected graphic.
 int[] getSelectionIDs()
          Gets the ids of the selected graphics.
 Symbol getSelectionSymbol()
          Gets the selection symbol.
protected  void init(boolean isVisible, int[] visibleLayers, String title, float opacity)
          This method is called only when composing a Map from a Web Map.
protected  void initializeNativeLayer()
           
protected  void initLayer()
           
protected  void internalInit()
           
 boolean isGraphicSelected(int id)
          Returns true if the graphic with the supplied id is selected.
 void movePointGraphic(int id, Point to)
          Moves the Point graphic to the supplied Point location.
 void recycle()
          Releases resources referenced by the Layer so that they can be recycled.
 void removeAll()
          Removes all graphics from the layer.
 void removeGraphic(int id)
          Removes the graphic with the specified id.
 void select(int id)
          Selects the graphic with the supplied id.
 void sendToBack(int id)
          Sends the graphic to back.
 void setGraphicVisible(int id, boolean visible)
          Sets the graphic visible or invisible.
 void setMapTip(MapTip mapTip)
          Sets the maptip to be used with this layer.
 void setMaxScale(double maxScale)
           
 void setMinScale(double minScale)
           
 void setRenderer(Renderer<Graphic> renderer)
          Sets the renderer of the GraphicsLayer.
 void setSelectionColor(Color selectionColor)
          Sets the color that is applied to a selected graphic.
 void setSelectionIDs(int[] ids, boolean inclusive)
          Selects the graphics with the supplied ids.
 void setSelectionSymbol(Symbol selectionSymbol)
          Sets the symbol to use for selected graphics.
 void unselect(int id)
          Deselects the graphic with the supplied id.
 void updateGraphic(int[] ids, int drawOrder)
          Updates the draw order of graphics.
 void updateGraphic(int[] ids, int[] drawOrder)
          Updates the draw order of the graphic.
 void updateGraphic(int id, Geometry geometry)
          Replaces the geometry of the identified graphic with the supplied geometry.
 void updateGraphic(int id, Graphic graphic)
          Replaces the identified graphic with the supplied graphic.
 void updateGraphic(int id, InfoTemplate infoTemplate)
          Replaces the infoTemplate of the identified graphic with the supplied infoTemplate.
 void updateGraphic(int id, int drawOrder)
          Updates the draw order of the graphic.
 void updateGraphic(int id, Map<String,Object> attributes)
          Replaces the set of attributes of the identified graphic with the supplied attributes.
 void updateGraphic(int id, Symbol symbol)
          Replaces the symbol of the identified graphic with the supplied symbol.
protected  void validateMapTip(MapTip mapTip)
          Validates maptip.
 
Methods inherited from class com.esri.map.Layer
addLayerInitializeCompleteListener, finalize, fireLayerCreateCompleteEvent, fireLayerCreateErrorEvent, fireLayerCreateErrorEvent, getCopyrightText, getCredentialsInternal, getDefaultSpatialReference, getDescription, getException, getExtent, getFullExtent, getInitialExtent, getInitializationError, getLayerHandle, getMap, getMapServer, getMapServerInfo, getMapServerLegendInfo, getName, getOpacity, getPopupInfo, getResolution, getResolutionList, getServiceDescription, getSpatialReference, getStatus, getUrl, getUrlHashCode, initializeAsync, internalGetLayerLegendInfos, isHidingNoDataTiles, isInitialized, isReady, isShowingCopyright, isVisible, loadServiceInfo, lock, reinitializeAsync, removeLayerInitializeCompleteListener, setCopyrightText, setCredentials, setDefaultSpatialReference, setDescription, setError, setException, setFullExtent, setInitialExtent, setLayerHandle, setMap, setMapServer, setName, setOpacity, setPopupInfos, setServiceDescription, setShowingCopyright, setStatus, setUrl, setVisible, unlock, updateSpatialReferenceStatus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicsLayer

public GraphicsLayer()
This constructs an empty GraphicsLayer (see the class description for an example of this usage).

This constructor assumes you have another layer as the bottom most layer defined for the Map, the GraphicsLayer cannot be the bottom most layer.


GraphicsLayer

protected GraphicsLayer(boolean init)
The constructor is used internally to allow more control over the layer initialization process.

Method Detail

recycle

public void recycle()
Description copied from class: Layer
Releases resources referenced by the Layer so that they can be recycled.

Overrides:
recycle in class Layer

createSymbolImage

public BufferedImage createSymbolImage(Symbol symbol,
                                       Geometry geometry,
                                       int width,
                                       int height,
                                       Color color)
Returns a swatch image of the given geometry rendered with the specified symbol.

Parameters:
symbol - to render the geometry with.
geometry - the geometry to render in the swatch.
width - the width of the swatch in pixels.
height - the height of the swatch in pixels.
color - the background color in ARGB format.
Returns:
the swatch BufferedImage or null.

createSymbolImages

public BufferedImage[] createSymbolImages(Symbol[] symbols,
                                          Geometry[] geometries,
                                          int width,
                                          int height,
                                          Color color)
Returns a swatch image array of for the given geometries rendered with the symbols.

Parameters:
symbols - a symbol array
geometries - a geometry array
width - the width of the swatch in pixels.
height - the height of the swatch in pixels.
color - the background color in ARGB format.
Returns:
a BufferedImage array

createNativeLayer

public void createNativeLayer()
Specified by:
createNativeLayer in class Layer

initLayer

protected void initLayer()

movePointGraphic

public void movePointGraphic(int id,
                             Point to)
Moves the Point graphic to the supplied Point location.

Parameters:
id - of the Point graphic to be moved. If the id is not of a Point graphic, then there will be no change.
to - destination of the move operation.

removeAll

public void removeAll()
Removes all graphics from the layer.


addGraphic

public int addGraphic(Graphic graphic)
Adds a graphic to the layer. It is good practise to store the id returned for the Graphic along with any application specific data that may be updated and will require the graphic to be changed.

Parameters:
graphic - the graphic to add
Returns:
int the graphics unique id

addGraphics

public int[] addGraphics(Graphic[] graphics)
Adds graphics to the layer. It is good practise to store the ids returned for each respective Graphic along with any application specific data that may be updated and will require a graphic to be changed.

Parameters:
graphics - the graphics to add
Returns:
the respective ids

getGraphic

public Graphic getGraphic(int id)
Gets the graphic with the supplied id.

Parameters:
id - the id
Returns:
the graphic

getGraphicIDs

public int[] getGraphicIDs()
Gets all graphic ids from the layer.

Returns:

getMaxScale

public double getMaxScale()
Description copied from class: Layer
Gets the maximum scale at which this layer will be displayed. For service layers this is defined by the service. For a GraphicsLayer there is no maximum scale.

Overrides:
getMaxScale in class Layer
Returns:
the maximum scale

getMinScale

public double getMinScale()
Description copied from class: Layer
Gets the minimum scale at which this layer will be displayed. For service layers this is defined by the service. For a GraphicsLayer there is no minimum scale.

Overrides:
getMinScale in class Layer
Returns:
the minimum scale

setMaxScale

public void setMaxScale(double maxScale)

setMinScale

public void setMinScale(double minScale)

getNumberOfGraphics

public int getNumberOfGraphics()
Gets the number of graphics in the layer.

Returns:
int the number of graphics

removeGraphic

public void removeGraphic(int id)
Removes the graphic with the specified id. If the id does not exist then no action is taken.

Parameters:
id - the id of the graphic to remove

updateGraphic

public void updateGraphic(int id,
                          Graphic graphic)
Replaces the identified graphic with the supplied graphic.

Parameters:
id - the id of the graphic to change
graphic - the new graphic

updateGraphic

public void updateGraphic(int id,
                          Geometry geometry)
Replaces the geometry of the identified graphic with the supplied geometry.

Parameters:
id - the id of the graphic to change
geometry - the new geometry

updateGraphic

public void updateGraphic(int id,
                          Symbol symbol)
Replaces the symbol of the identified graphic with the supplied symbol.

Parameters:
id - the id of the graphic to change
symbol - the new symbol

updateGraphic

public void updateGraphic(int id,
                          InfoTemplate infoTemplate)
                   throws Exception
Replaces the infoTemplate of the identified graphic with the supplied infoTemplate.

Parameters:
id - the id of the graphic to change
infoTemplate - the new infoTemplate
Throws:
Exception

updateGraphic

public void updateGraphic(int id,
                          Map<String,Object> attributes)
Replaces the set of attributes of the identified graphic with the supplied attributes.

Parameters:
id - the id of the graphic to change
attributes - the new attributes

updateGraphic

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 - graphic id.
drawOrder - draw order.
Since:
10.1.1
See Also:
updateGraphic(int[], int), updateGraphic(int[], int[])

updateGraphic

public void updateGraphic(int[] ids,
                          int drawOrder)
Updates the draw order of graphics. Higher valued graphics are drawn on top of those with lower value.

Parameters:
ids - graphic ids.
drawOrder - draw order.
Since:
10.1.1
See Also:
updateGraphic(int, int), updateGraphic(int[], int[])

updateGraphic

public void updateGraphic(int[] ids,
                          int[] drawOrder)
Updates the draw order of the graphic. Higher valued graphics are drawn on top of those with lower value.

Parameters:
ids - graphic ids.
drawOrder - draw order corresponding to corresponding graphic id.
Since:
10.1.1

getMinDrawOrder

public int getMinDrawOrder()
Returns the current minimum draw order of the graphics.

Returns:
the current minimum draw order.
Since:
10.1.1

getMaxDrawOrder

public int getMaxDrawOrder()
Returns the current maximum draw order of the graphics.

Returns:
the current maximum draw order.
Since:
10.1.1

bringToFront

public void bringToFront(int id)
Brings the graphic to front.

Parameters:
id - graphic id.
Since:
10.1.1

sendToBack

public void sendToBack(int id)
Sends the graphic to back.

Parameters:
id - graphic id.
Since:
10.1.1

setGraphicVisible

public void setGraphicVisible(int id,
                              boolean visible)
Sets the graphic visible or invisible.

Parameters:
id - the id of the graphic to change
visible - true if the graphic is to be visible, false otherwise.

getMapTip

public MapTip getMapTip()
Returns the maptip.

Returns:
the maptip.
Since:
10.1.1

setMapTip

public void setMapTip(MapTip mapTip)
Sets the maptip to be used with this layer.

Parameters:
mapTip - maptip to be used.
Since:
10.1.1

validateMapTip

protected void validateMapTip(MapTip mapTip)
Validates maptip.

Parameters:
mapTip - maptip to be validated.

attributesToJson

protected String attributesToJson(Map<String,Object> attributes)

getRenderer

public Renderer<Graphic> getRenderer()
Gets the renderer of the GraphicsLayer.

Returns:
Returns the renderer.

setRenderer

public void setRenderer(Renderer<Graphic> renderer)
Sets the renderer of the GraphicsLayer.

Parameters:
renderer - The renderer to set.

getGraphicIDs

public int[] getGraphicIDs(float x,
                           float y,
                           int tolerance)
Finds the graphics near the supplied x,y in pixels. Both visible and invisible graphics are returned. The graphics must have been through a Map draw cycle before they can be found.

Parameters:
x - the x coordinates of the point for searching.
y - the y coordinates of the point for searching.
tolerance - the search tolerance in pixels
Returns:
the first 10 graphics within the search tolerance.

getGraphicIDs

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

internalInit

protected void internalInit()
Specified by:
internalInit in class Layer

init

protected void init(boolean isVisible,
                    int[] visibleLayers,
                    String title,
                    float opacity)
Description copied from class: Layer
This method is called only when composing a Map from a Web Map. The web map contains properties that every layer should be initialized with, up front.

Specified by:
init in class Layer

initializeNativeLayer

protected void initializeNativeLayer()
Specified by:
initializeNativeLayer in class Layer

setSelectionSymbol

public void setSelectionSymbol(Symbol selectionSymbol)
Sets the symbol to use for selected graphics. If the selection symbol is not appropriate for the graphic's geometry type then the graphic will not be drawn.

Parameters:
selectionSymbol -
See Also:
getSelectionSymbol(), setSelectionColor(Color)

getSelectionSymbol

public Symbol getSelectionSymbol()
Gets the selection symbol.

Returns:
the symbol applied to a selected graphic.
See Also:
setSelectionSymbol(Symbol), getSelectionColor()

getSelectionColor

public Color getSelectionColor()
Returns the color applied to a selected graphic.

Returns:
the color applied to a selected graphic.
Since:
10.1.1
See Also:
setSelectionColor(Color), getSelectionSymbol()

setSelectionColor

public void setSelectionColor(Color selectionColor)
Sets the color that is applied to a selected graphic.

Parameters:
selectionColor - color that is applied to a selected graphic.
Since:
10.1.1
See Also:
getSelectionColor(), setSelectionSymbol(Symbol)

setSelectionIDs

public void setSelectionIDs(int[] ids,
                            boolean inclusive)
Selects the graphics with the supplied ids.

Parameters:
ids -
inclusive - true if the supplied graphics will be added to the selection; false if the supplied graphics are the only selected graphics.

select

public void select(int id)
Selects the graphic with the supplied id.

Parameters:
id -

unselect

public void unselect(int id)
Deselects the graphic with the supplied id.

Parameters:
id -

getSelectionIDs

public int[] getSelectionIDs()
Gets the ids of the selected graphics.

Returns:

isGraphicSelected

public boolean isGraphicSelected(int id)
Returns true if the graphic with the supplied id is selected.

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

clearSelection

public void clearSelection()
Deselects all selected graphics.


getLegend

public LayerLegendInfoCollection getLegend()
Specified by:
getLegend in class Layer

getLegendImageGeometry

protected Geometry getLegendImageGeometry()

getLegendImageGeometryByType

protected Geometry getLegendImageGeometryByType(Geometry.Type type)

generateLegendInfo

public LayerLegendInfoCollection generateLegendInfo(ArrayList<com.esri.map.GraphicsLayer.LegendData> legendData)
                                             throws Exception,
                                                    IOException
Parameters:
legendData -
Returns:
Throws:
Exception
IOException

getLayerType

protected String getLayerType()


Copyright © 2012. All Rights Reserved.