/** * 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.setWidth(legendOptionData.getImageWidth()); request.setHeight(legendOptionData.getImageHeight()); request.setTransparent(legendOptionData.isTransparent());
/** 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)); }
/** 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)); }
/** 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); }
/** 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); }