com.esri.adf.web.data
Class WebGraphics

java.lang.Object
  extended by com.esri.adf.web.data.WebGraphics
All Implemented Interfaces:
WebContextInitialize, Serializable

public class WebGraphics
extends Object
implements WebContextInitialize, Serializable

The WebGraphics class represents a simple way to add feature graphics and images to a map. It is primarily intended for showing geographic items on the map whose geographic position does not necessarily matter. Some example uses for the WebGraphics include adding a logo for your organization to the map, adding text to the map such as a copyright, or adding a scalebar. There is no restriction on the types of features added to a WebGraphics; points, lines, and polygons can all be added. Images can also be added by implementing GraphicImage2 interface and adding it to WebGraphics. There can only be one WebGraphics associated with a map at a given time.

WebGraphics items are added at the top of the map, above all layers from all resources. Their visibility can not be controlled through the TOC (table of contents) control. Queries can not be executed against WebGraphics since it is not a type of GISResource. You can add items to WebGraphics by calling any of these methods addGraphics(GraphicElement) or addRenderer(GraphicRenderer) or addImage(GraphicImage)

An alternative for adding geographic features programmatically is to use the GraphicsResource which allows you to display and query geographic features and allows for those items to appear in the TOC. GraphicsResources also allow for multiple GraphicsLayers, therefore it’s possible to group features as layers which allows for the visibility of those groups of features to be changed by the end-user. This is not easily done with the WebGraphics.

To use the WebGraphics, it needs to be registered as a context attribute of the WebContext. This is most commonly done through settings in the context-attributes.xml file and the faces-config.xml file for the web application. If you generate an application through Manager or IDE wizards, it will have done this for you.

Here is an example of how WebGraphics is declared in context-attributes.xml :

 <managed-bean>
  <managed-bean-name>graphics</managed-bean-name>
  <managed-bean-class>com.esri.adf.web.data.WebGraphics</managed-bean-class>
  <managed-bean-scope>none</managed-bean-scope>
 </managed-bean>
 

Here is an example of how WebGraphics is registered as an attribute of the WebContext in faces-config.xml:

 <managed-bean>
   <managed-bean-name>mapContext</managed-bean-name>
   <managed-property>
     <property-name>attributes</property-name>
     <map-entries>
       <map-entry>
         <key>graphics</key>
         <value>#{graphics}</value>
       </map-entry>
            .
            .
            .
     </map-entries>
   </managed-property>
 </managed-bean>
 

See Also:
Serialized Form

Field Summary
protected  WebContext context
          Holds the reference to WebContext object.
protected  WebExtent extent
          Holds the map's current extent.
protected  byte[] imageBytes
          Holds the WebGraphics image bytes.
protected  List<GraphicImage> images
          Holds the list of image that are available in the WebGraphics.
protected  List<GraphicElement> lineGraphics
          Holds the list of polyline graphics that are available in the WebGraphics.
protected  List<GraphicImage> lineImages
          Holds the list of polyline images that are available in the WebGraphics.
protected  List<GraphicRenderer> lineRenderers
          Holds the list of polyline renderers that are available in the WebGraphics.
protected  List<GraphicElement> pointGraphics
          Holds the list of point graphics that are available in the WebGraphics.
protected  List<GraphicImage> pointImages
          Holds the list of point images that are available in the WebGraphics.
protected  List<GraphicRenderer> pointRenderers
          Holds the list of point renderers that are available in the WebGraphics.
protected  List<GraphicElement> polygonGraphics
          Holds the list of polygon graphics that are available in the WebGraphics.
protected  List<GraphicImage> polygonImages
          Holds the list of polygon images that are available in the WebGraphics.
protected  List<GraphicRenderer> polygonRenderers
          Holds the list of polygon renderers that are available in the WebGraphics.
static String WEBGRAPHICS_IMAGE_FORMAT
          Default image format that is used for generating WebGraphics.
 
