com.esri.adf.web.data.graphics
Class GraphicsResource

java.lang.Object
  extended by com.esri.adf.web.data.GISResource
      extended by com.esri.adf.web.data.graphics.GraphicsResource
All Implemented Interfaces:
WebContextInitialize, WebLifecycle, Serializable
Direct Known Subclasses:
DefaultGraphicsResource

public class GraphicsResource
extends GISResource

GraphicsResource is a GISResource that permits working with GraphicsLayers that originate and live solely in the ADF tier. GraphicsResource holds a list of GraphicsLayers.
For instance, you can use that class to display graphics like lines to highlight a route from a point A to a point B of an underlying resource.
The example below demonstrates how to declare and use a GraphicsResource to display waypoints on a WebMap:

 In the faces-config.xml:
 
   <managed-bean>
    <managed-bean-name>myGraphicsResource</managed-bean-name>
    <managed-bean-class>com.esri.adf.web.data.graphics.GraphicsResource</managed-bean-class>
    <managed-bean-scope>none</managed-bean-scope>
  </managed-bean>
 
 Programmatically :
 
  // Create the graphics resource we want to use to display the waypoints and add it to the WebContext
  GraphicsResource myGR = new GraphicsResource();
  // omitting to set the default spatial can result in inaccuracies in the display of the graphics
  myGR.setDefaultSpatialReference(WebSpatialReference.getWebSpatialReference(4326));  
  myGR.init(theWebContext);
  theWebContext.addResource("myGraphicsResource", myGR);
 
 Once the Resource has been declared:
 
  // Create a new GraphicsLayer that will contain the waypoints
  GraphicsLayer waypointLayer = new GraphicsLayer();
  waypointLayer.setName("Waypoints");
 
  // Create a renderer for the waypoint graphics layer
  WebSimpleRenderer rendererWpt = new WebSimpleRenderer();
  WebPictureMarkerSymbol symbolWpt = new WebPictureMarkerSymbol();
  symbolWpt.setFileName("images/maptips/sphere-green-16x16.png");
  symbolWpt.setWidth(5);
  rendererWpt.setSymbol(symbolWpt);
  waypointLayer.setRenderer(rendererWpt);
 
  // Create a highlight renderer for the waypoint graphics layer
  WebSimpleRenderer highlightRendererWpt = new WebSimpleRenderer();
  WebPictureMarkerSymbol highlightSymbolWpt = new WebPictureMarkerSymbol();
  highlightSymbolWpt.setFileName("images/maptips/sphere-red-16x16.png");
  highlightSymbolWpt.setWidth(5);
  highlightRendererWpt.setSymbol(highlightSymbolWpt);
  waypointLayer.setHighlightRenderer(highlightRendererWpt);
 
  // Create a callout template for the waypoint graphics layer 
  // to display the waypoint information in the callout windows
  StringBuffer calloutTemplate = new StringBuffer("<header>${Name}</header>");
  calloutTemplate.append("<body><table>");
  calloutTemplate.append("<tr><td>NAME: </td><td>${Name}</td></tr>");
  calloutTemplate.append("<tr><td>DESCRIPTION: </td><td>${Description}</td></tr>");
  calloutTemplate.append("<tr><td>TIME: </td><td>${Time}</td></tr>");
  calloutTemplate.append("<tr><td>ELEVATION: </td><td>${Elevation}</td></tr>");
  calloutTemplate.append("<tr><td>SYMBOLOGY: </td><td>${Symbology}</td></tr>");
  calloutTemplate.append("<tr><td>TYPE: </td><td>${Type}</td></tr>");
  calloutTemplate.append("</table></body>");
  waypointLayer.setCalloutTemplate(calloutTemplate.toString());
 
  // Add the graphics layer to the the graphics resource
  myGR.addGraphicsLayer(waypointLayer);
 
  // Once the graphics layer has been created, you can add graphics features to it 
  // that will be displayed according to the renderer, the highlight renderer and the callout defined
  GraphicFeature waypointGraphicsfeature = new GraphicFeature();
  
  // Create the WebPoint corresponding to the geolocation of the waypoint
  double lat = 34.056804;
  double lon = -117.194554;
  WebPoint drawPoint = new WebPoint(lon, lat, WebSpatialReference.getWebSpatialReference(4326));
  waypointGraphicsfeature.setGeometry(drawPoint);
    
  // Add some information to be used by the callout window for instance
  Map<String, String> attributes = new LinkedHashMap<String, String>();
  attributes.putAll([some information like Name, Description, ..., as expected by the callout template]); *
  waypointGraphicsfeature.setAttributes(attributes);
  
  // Add the graphics feature to the waypoint layer
  waypointLayer.addGraphicFeature(waypointGraphicsfeature);
 
 

