com\esri\adf\sample\graphics\MyGraphicsResource.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.adf.sample.graphics; import java.awt.image.BufferedImage; import java.io.Serializable; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.logging.Logger; import javax.faces.model.SelectItem; import com.esri.adf.web.data.TocFunctionality; import com.esri.adf.web.data.WebContext; import com.esri.adf.web.data.WebContextInitialize; import com.esri.adf.web.data.WebLayerInfo; import com.esri.adf.web.data.WebMap; import com.esri.adf.web.data.geometry.WebExtent; import com.esri.adf.web.data.geometry.WebGeometry; import com.esri.adf.web.data.geometry.WebMultiPoint; import com.esri.adf.web.data.geometry.WebPath; import com.esri.adf.web.data.geometry.WebPoint; import com.esri.adf.web.data.geometry.WebPolygon; import com.esri.adf.web.data.geometry.WebPolyline; import com.esri.adf.web.data.geometry.WebSpatialReference; import com.esri.adf.web.data.graphics.GraphicFeature; import com.esri.adf.web.data.graphics.GraphicsLayer; import com.esri.adf.web.data.graphics.GraphicsResource; import com.esri.adf.web.data.query.IdentifyCriteria; import com.esri.adf.web.data.query.QueryResult; import com.esri.adf.web.data.query.WebQuery; import com.esri.adf.web.data.renderer.WebClassBreakInfo; import com.esri.adf.web.data.renderer.WebClassBreaksRenderer; import com.esri.adf.web.data.renderer.WebGroupRenderer; import com.esri.adf.web.data.renderer.WebRenderer; import com.esri.adf.web.data.renderer.WebSimpleRenderer; import com.esri.adf.web.data.renderer.WebUniqueValueInfo; import com.esri.adf.web.data.renderer.WebUniqueValueRenderer; import com.esri.adf.web.data.results.ResultDefinition; import com.esri.adf.web.data.symbol.WebPictureMarkerSymbol; import com.esri.adf.web.data.symbol.WebSimpleLineSymbol; import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol; import com.esri.adf.web.data.symbol.WebSimplePolygonSymbol; import com.esri.adf.web.data.symbol.WebTrueTypeMarkerSymbol; import com.esri.adf.web.faces.event.MapEvent; import com.esri.internal.adf.web.data.display.ImportImage; public class MyGraphicsResource implements WebContextInitialize, Serializable { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(MyGraphicsResource.class.getName()); private WebContext webContext = null; private String graphicsLayerName = "Graphics Layer "; private short graphicsLayerCount = 0; private Map<String, String> actions = null; private int renderer = 3; private List<SelectItem> renderers = new ArrayList<SelectItem>(3); public void init(WebContext context) { this.webContext = context; WebSpatialReference sr = WebSpatialReference.getWebSpatialReference(4326); GraphicsResource gResource = (GraphicsResource) context.getResourceById("graphicsResource"); gResource.setDefaultSpatialReference(sr); WebMap wMap = this.webContext.getWebMap(); wMap.getInitExtent().setSpatialReference(sr); wMap.getFullExtent().setSpatialReference(sr); wMap.getCurrentExtent().setSpatialReference(sr); this.actions = new LinkedHashMap<String, String>(); this.actions.put("Zoom", "zoom"); this.actions.put("HighLight", "highlight"); this.actions.put("Clear Graphic", "clearGraphic"); this.renderers.add(new SelectItem(Integer.valueOf(1), "Simple Renderer", "Web Simple Renderer")); this.renderers.add(new SelectItem(Integer.valueOf(2), "Class Breaks Renderer", "Web Class Breaks Renderer")); this.renderers.add(new SelectItem(Integer.valueOf(3), "Unique Value Renderer", "Web Unique Value Renderer")); } public void destroy() { } public void identifyCriteria(MapEvent event) { WebGeometry geometry = event.getWebGeometry().toMapGeometry(event.getWebContext().getWebMap()); identifyCriteria(geometry); } public void identifyCriteria(WebGeometry geometry) { try { WebQuery webQuery = this.webContext.getWebQuery(); IdentifyCriteria ic = new IdentifyCriteria(geometry); List<WebLayerInfo> newInfo = new ArrayList<WebLayerInfo>(1); newInfo.add(WebQuery.allLayersOption); List<QueryResult> results = webQuery.query(ic, newInfo); ResultDefinition definition = new ResultDefinition(); definition.setHeader("My Result(s): " + geometry); definition.setDisplayNameMethodName("getName"); definition.setDetailsMethodName("getDetails"); definition.setActionMethodNames(this.actions); definition.setRemoveMethodName("clearGraphic"); this.webContext.getWebResults().addQueryResults(results, definition); } catch (Exception e) { WebGeometry geometry1 = null; if (geometry != null && this.webContext.getWebMap() != null) { geometry1 = geometry.toMapGeometry(this.webContext.getWebMap()); } else { geometry1 = geometry; } if (this.webContext.getWebResults() != null) { this.webContext.getWebResults().addResultsWithActionMap( "Identify Result(s) " + (geometry1 == null ? "" : geometry1.toString()), null, null, null, null); } } } public void addGraphicFeature(MapEvent event) { WebContext context = event.getWebContext(); WebGeometry geom = event.getMapGeometry(); GraphicsResource gResource = (GraphicsResource) context.getResourceById("graphicsResource"); WebSimpleRenderer simpleRenderer = new WebSimpleRenderer(); String layerName = this.graphicsLayerName + (++this.graphicsLayerCount); Map<String, String> attributes = new LinkedHashMap<String, String>(); attributes.put("Name", layerName); attributes.put("ID", new Integer(this.graphicsLayerCount).toString()); if (geom instanceof WebPoint) { GraphicsLayer gLayer = new GraphicsLayer(); GraphicFeature gFeature = new GraphicFeature(); WebPoint point = (WebPoint) geom; WebPictureMarkerSymbol markerSymbol = new WebPictureMarkerSymbol(); try { markerSymbol.setFileName("images/maptips/helicopter-red-32x32.png"); } catch (Exception ex1) { } simpleRenderer.setSymbol(markerSymbol); gFeature.setGeometry(point); gFeature.setAttributes(attributes); gLayer.setName(layerName); gLayer.addGraphicFeature(gFeature); gLayer.setRenderer(simpleRenderer); gResource.addGraphicsLayer(gLayer); } else if (geom instanceof WebExtent) { GraphicsLayer gLayer = new GraphicsLayer(); GraphicFeature gFeature = new GraphicFeature(); WebExtent extent = (WebExtent) geom; WebMultiPoint points = new WebMultiPoint(); points.addPoint(new WebPoint(extent.getMinX(), extent.getMaxY())); points.addPoint(new WebPoint(extent.getMaxX(), extent.getMaxY())); points.addPoint(new WebPoint(extent.getMinX(), extent.getMinY())); points.addPoint(new WebPoint(extent.getMaxX(), extent.getMinY())); WebPictureMarkerSymbol markerSymbol = new WebPictureMarkerSymbol(); try { markerSymbol.setFileName("images/maptips/flag-bl-yellow-16x16.png"); } catch (Exception ex1) { } simpleRenderer.setSymbol(markerSymbol); gFeature.setGeometry(points); gFeature.setAttributes(attributes); gLayer.setName(layerName); gLayer.addGraphicFeature(gFeature); gLayer.setRenderer(simpleRenderer); gResource.addGraphicsLayer(gLayer); } else if (geom instanceof WebPolyline) { GraphicsLayer gLayer = new GraphicsLayer(); GraphicFeature gFeature = new GraphicFeature(); WebPolyline polyline = (WebPolyline) geom; WebSimpleLineSymbol lineSymbol = new WebSimpleLineSymbol(); simpleRenderer.setSymbol(lineSymbol); gFeature.setGeometry(polyline); gFeature.setAttributes(attributes); gLayer.setName(layerName); gLayer.addGraphicFeature(gFeature); gLayer.setRenderer(simpleRenderer); gResource.addGraphicsLayer(gLayer); } else if (geom instanceof WebPolygon) { GraphicsLayer gLayer = new GraphicsLayer(); GraphicFeature gFeature = new GraphicFeature(); WebPolygon polygon = (WebPolygon) geom; WebSimplePolygonSymbol polygonSymbol = new WebSimplePolygonSymbol(); // polygonSymbol.setFillTransparency(0.5); BufferedImage bImage = null; try { bImage = ImportImage.getImage(this.getClass().getClassLoader().getResourceAsStream( "/images/maptips/info-16x16.png")); polygonSymbol.setFillTexture(bImage); polygonSymbol.setFillType(WebSimplePolygonSymbol.TEXTURE); } catch (Exception ex) { } simpleRenderer.setSymbol(polygonSymbol); gFeature.setGeometry(polygon); gFeature.setAttributes(attributes); gLayer.setName(layerName); gLayer.addGraphicFeature(gFeature); gLayer.setRenderer(simpleRenderer); gResource.addGraphicsLayer(gLayer); } this.refresh(); } public void addRendererGraphicsLayer(MapEvent event) { WebGeometry geometry = event.getWebGeometry(); if (!(geometry instanceof WebPolyline)) { logger .severe("Unable to add render, the given geometry should be of type WebPolyline. Use adf.MapPolyline client action."); return; } WebPolyline polyline = (WebPolyline) event.getMapGeometry(); WebContext context = event.getWebContext(); WebRenderer wr = null; WebSimpleMarkerSymbol defaultMarkerSymbol = new WebSimpleMarkerSymbol(); defaultMarkerSymbol.setColor("0,0,255"); defaultMarkerSymbol.setWidth(10); String defaultField = null; String defaultLabel = "Default Label"; if (this.renderer == 1) { WebSimpleRenderer wsr = new WebSimpleRenderer(); wsr.setSymbol(defaultMarkerSymbol); wr = wsr; } else if (this.renderer == 2) { defaultField = "Type"; WebUniqueValueRenderer wuvr = new WebUniqueValueRenderer(); defaultMarkerSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); wuvr.setDefaultSymbol(defaultMarkerSymbol); wuvr.setDefaultLabel(defaultLabel); wuvr.setField1(defaultField); wuvr.setField2(null); wuvr.setField3(null); wuvr.setFieldDelimiter(null); List<WebUniqueValueInfo> infos = new ArrayList<WebUniqueValueInfo>(5); WebSimpleMarkerSymbol redMS = new WebSimpleMarkerSymbol(); redMS.setColor("255,0,0"); redMS.setWidth(15); redMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); WebUniqueValueInfo uvi = new WebUniqueValueInfo("Red Color(1)", "Value is 1", "1", redMS); infos.add(uvi); WebSimpleMarkerSymbol greenMS = new WebSimpleMarkerSymbol(); greenMS.setColor("0,255,0"); greenMS.setWidth(20); greenMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi = new WebUniqueValueInfo("Green Color(2)", "Value is 2", "2", greenMS); infos.add(uvi); WebSimpleMarkerSymbol blueMS = new WebSimpleMarkerSymbol(); blueMS.setColor("0,0,255"); blueMS.setWidth(25); blueMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi = new WebUniqueValueInfo("Blue Color(3)", "Value is 3", "3", blueMS); infos.add(uvi); WebSimpleMarkerSymbol yellowMS = new WebSimpleMarkerSymbol(); yellowMS.setColor("255,255,0"); yellowMS.setWidth(30); yellowMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi = new WebUniqueValueInfo("Yellow Color(4)", "Value is 4", "4", yellowMS); infos.add(uvi); WebSimpleMarkerSymbol cyanMS = new WebSimpleMarkerSymbol(); cyanMS.setColor("0,255,255"); cyanMS.setWidth(35); cyanMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi = new WebUniqueValueInfo("Cyan Color(5)", "Value is 5", "5", cyanMS); infos.add(uvi); wuvr.setUniqueValueInfos(infos); wr = wuvr; } else if (this.renderer == 3) { defaultField = "Break"; WebClassBreaksRenderer wcbr = new WebClassBreaksRenderer(); defaultMarkerSymbol.setMarkerType(WebSimpleMarkerSymbol.STAR); wcbr.setDefaultSymbol(defaultMarkerSymbol); wcbr.setDefaultLabel(defaultLabel); wcbr.setField(defaultField); wcbr.setMinimumValue(0); List<WebClassBreakInfo> infos = new ArrayList<WebClassBreakInfo>(5); WebSimpleMarkerSymbol redMS = new WebSimpleMarkerSymbol(); redMS.setColor("255,0,0"); redMS.setWidth(15); redMS.setMarkerType(WebSimpleMarkerSymbol.STAR); WebClassBreakInfo cbi = new WebClassBreakInfo("0 - 5", "Value Greater than or equal to 0 and Less than or equal to 5", 5, redMS); infos.add(cbi); WebSimpleMarkerSymbol greenMS = new WebSimpleMarkerSymbol(); greenMS.setColor("0,255,0"); greenMS.setWidth(20); greenMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi = new WebClassBreakInfo("6 - 10", "Value Greater than 5 and Less than or equal to 10", 10, greenMS); infos.add(cbi); WebSimpleMarkerSymbol blueMS = new WebSimpleMarkerSymbol(); blueMS.setColor("0,0,255"); blueMS.setWidth(25); blueMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi = new WebClassBreakInfo("11 - 15", "Value Greater than 10 and Less than or equal to 15", 15, blueMS); infos.add(cbi); WebSimpleMarkerSymbol yellowMS = new WebSimpleMarkerSymbol(); yellowMS.setColor("255,255,0"); yellowMS.setWidth(30); yellowMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi = new WebClassBreakInfo("16 - 20", "Value Greater than 15 and Less than or equal to 20", 20, yellowMS); infos.add(cbi); WebSimpleMarkerSymbol cyanMS = new WebSimpleMarkerSymbol(); cyanMS.setColor("0,255,255"); cyanMS.setWidth(35); cyanMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi = new WebClassBreakInfo("21 - 25", "Value Greater than 20 and Less than or equal to 25", 25, cyanMS); infos.add(cbi); wcbr.setClassBreakInfos(infos); wr = wcbr; } GraphicsResource gResource = (GraphicsResource) context.getResourceById("graphicsResource"); String layerName = this.graphicsLayerName + (++this.graphicsLayerCount); GraphicsLayer gLayer = new GraphicsLayer(); gLayer.setName(layerName); GraphicFeature gFeature = null; Map<String, String> attributes = null; Random randVal = new Random(); int i = 0; for (WebPath path : polyline.getPaths()) { if (path == null) { continue; } for (WebPoint point : path.getPoints()) { if (point == null) { continue; } gFeature = new GraphicFeature(); attributes = new LinkedHashMap<String, String>(); attributes.put("Name", layerName); attributes.put("ID", new Integer(this.graphicsLayerCount).toString() + "(" + (++i) + ")"); if (this.renderer == 2) { attributes.put(defaultField, String.valueOf(randVal.nextInt(5) + 1)); } else if (this.renderer == 3) { attributes.put(defaultField, String.valueOf(randVal.nextInt(30) + 1)); } gFeature.setAttributes(attributes); gFeature.setGeometry(point); gLayer.addGraphicFeature(gFeature); } } gLayer.setRenderer(wr); gResource.addGraphicsLayer(gLayer); this.refresh(); } public void addGroupRendererGraphicsLayer(MapEvent event) { WebGeometry geometry = event.getWebGeometry(); if (!(geometry instanceof WebPolyline)) { logger .severe("Unable to add render, the given geometry should be of type WebPolyline. Use adf.MapPolyline client action."); return; } WebPolyline polyline = (WebPolyline) event.getMapGeometry(); WebContext context = event.getWebContext(); WebGroupRenderer wgr = new WebGroupRenderer(); WebSimpleMarkerSymbol defaultMarkerSymbol = new WebSimpleMarkerSymbol(); defaultMarkerSymbol.setColor("0,0,255"); defaultMarkerSymbol.setWidth(10); WebTrueTypeMarkerSymbol defaultLabelSymbol = new WebTrueTypeMarkerSymbol(); defaultLabelSymbol.setAntialiasing(true); defaultLabelSymbol.setFontColor("0,0,255"); defaultLabelSymbol.setFontSize(10); defaultLabelSymbol.addTextValue("Default"); defaultLabelSymbol.setXOffset(30.0); defaultLabelSymbol.setYOffset(-20.0); String defaultField = null; String defaultLabel = "Default Label"; if (this.renderer == 1) { WebSimpleRenderer wsr1 = new WebSimpleRenderer(); wsr1.setSymbol(defaultMarkerSymbol); WebSimpleRenderer wsr2 = new WebSimpleRenderer(); wsr2.setSymbol(defaultLabelSymbol); wgr.addRenderer(wsr1); wgr.addRenderer(wsr2); } else if (this.renderer == 2) { defaultField = "Type"; WebUniqueValueRenderer wuvr1 = new WebUniqueValueRenderer(); defaultMarkerSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); wuvr1.setDefaultSymbol(defaultMarkerSymbol); wuvr1.setDefaultLabel(defaultLabel); wuvr1.setField1(defaultField); wuvr1.setField2(null); wuvr1.setField3(null); wuvr1.setFieldDelimiter(null); List<WebUniqueValueInfo> infos1 = new ArrayList<WebUniqueValueInfo>(5); WebSimpleMarkerSymbol redMS = new WebSimpleMarkerSymbol(); redMS.setColor("255,0,0"); redMS.setWidth(15); redMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); WebUniqueValueInfo uvi1 = new WebUniqueValueInfo("Red Color(1)", "Value is 1", "1", redMS); infos1.add(uvi1); WebSimpleMarkerSymbol greenMS = new WebSimpleMarkerSymbol(); greenMS.setColor("0,255,0"); greenMS.setWidth(20); greenMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi1 = new WebUniqueValueInfo("Green Color(2)", "Value is 2", "2", greenMS); infos1.add(uvi1); WebSimpleMarkerSymbol blueMS = new WebSimpleMarkerSymbol(); blueMS.setColor("0,0,255"); blueMS.setWidth(25); blueMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi1 = new WebUniqueValueInfo("Blue Color(3)", "Value is 3", "3", blueMS); infos1.add(uvi1); WebSimpleMarkerSymbol yellowMS = new WebSimpleMarkerSymbol(); yellowMS.setColor("255,255,0"); yellowMS.setWidth(30); yellowMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi1 = new WebUniqueValueInfo("Yellow Color(4)", "Value is 4", "4", yellowMS); infos1.add(uvi1); WebSimpleMarkerSymbol cyanMS = new WebSimpleMarkerSymbol(); cyanMS.setColor("0,255,255"); cyanMS.setWidth(35); cyanMS.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); uvi1 = new WebUniqueValueInfo("Cyan Color(5)", "Value is 5", "5", cyanMS); infos1.add(uvi1); wuvr1.setUniqueValueInfos(infos1); WebUniqueValueRenderer wuvr2 = new WebUniqueValueRenderer(); wuvr2.setDefaultSymbol(defaultLabelSymbol); wuvr2.setDefaultLabel(defaultLabel); wuvr2.setField1(defaultField); wuvr2.setField2(null); wuvr2.setField3(null); wuvr2.setFieldDelimiter(null); List<WebUniqueValueInfo> infos2 = new ArrayList<WebUniqueValueInfo>(5); WebTrueTypeMarkerSymbol redTTMS = new WebTrueTypeMarkerSymbol(); redTTMS.setAntialiasing(true); redTTMS.setFontColor("255,0,0"); redTTMS.setFontSize(10); redTTMS.addTextValue("Red"); redTTMS.setXOffset(20.0); redTTMS.setYOffset(-15.0); WebUniqueValueInfo uvi2 = new WebUniqueValueInfo("Red Color(1)", "Value is 1", "1", redTTMS); infos2.add(uvi2); WebTrueTypeMarkerSymbol greenTTMS = new WebTrueTypeMarkerSymbol(); greenTTMS.setAntialiasing(true); greenTTMS.setFontColor("0,255,0"); greenTTMS.setFontSize(15); greenTTMS.addTextValue("Green"); greenTTMS.setXOffset(30.0); greenTTMS.setYOffset(-20.0); uvi2 = new WebUniqueValueInfo("Green Color(2)", "Value is 2", "2", greenTTMS); infos2.add(uvi2); WebTrueTypeMarkerSymbol blueTTMS = new WebTrueTypeMarkerSymbol(); blueTTMS.setAntialiasing(true); blueTTMS.setFontColor("0,0,255"); blueTTMS.setFontSize(20); blueTTMS.addTextValue("Blue"); blueTTMS.setXOffset(30.0); blueTTMS.setYOffset(-20.0); uvi2 = new WebUniqueValueInfo("Blue Color(3)", "Value is 3", "3", blueTTMS); infos2.add(uvi2); WebTrueTypeMarkerSymbol yellowTTMS = new WebTrueTypeMarkerSymbol(); yellowTTMS.setAntialiasing(true); yellowTTMS.setFontColor("255,255,0"); yellowTTMS.setFontSize(25); yellowTTMS.addTextValue("Yellow"); yellowTTMS.setXOffset(40.0); yellowTTMS.setYOffset(-28.0); uvi2 = new WebUniqueValueInfo("Yellow Color(4)", "Value is 4", "4", yellowTTMS); infos2.add(uvi2); WebTrueTypeMarkerSymbol cyanTTMS = new WebTrueTypeMarkerSymbol(); cyanTTMS.setAntialiasing(true); cyanTTMS.setFontColor("0,255,255"); cyanTTMS.setFontSize(30); cyanTTMS.addTextValue("Cyan"); cyanTTMS.setXOffset(35.0); cyanTTMS.setYOffset(-30.0); uvi2 = new WebUniqueValueInfo("Cyan Color(5)", "Value is 5", "5", cyanTTMS); infos2.add(uvi2); wuvr2.setUniqueValueInfos(infos2); wgr.addRenderer(wuvr1); wgr.addRenderer(wuvr2); } else if (this.renderer == 3) { defaultField = "Break"; WebClassBreaksRenderer wcbr1 = new WebClassBreaksRenderer(); defaultMarkerSymbol.setMarkerType(WebSimpleMarkerSymbol.STAR); wcbr1.setDefaultSymbol(defaultMarkerSymbol); wcbr1.setDefaultLabel(defaultLabel); wcbr1.setField(defaultField); wcbr1.setMinimumValue(0); List<WebClassBreakInfo> infos1 = new ArrayList<WebClassBreakInfo>(5); WebSimpleMarkerSymbol redMS = new WebSimpleMarkerSymbol(); redMS.setColor("255,0,0"); redMS.setWidth(15); redMS.setMarkerType(WebSimpleMarkerSymbol.STAR); WebClassBreakInfo cbi1 = new WebClassBreakInfo("0 - 5", "Value Greater than or equal to 0 and Less than or equal to 5", 5, redMS); infos1.add(cbi1); WebSimpleMarkerSymbol greenMS = new WebSimpleMarkerSymbol(); greenMS.setColor("0,255,0"); greenMS.setWidth(20); greenMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi1 = new WebClassBreakInfo("6 - 10", "Value Greater than 5 and Less than or equal to 10", 10, greenMS); infos1.add(cbi1); WebSimpleMarkerSymbol blueMS = new WebSimpleMarkerSymbol(); blueMS.setColor("0,0,255"); blueMS.setWidth(25); blueMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi1 = new WebClassBreakInfo("11 - 15", "Value Greater than 10 and Less than or equal to 15", 15, blueMS); infos1.add(cbi1); WebSimpleMarkerSymbol yellowMS = new WebSimpleMarkerSymbol(); yellowMS.setColor("255,255,0"); yellowMS.setWidth(30); yellowMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi1 = new WebClassBreakInfo("16 - 20", "Value Greater than 15 and Less than or equal to 20", 20, yellowMS); infos1.add(cbi1); WebSimpleMarkerSymbol cyanMS = new WebSimpleMarkerSymbol(); cyanMS.setColor("0,255,255"); cyanMS.setWidth(35); cyanMS.setMarkerType(WebSimpleMarkerSymbol.STAR); cbi1 = new WebClassBreakInfo("21 - 25", "Value Greater than 20 and Less than or equal to 25", 25, cyanMS); infos1.add(cbi1); wcbr1.setClassBreakInfos(infos1); WebClassBreaksRenderer wcbr2 = new WebClassBreaksRenderer(); wcbr2.setDefaultSymbol(defaultLabelSymbol); wcbr2.setDefaultLabel(defaultLabel); wcbr2.setField(defaultField); wcbr2.setMinimumValue(0); List<WebClassBreakInfo> infos2 = new ArrayList<WebClassBreakInfo>(5); WebTrueTypeMarkerSymbol redTTMS = new WebTrueTypeMarkerSymbol(); redTTMS.setAntialiasing(true); redTTMS.setFontColor("255,0,0"); redTTMS.setFontSize(10); redTTMS.addTextValue("Red"); redTTMS.setXOffset(20.0); redTTMS.setYOffset(-15.0); WebClassBreakInfo cbi2 = new WebClassBreakInfo("0 - 5", "Value Greater than or equal to 0 and Less than or equal to 5", 5, redTTMS); infos2.add(cbi2); WebTrueTypeMarkerSymbol greenTTMS = new WebTrueTypeMarkerSymbol(); greenTTMS.setAntialiasing(true); greenTTMS.setFontColor("0,255,0"); greenTTMS.setFontSize(15); greenTTMS.addTextValue("Green"); greenTTMS.setXOffset(30.0); greenTTMS.setYOffset(-20.0); cbi2 = new WebClassBreakInfo("6 - 10", "Value Greater than 5 and Less than or equal to 10", 10, greenTTMS); infos2.add(cbi2); WebTrueTypeMarkerSymbol blueTTMS = new WebTrueTypeMarkerSymbol(); blueTTMS.setAntialiasing(true); blueTTMS.setFontColor("0,0,255"); blueTTMS.setFontSize(20); blueTTMS.addTextValue("Blue"); blueTTMS.setXOffset(30.0); blueTTMS.setYOffset(-20.0); cbi2 = new WebClassBreakInfo("11 - 15", "Value Greater than 10 and Less than or equal to 15", 15, blueTTMS); infos2.add(cbi2); WebTrueTypeMarkerSymbol yellowTTMS = new WebTrueTypeMarkerSymbol(); yellowTTMS.setAntialiasing(true); yellowTTMS.setFontColor("255,255,0"); yellowTTMS.setFontSize(25); yellowTTMS.addTextValue("Yellow"); yellowTTMS.setXOffset(40.0); yellowTTMS.setYOffset(-28.0); cbi2 = new WebClassBreakInfo("16 - 20", "Value Greater than 15 and Less than or equal to 20", 20, yellowTTMS); infos2.add(cbi2); WebTrueTypeMarkerSymbol cyanTTMS = new WebTrueTypeMarkerSymbol(); cyanTTMS.setAntialiasing(true); cyanTTMS.setFontColor("0,255,255"); cyanTTMS.setFontSize(30); cyanTTMS.addTextValue("Cyan"); cyanTTMS.setXOffset(35.0); cyanTTMS.setYOffset(-30.0); cbi2 = new WebClassBreakInfo("21 - 25", "Value Greater than 20 and Less than or equal to 25", 25, cyanTTMS); infos2.add(cbi2); wcbr2.setClassBreakInfos(infos2); wgr.addRenderer(wcbr1); wgr.addRenderer(wcbr2); } GraphicsResource gResource = (GraphicsResource) context.getResourceById("graphicsResource"); String layerName = this.graphicsLayerName + (++this.graphicsLayerCount); GraphicsLayer gLayer = new GraphicsLayer(); gLayer.setName(layerName); GraphicFeature gFeature = null; Map<String, String> attributes = null; Random randVal = new Random(); int i = 0; for (WebPath path : polyline.getPaths()) { if (path == null) { continue; } for (WebPoint point : path.getPoints()) { if (point == null) { continue; } gFeature = new GraphicFeature(); attributes = new LinkedHashMap<String, String>(); attributes.put("Name", layerName); attributes.put("ID", new Integer(this.graphicsLayerCount).toString() + "(" + (++i) + ")"); if (this.renderer == 2) { attributes.put(defaultField, String.valueOf(randVal.nextInt(5) + 1)); } else if (this.renderer == 3) { attributes.put(defaultField, String.valueOf(randVal.nextInt(30) + 1)); } gFeature.setAttributes(attributes); gFeature.setGeometry(point); gLayer.addGraphicFeature(gFeature); } } gLayer.setRenderer(wgr); gResource.addGraphicsLayer(gLayer); this.refresh(); } public void clearGraphicsLayers() { GraphicsResource gResource = (GraphicsResource) this.webContext.getResourceById("graphicsResource"); gResource.removeAllGraphicsLayer(); this.refresh(); } public void setRenderer(int renderer) { this.renderer = renderer; } public int getRenderer() { return this.renderer; } public List<SelectItem> getRenderers() { return this.renderers; } private void refresh() { if (this.webContext.getWebToc() != null) { GraphicsResource gResource = (GraphicsResource) this.webContext.getResourceById("graphicsResource"); this.webContext.getWebToc().init( (TocFunctionality) gResource.getFunctionality(TocFunctionality.FUNCTIONALITY_NAME)); } if (this.webContext.getWebOverview() != null) { this.webContext.getWebOverview().exportImage(); } if (this.webContext.getWebQuery() != null) { this.webContext.getWebQuery().init(this.webContext); } this.webContext.refresh(); } }