/** * Builds and returns a {@link BufferedImageLegendGraphic} appropriate to be encoded as PNG * * @see GetLegendGraphicOutputFormat#produceLegendGraphic(GetLegendGraphicRequest) */ public BufferedImageLegendGraphic produceLegendGraphic(GetLegendGraphicRequest request) throws ServiceException { BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder(); BufferedImage legendGraphic = builder.buildLegendGraphic(request); BufferedImageLegendGraphic legend = new BufferedImageLegendGraphic(legendGraphic); return legend; }
@Override protected Rule[] updateRuleTitles( FeatureCountProcessor processor, LegendRequest legend, Rule[] applicableRules) { Rule[] updatedRules = super.updateRuleTitles(processor, legend, applicableRules); FeatureCountLegendGraphicTest.this.ruleSets.add(updatedRules); return updatedRules; } };
/** * Creates a sample Feature instance in the hope that it can be used in the rendering of the * legend graphic, using the given dimensionality for the geometry attribute. * * @param schema the schema for which to create a sample Feature instance * @param dimensionality the geometry dimensionality required (ovverides the one defined in the * schema) 1= points, 2= lines, 3= polygons * @throws ServiceException */ private Feature createSampleFeature(FeatureType schema, int dimensionality) throws ServiceException { if (schema instanceof SimpleFeatureType) { schema = cloneWithDimensionality(schema, dimensionality); } return createSampleFeature(schema); }
req.setLegendOptions(legendOptions); this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertEquals(HEIGHT_HINT * 2, image.getHeight()); for (int x = 21; x <= 29; x++) { req.setLegendOptions(legendOptions); this.legendProducer.buildLegendGraphic(req); image = this.legendProducer.buildLegendGraphic(req); assertEquals(HEIGHT_HINT * 2, image.getHeight()); for (int x = 21; x <= 39; x++) {
titleImage = getLayerTitle(legend, w, h, transparent, request); legendImage = getLayerLegend(legend, w, h, transparent, request); final Feature sampleFeature; if (layer == null || hasVectorTransformation) { sampleFeature = createSampleFeature(); } else { sampleFeature = createSampleFeature(layer); applicableRules = updateRuleTitles(countProcessor, legend, applicableRules); calcSymbolSize( defaultSize, minimumSymbolSize, getSampleFeatureForRule(layer, sampleFeature, applicableRules[i]); LiteShape2 shape = getSampleShape(symbolizer, w, h, w, h); if (rescalingRequired && (symbolizer instanceof PointSymbolizer || symbolizer instanceof LineSymbolizer)) { double size = getSymbolizerSize( estimator, symbolizer, Math.min(w, h) - 4); double newSize = rescaler.apply(size); symbolizer = rescaleSymbolizer(symbolizer, size, newSize); } else if (symbolizer instanceof PolygonSymbolizer) {
builder.setCRS(schema.getCoordinateReferenceSystem()); for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) { if (isMixedGeometry(desc)) { GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc; GeometryType geomType = geomDescriptor.getType(); Class<?> geometryClass = getGeometryForDimensionality(dimensionality);
return createSampleFeature(featureType, dimensionality); } else { return sample;
/** 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 minSymbolSize legend option is respected. */ @org.junit.Test public void testInternationalizedLabels() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); Map<String, String> options = new HashMap<String, String>(); options.put("forceLabels", "on"); req.setLegendOptions(options); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("Internationalized.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); int noLocalizedWidth = image.getWidth(); req.setLocale(Locale.ITALIAN); image = this.legendProducer.buildLegendGraphic(req); // test that using localized labels we get a different label than when not using it int itWidth = image.getWidth(); assertTrue(itWidth != noLocalizedWidth); req.setLocale(Locale.ENGLISH); image = this.legendProducer.buildLegendGraphic(req); // test that using localized labels we get a different label than when not using it int enWidth = image.getWidth(); assertTrue(enWidth != noLocalizedWidth); assertTrue(enWidth != itWidth); }
/** * @return a {@link BufferedImageLegendGraphic} * @see GetLegendGraphicOutputFormat#produceLegendGraphic(GetLegendGraphicRequest) * @see BufferedImageLegendGraphicBuilder */ public BufferedImageLegendGraphic produceLegendGraphic(GetLegendGraphicRequest request) throws ServiceException { BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder(); BufferedImage legendGraphic = builder.buildLegendGraphic(request); BufferedImageLegendGraphic legend = new BufferedImageLegendGraphic(legendGraphic); return legend; }
this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req);
/** * Builds a JPEG {@link BufferedImageLegendGraphic} * * @return a {@link BufferedImageLegendGraphic} holding a legend image appropriate to be encoded * as JPEG * @see GetLegendGraphicOutputFormat#produceLegendGraphic(GetLegendGraphicRequest) */ public BufferedImageLegendGraphic produceLegendGraphic(GetLegendGraphicRequest request) throws ServiceException { request.setTransparent(false); BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder(); BufferedImage legendGraphic = builder.buildLegendGraphic(request); BufferedImageLegendGraphic legend = new BufferedImageLegendGraphic(legendGraphic); return legend; }
req.setStyles(styles); this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req);
new BufferedImageLegendGraphicBuilder(); GetLegendGraphicRequest request = new GetLegendGraphicRequest(); request.setLayer(layer.getFeatureSource().getSchema()); BufferedImage legendImage = legendGraphicBuilder.buildLegendGraphic(request); legend.legend = legendImage;
this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); req.getLegends().add(legend); this.legendProducer.buildLegendGraphic(req); image = this.legendProducer.buildLegendGraphic(req);
request.setLegendOptions(legendOptions); BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder(); legendImage = builder.buildLegendGraphic(request); legendImg.setVisible(true);
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testProportionalSymbolsLine() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbolsLine.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("ProportionalSymbolsLine", image, LegendUtils.DEFAULT_BG_COLOR); // biggest symbol, thick border assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside assertPixel(image, 5, 5, new Color(0, 0, 0)); // border assertPixel(image, 7, 12, new Color(255, 0, 0)); // inside // second symbol, small, no border assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside }
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testProportionalSymbolThickBorder() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbolsThickBorder.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank( "testProportionalSymbolSizeThickBorder", image, LegendUtils.DEFAULT_BG_COLOR); // biggest symbol, thick border assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside assertPixel(image, 5, 5, new Color(0, 0, 0)); // border assertPixel(image, 10, 10, new Color(255, 0, 0)); // inside // second symbol, small, no border assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside }
/** * Test that the legend is not the same if there is a rendering transformation that converts the * rendered layer from vector to raster */ @org.junit.Test public void testRenderingTransformationVectorRaster() throws Exception { Style transformStyle = readSLD("RenderingTransformVectorRaster.sld"); GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.NAMED_PLACES.getNamespaceURI(), MockData.NAMED_PLACES.getLocalPart()); assertNotNull(ftInfo); req.setLayer(ftInfo.getFeatureType()); req.setStyle(transformStyle); req.setLegendOptions(new HashMap()); this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); // ImageIO.write(image, "PNG", new File("/tmp/vr.png")); assertNotBlank("testRenderingTransform", image, LegendUtils.DEFAULT_BG_COLOR); assertPixel(image, 10, 70, new Color(188, 188, 255)); assertPixel(image, 10, 80, new Color(68, 68, 255)); assertPixel(image, 10, 130, new Color(255, 152, 0)); }
/** Tests that minSymbolSize legend option is respected. */ @org.junit.Test public void testMinSymbolSize() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); Map<String, String> options = new HashMap<String, String>(); options.put("minSymbolSize", "10"); req.setLegendOptions(options); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbols.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("testProportionalSymbolSize", image, LegendUtils.DEFAULT_BG_COLOR); // biggest symbol assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 5, 5, new Color(255, 0, 0)); assertPixel(image, 10, 10, new Color(255, 0, 0)); // smallest symbol assertPixel(image, 1, 61, new Color(255, 255, 255)); assertPixel(image, 7, 67, new Color(255, 0, 0)); assertPixel(image, 10, 70, new Color(255, 0, 0)); }