See Also:
Serialized Form

Field Summary
protected  WebSpatialReference spatialReference
          Spatial reference for this resource
 
Fields inherited from class com.esri.adf.web.data.GISResource
alias, context, defaultSpatialReference, functionalities, hasFailedFunctionalities, init
 
Constructor Summary
GraphicsResource()
           
 
Method Summary
 int addGraphicsLayer(GraphicsLayer layer)
          Adds a GraphicsLayer to the internal list of GraphicsLayers.
 String getAlias()
           Returns a reader friendly name for this resource.
 List<GraphicsLayer> getLayers(boolean leafNodesOnly)
          Returns a list of all graphics layers.
 void init(WebContext wcontext)
           This method is called by the WebContext to initialize the resource.
 void removeAllGraphicsLayer()
          Removes all graphics layers.
 void removeGraphicsLayer(GraphicsLayer layer)
          Removes a given graphics layer.
 void setDefaultSpatialReference(WebSpatialReference spatialReference)
          Sets the default spatial reference of the resource
 
Methods inherited from class com.esri.adf.web.data.GISResource
activate, addFunctionality, destroy, getDefaultSpatialReference, getFunctionalities, getFunctionality, getWebContext, passivate, setAlias, setFunctionalities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spatialReference

protected WebSpatialReference spatialReference
Spatial reference for this resource

Constructor Detail

GraphicsResource

public GraphicsResource()
Method Detail

init

public void init(WebContext wcontext)
Description copied from class: GISResource

This method is called by the WebContext to initialize the resource. This is typically called when the context itself is initialized or when users add a new resource to the context by using the WebContext.addResource(String, GISResource) method. A GISResource is usable only after this method has been called.

This method iterates through all its supported GISFunctionalitys and calls the GISFunctionality.initFunctionality(GISResource) on them all.

Sub-classes that want to do custom initialization should override this method and make the super call first before doing the custom stuff:

 public void init(WebContext context) {
   super.init(context);
   myInit();
 }
 

Specified by:
init in interface WebContextInitialize
Overrides:
init in class GISResource
Parameters:
wcontext - the WebContext that maintains a reference to this resource
See Also:
WebContextInitialize.init(com.esri.adf.web.data.WebContext), GISFunctionality.initFunctionality(GISResource), WebContext.init(WebContext), WebContext.addResource(String, GISResource)

getAlias

public String getAlias()
Description copied from class: GISResource

Returns a reader friendly name for this resource.

It is a good practice for users to explicitly set an alias when the resource is created programmatically or declaratively. Resource providers should provide an auto-generated alias anyway in case users don't explicitly set an alias themselves.

Overrides:
getAlias in class GISResource
Returns:
a reader friendly name for this resource

setDefaultSpatialReference

public void setDefaultSpatialReference(WebSpatialReference spatialReference)
Sets the default spatial reference of the resource

Parameters:
spatialReference - the spatial reference to set

addGraphicsLayer

public int addGraphicsLayer(GraphicsLayer layer)
Adds a GraphicsLayer to the internal list of GraphicsLayers.

Parameters:
layer - a layer to be added
Returns:
id of the added layer

removeGraphicsLayer

public void removeGraphicsLayer(GraphicsLayer layer)
Removes a given graphics layer.

Parameters:
layer - a layer to be removed

removeAllGraphicsLayer

public void removeAllGraphicsLayer()
Removes all graphics layers.


getLayers

public List<GraphicsLayer> getLayers(boolean leafNodesOnly)
Returns a list of all graphics layers.

Parameters:
leafNodesOnly - determines whether instances of GroupGraphicsLayer should be returned
Returns:
the list of graphics layers