public RuleBuilder reset(Rule rule) { if (rule == null) { return unset(); } name = rule.getName(); title = rule.getTitle(); ruleAbstract = rule.getAbstract(); minScaleDenominator = rule.getMinScaleDenominator(); maxScaleDenominator = rule.getMaxScaleDenominator(); filter = rule.getFilter(); elseFilter = rule.isElseFilter(); symbolizers.clear(); symbolizers.addAll(rule.symbolizers()); // TODO: unpack into builders in order to "copy" symbolizerBuilder = null; unset = false; legend.reset(rule.getLegend()); return this; }
@Test public void testGraphicLegendNegativeScale() throws Exception { // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Paint legend using StyledShapePainter final Point point = new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, -1, false); graphics.dispose(); // Ensure painted legend matches image from file Assert.assertTrue(imagesIdentical(paintedImage, testImage)); }
@Test public void testGraphicLegend() throws Exception { // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Paint legend using StyledShapePainter final Point point = new GeometryFactory().createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, 1, false); graphics.dispose(); // Ensure painted legend matches image from file Assert.assertTrue(imagesIdentical(paintedImage, testImage)); }
public void testGraphicLegendRotation() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Set rotation to 45 degrees legend.setRotation(ff.literal(45.0)); // Paint legend using StyledShapePainter final Point point = gf.createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, 1, false); graphics.dispose(); // Ensure painted legend does not match image from file Assert.assertFalse(imagesIdentical(paintedImage, testImage)); }
@Test public void testLegend() throws Exception { String yaml = "feature-styles:\n" + "- rules:\n" + " - legend:\n" + " symbols:\n" + " - external:\n" + " url: smileyface.png\n" + " format: image/png\n" + " symbolizers:\n" + " - point:\n" + " symbols:\n" + " - mark:\n" + " shape: circle\n" + " fill-color: '#FF0000'"; StyledLayerDescriptor sld = Ysld.parse(yaml); Rule rule = SLD.rules(SLD.defaultStyle(sld))[0]; assertThat(rule.getLegend().graphicalSymbols().get(0), instanceOf(ExternalGraphic.class)); ExternalGraphic legend = (ExternalGraphic) rule.getLegend().graphicalSymbols().get(0); assertEquals(new URL("file:smileyface.png"), legend.getLocation()); assertEquals("image/png", legend.getFormat()); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertEquals("circle", SLD.wellKnownName(SLD.mark(p))); assertEquals(Color.RED, SLD.color(SLD.fill(p))); }
GraphicLegend legend = (GraphicLegend) SLD.rules(style)[0].getLegend(); assertEquals(32, Filters.asInt(legend.getSize()));
/** * @param existingRule * @return */ private Graphic[] updateLegend(org.geotools.styling.Rule existingRule) { int index; GraphicLegend existingLegend = existingRule.getLegend(); Graphic[] legendGraphics = null; if (existingLegend != null) { int legendGraphicCount = existingLegend.graphicalSymbols().size(); legendGraphics = new Graphic[legendGraphicCount]; index = 0; for (GraphicalSymbol graphicalSymbol : existingLegend.graphicalSymbols()) { legendGraphics[index] = (Graphic) graphicalSymbol; index++; } } else { legendGraphics = new Graphic[0]; } return legendGraphics; }
final GraphicLegend graphic = applicableRules[i].getLegend();
final GraphicLegend graphic = applicableRules[i].getLegend();