|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.esri.adf.web.data.GISResource com.esri.adf.web.data.graphics.GraphicsResource
public class GraphicsResource
GraphicsResource is a GISResource
that permits working with
GraphicsLayer
s that originate and live solely in the ADF tier.
GraphicsResource holds a list of GraphicsLayer
s.
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);
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 |
---|
protected WebSpatialReference spatialReference
Constructor Detail |
---|
public GraphicsResource()
Method Detail |
---|
public void init(WebContext wcontext)
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 GISFunctionality
s 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(); }
init
in interface WebContextInitialize
init
in class GISResource
wcontext
- the WebContext
that maintains a reference to this resourceWebContextInitialize.init(com.esri.adf.web.data.WebContext)
,
GISFunctionality.initFunctionality(GISResource)
,
WebContext.init(WebContext)
,
WebContext.addResource(String, GISResource)
public String getAlias()
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.
getAlias
in class GISResource
public void setDefaultSpatialReference(WebSpatialReference spatialReference)
spatialReference
- the spatial reference to setpublic int addGraphicsLayer(GraphicsLayer layer)
layer
- a layer to be added
public void removeGraphicsLayer(GraphicsLayer layer)
layer
- a layer to be removedpublic void removeAllGraphicsLayer()
public List<GraphicsLayer> getLayers(boolean leafNodesOnly)
leafNodesOnly
- determines whether instances of GroupGraphicsLayer should be returned
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |