legendOptions.putAll((Map) dispatcherRequest.getKvp().get("legend_options")); request.setLegendOptions(legendOptions);
/** 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)); }
req.setLegendOptions(legendOptions); req.setLegendOptions(legendOptions);
/** 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)); }
legendOptions.put("forceTitles", "off"); legendOptions.put("forceLabels", "on"); req.setLegendOptions(legendOptions); req.setLegendOptions(legendOptions);
legendOptions.put("forceTitles", "on"); legendOptions.put("fontName", "Bitstream Vera Sans"); req.setLegendOptions(legendOptions); req.setLegendOptions(legendOptions);
/** 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); }
/** * 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)); }
Map<String, String> options = new HashMap<String, String>(); options.put("forceTitles", "off"); req.setLegendOptions(options);
legendOptions.put("dy", "0"); legendOptions.put("forceRule", "false"); req.setLegendOptions(legendOptions);
legendOptions.put("dy", "0"); legendOptions.put("forceRule", "false"); req.setLegendOptions(legendOptions);
legendOptions.put("forceLabels", "on"); legendOptions.put("fontAntiAliasing", "true"); request.setLegendOptions(legendOptions); BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder();
req.setHeight(HEIGHT_HINT); HashMap legendOptions = new HashMap(); req.setLegendOptions(legendOptions); req.setLegendOptions(legendOptions);
legendOptions.put("dy", "0"); legendOptions.put("forceRule", "false"); req.setLegendOptions(legendOptions);
req.setLayer(feature.getSchema()); req.setStyle(transformStyle); req.setLegendOptions(new HashMap());
request.setLegendOptions(legendOptions); helper = new RasterLayerLegendHelper(request, style, null); rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); legendOptions.put("borderColor", SLD.toHTMLColor(colourToTest)); request.setLegendOptions(legendOptions); helper = new RasterLayerLegendHelper(request, style, null); rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows());
req.setStyle(multipleRulesStyle); req.setRule(rule.getName()); req.setLegendOptions(new HashMap());
legendOptions.put("dx", "0.5"); legendOptions.put("dy", "0"); req.setLegendOptions(legendOptions);
req.setLayer(feature.getSchema()); req.setStyle(style); req.setLegendOptions(new HashMap());
req.setLayer(feature.getSchema()); req.setStyle(multipleRulesStyle); req.setLegendOptions(new HashMap());