/** * Ensures the online resource is stored on the GetLegendGraphicRequest and native dimensions * are configured if not specified on the original request. * * @param request GetLegendGraphicRequest original KWP Request * @param legend LegendRequest internal Class containing references to Resources * @param legendInfo LegendInfo used to document use external graphic */ private void configureLegendInfo( GetLegendGraphicRequest request, LegendRequest legend, LegendInfo legendInfo) { legend.setLegendInfo(legendInfo); if (legendInfo.getHeight() > 0 && !request.getKvp().containsKey("HEIGHT")) { request.setHeight(legendInfo.getHeight()); } if (legendInfo.getWidth() > 0 && !request.getKvp().containsKey("WIDTH")) { request.setWidth(legendInfo.getWidth()); } } /**
request.setHeight(legendOptionData.getImageHeight()); request.setTransparent(legendOptionData.isTransparent()); request.setStrict(false);
/** Tests horizontal layout for vector */ @org.junit.Test public void testVectorLayersHorizontal() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), MockData.ROAD_SEGMENTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle()); final int HEIGHT_HINT = 20; req.setHeight(HEIGHT_HINT); HashMap legendOptions = new HashMap(); legendOptions.put("layout", "horizontal"); legendOptions.put("forceLabels", "off"); req.setLegendOptions(legendOptions); this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertEquals(HEIGHT_HINT, image.getHeight()); assertPixel(image, 10, HEIGHT_HINT / 2, new Color(192, 160, 0)); assertPixel(image, 50, HEIGHT_HINT / 2, new Color(224, 64, 0)); }
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testThickPolygonBorder() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(20); req.setHeight(20); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ThickBorder.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("testThickPolygonBorder", image, LegendUtils.DEFAULT_BG_COLOR); // thick symbol, there is padding, black thick border, and center assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 6, 6, new Color(0, 0, 0)); assertPixel(image, 10, 10, new Color(255, 0, 0)); // second symbol, padding, border, green center assertPixel(image, 1, 21, new Color(255, 255, 255)); // assertPixel(image, 4, 25, new Color(0, 0, 0)); // unsafe, the border is thin here assertPixel(image, 10, 30, new Color(0, 255, 0)); }
req.setHeight(HEIGHT_HINT);
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testThickPolygonAsymmetricSymbol() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(40); req.setHeight(20); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ThickBorder.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("testThickPolygonBorder", image, LegendUtils.DEFAULT_BG_COLOR); // thick symbol, there is padding, black thick border, and center assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 9, 6, new Color(0, 0, 0)); assertPixel(image, 20, 10, new Color(255, 0, 0)); // second symbol, padding, border, green center assertPixel(image, 1, 23, new Color(255, 255, 255)); // assertPixel(image, 4, 25, new Color(0, 0, 0)); // unsafe, the border is thin here assertPixel(image, 20, 30, new Color(0, 255, 0)); }
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT); HashMap legendOptions = new HashMap(); req.setLegendOptions(legendOptions);
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testSimpleLine() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(20); req.setHeight(20); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("line.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("line", image, LegendUtils.DEFAULT_BG_COLOR); // line in the middle, but off the middle, it's white Color colorCenter = getPixelColor(image, 10, 10); assertColorSimilar(Color.BLUE, colorCenter, 20); Color colorOutsideCenter = getPixelColor(image, 6, 6); assertColorSimilar(Color.WHITE, colorOutsideCenter, 20); }
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testLargeCirclePlacement() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(48); req.setHeight(25); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("largeCircle.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("largeCircle", image, LegendUtils.DEFAULT_BG_COLOR); // the border is visible both top middle and bottom middle. Different JDK // build wildly different colors for the border unfortunately, so the test // checks that pixels at top/middle bottom/middle are similar color (they used to be // different, significantly) Color colorTop = getPixelColor(image, 24, 0); Color colorBottom = getPixelColor(image, 24, 24); assertColorSimilar(colorTop, colorBottom, 20); }
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);
/** * Tests that the legend graphic is still produced when the request's strict parameter is set to * false and a layer is not specified */ @org.junit.Test public void testNoLayerProvidedAndNonStrictRequest() throws Exception { Style style = getCatalog().getStyleByName("rainfall").getStyle(); assertNotNull(style); GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setStrict(false); req.setLayer(null); req.setStyle(style); final int HEIGHT_HINT = 30; req.setHeight(HEIGHT_HINT); // use default values for the rest of parameters this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); } /** Tests that the legend graphic is produced for multiple layers */
req.setHeight(HEIGHT_HINT);
req.setHeight(HEIGHT_HINT);