Constructor Summary
WebGraphics()
           
 
Method Summary
 void addGraphics(GraphicElement element)
          Adds a point, multipoint, polyline or polygon graphic to the map.
 void addImage(GraphicImage image)
          Adds an image to the map.
 void addRenderer(GraphicRenderer renderer)
          Adds a renderer to the map.
 void clearGraphics()
          Clears all graphic elements, images, and renderers from the WebGraphics object.
 void destroy()
           The cleaup chores (such as releasing held resources) of attributes of a WebContext should be performed in this method.
 byte[] exportGraphics()
          Exports all the graphics as a byte array based on the WebMap current state.
 byte[] exportGraphics(ExportProperties properties)
          Draw all the graphics and return as a byte array.
 List<GraphicElement> getLineGraphics()
          Returns the list of line graphics that are displayed in the map as WebGraphics.
 List<GraphicElement> getPointGraphics()
          Returns the list of point graphics that are displayed in the map as WebGraphics.
 List<GraphicElement> getPolygonGraphics()
          Returns the list of polygon graphics that are displayed in the map as WebGraphics.
 void init(WebContext webContext)
           The initialization chores of attributes of a WebContext should be performed in this method.
 boolean isEmpty()
          Returns true if no graphics elements, images, or renderers are currently referenced by the WebGraphics object.
 boolean isGraphicsExists(GraphicElement element)
          Determines if the element has already been added to the map.
 boolean isImageExists(GraphicImage image)
          Determines if the image has already been added to the map.
 boolean isRendererExists(GraphicRenderer renderer)
          Determines if the renderer has already been added to the map.
 boolean isWebGraphicsChanged()
          Determines whether WebGraphics changed or not.
 void removeGraphics(GraphicElement element)
          Removes the specified element from WebGraphics.
 void removeImage(GraphicImage image)
          Removes the specified image from the WebGraphics.
 void removeRenderer(GraphicRenderer renderer)
          Removes the specified renderer from the WebGraphics.
 void resetWebGraphics()
          This method resets the WebGraphics and forces the next exportGraphics() call to redraw the graphics even though the current extent of WebMap may not have changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEBGRAPHICS_IMAGE_FORMAT

public static final String WEBGRAPHICS_IMAGE_FORMAT
Default image format that is used for generating WebGraphics.

See Also:
Constant Field Values

context

protected WebContext context
Holds the reference to WebContext object.


imageBytes

protected byte[] imageBytes
Holds the WebGraphics image bytes.


extent

protected WebExtent extent
Holds the map's current extent. This is used for optimization purpose to prevent re-exporting web graphics when there is no change in extent.

See Also:
WebMap.getCurrentExtent()

pointGraphics

protected List<GraphicElement> pointGraphics
Holds the list of point graphics that are available in the WebGraphics.


lineGraphics

protected List<GraphicElement> lineGraphics
Holds the list of polyline graphics that are available in the WebGraphics.


polygonGraphics

protected List<GraphicElement> polygonGraphics
Holds the list of polygon graphics that are available in the WebGraphics.


pointImages

protected List<GraphicImage> pointImages
Holds the list of point images that are available in the WebGraphics.


lineImages

protected List<GraphicImage> lineImages
Holds the list of polyline images that are available in the WebGraphics.


polygonImages

protected List<GraphicImage> polygonImages
Holds the list of polygon images that are available in the WebGraphics.


images

protected List<GraphicImage> images
Holds the list of image that are available in the WebGraphics.


pointRenderers

protected List<GraphicRenderer> pointRenderers
Holds the list of point renderers that are available in the WebGraphics.


lineRenderers

protected List<GraphicRenderer> lineRenderers
Holds the list of polyline renderers that are available in the WebGraphics.


polygonRenderers

protected List<GraphicRenderer> polygonRenderers
Holds the list of polygon renderers that are available in the WebGraphics.

Constructor Detail

WebGraphics

public WebGraphics()
Method Detail

init

public void init(WebContext webContext)
Description copied from interface: WebContextInitialize

The initialization chores of attributes of a WebContext should be performed in this method.

Typically this method is called by the WebContext when the context itself is initialized. It is important to note that this method is again called by the context when a GISResource is dynamically added to or removed from the context. Classes that implement this method should keep this in mind and adapt the method to react to the callbacks in these circumstances as well.

A WebContext attribute is usable only after this method has been called.

Specified by:
init in interface WebContextInitialize
Parameters:
webContext - WebContext- the WebContext
See Also:
WebContext.init(WebContext), WebContext.addResource(String, GISResource, int), WebContext.removeResource(GISResource)

destroy

public void destroy()
Description copied from interface: WebContextInitialize

The cleaup chores (such as releasing held resources) of attributes of a WebContext should be performed in this method.

Typically this method is called by the WebContext when the context itself is destroyed.

The WebContext attribute is unusable after this method has been called.

Specified by:
destroy in interface WebContextInitialize
See Also:
WebContext.destroy()

getPointGraphics

public List<GraphicElement> getPointGraphics()
Returns the list of point graphics that are displayed in the map as WebGraphics.

Returns:
the list containing the point graphics

getLineGraphics

public List<GraphicElement> getLineGraphics()
Returns the list of line graphics that are displayed in the map as WebGraphics.

Returns:
the list containing the line graphics

getPolygonGraphics

public List<GraphicElement> getPolygonGraphics()
Returns the list of polygon graphics that are displayed in the map as WebGraphics.

Returns:
the list containing the polygon graphics

addGraphics

public void addGraphics(GraphicElement element)
Adds a point, multipoint, polyline or polygon graphic to the map.

Parameters:
element - the graphic element to add in the map

addImage

public void addImage(GraphicImage image)
Adds an image to the map.

Parameters:
image - the image to add in the map

addRenderer

public void addRenderer(GraphicRenderer renderer)
Adds a renderer to the map. The GraphicsRenderer being added to the map must have geometries and it must have a WebRenderer set. The method will do nothing if geometries and the WebRenderer have not been set.

Parameters:
renderer -

clearGraphics

public void clearGraphics()
Clears all graphic elements, images, and renderers from the WebGraphics object.


resetWebGraphics

public void resetWebGraphics()
This method resets the WebGraphics and forces the next exportGraphics() call to redraw the graphics even though the current extent of WebMap may not have changed. The graphic elements, images, and renderers are preserved. An example of when to use this method is if you modify the properties of a graphic element or renderer that has already been added to the WebGraphics object.


removeGraphics

public void removeGraphics(GraphicElement element)
Removes the specified element from WebGraphics.

Parameters:
element - the graphic element to remove
See Also:
addGraphics(GraphicElement)

removeImage

public void removeImage(GraphicImage image)
Removes the specified image from the WebGraphics.

Parameters:
image - the image to remove
See Also:
addImage(GraphicImage)

removeRenderer

public void removeRenderer(GraphicRenderer renderer)
Removes the specified renderer from the WebGraphics.

Parameters:
renderer - the renderer to remove
See Also:
addRenderer(GraphicRenderer)

isGraphicsExists

public boolean isGraphicsExists(GraphicElement element)
Determines if the element has already been added to the map. It does so by value comparison.

Parameters:
element - the element to be checked for existence
Returns:
true if the specified element exist in the map

isImageExists

public boolean isImageExists(GraphicImage image)
Determines if the image has already been added to the map. It does so by reference comparison of the GraphicImage object, it does not do a value comparison of the actual image or its type.

Parameters:
image - the image to be checked for existence
Returns:
true if the specified graphic image exist in the map

isRendererExists

public boolean isRendererExists(GraphicRenderer renderer)
Determines if the renderer has already been added to the map. It does so by reference comparison, it does not do a value comparison of renderer.

Parameters:
renderer - the renderer to be checked for existence
Returns:
true if the specified renderer exists in the map

isEmpty

public boolean isEmpty()
Returns true if no graphics elements, images, or renderers are currently referenced by the WebGraphics object.

Returns:
true if there are no graphics

isWebGraphicsChanged

public boolean isWebGraphicsChanged()
Determines whether WebGraphics changed or not. Basic assumption is that if current map extent does not change, WebGraphics does not change.

Returns:
true if the map current extent equals to the copy of the extent this object maintains

exportGraphics

public byte[] exportGraphics()
Exports all the graphics as a byte array based on the WebMap current state. For Example width, height, DPI, extent etc. The graphics are drawn only if there is a change in the map's current extent from the previous exportGraphics() call, otherwise it returns the copy of the byte array that this object holds. The byte array is in the PNG Image format. WEBGRAPHICS_IMAGE_FORMAT.

See Also:
resetWebGraphics()

exportGraphics

public byte[] exportGraphics(ExportProperties properties)
Draw all the graphics and return as a byte array. The byte array is always in the PNG Image format regardless of what is set in the properties parameter.

Parameters:
properties - the export properties that are used for drawing graphics.
See Also:
addGraphics(GraphicElement), addImage(GraphicImage), addRenderer(GraphicRenderer)