/** * Creates the default graphic object * * @return the graphic object */ public Graphic createGraphic() { Graphic gr = sf.getDefaultGraphic(); Mark mark = createMark(MARK_SQUARE, Color.decode("#808080"), Color.BLACK, 1); gr.setMarks(new Mark[] {mark}); gr.setSize(Expression.NIL); return gr; }
size = Graphic.DEFAULT.getSize(); graphic.setSize(size);
public static Symbolizer[] getSymbolizers( Class<? extends Geometry> type, Color baseColor, boolean useTransparency) { StyleBuilder builder = new StyleBuilder(); Symbolizer[] syms = new Symbolizer[1]; if (LineString.class.isAssignableFrom(type) || MultiLineString.class.isAssignableFrom(type)) syms[0] = builder.createLineSymbolizer(baseColor, 2); if (Point.class.isAssignableFrom(type) || MultiPoint.class.isAssignableFrom(type)) { PointSymbolizer point = builder.createPointSymbolizer(builder.createGraphic()); // set graphic size to 10 by default point.getGraphic() .setSize( (Expression) CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()) .literal(10)); // danger assumes a Mark! point.getGraphic().getMarks()[0].setFill(builder.createFill(baseColor)); syms[0] = point; } if (Polygon.class.isAssignableFrom(type) || MultiPolygon.class.isAssignableFrom(type)) { syms[0] = builder.createPolygonSymbolizer( builder.createStroke(baseColor, 2), builder.createFill(baseColor, useTransparency ? .6 : 1.0)); } return syms; }
public Graphic createDefaultGraphic() { Graphic graphic = new GraphicImpl(filterFactory); graphic.addMark(createMark()); // a default graphic is assumed to have a single Mark graphic.setSize(Expression.NIL); graphic.setOpacity(filterFactory.literal(1.0)); graphic.setRotation(filterFactory.literal(0.0)); return graphic; }
public void testResizeExternalGraphic() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); symb.getGraphic().graphicalSymbols().add(eg); symb.getGraphic().setSize(ff.literal(20)); GraphicStyle2D gs = (GraphicStyle2D) sld.createPointStyle(feature, symb, range); BufferedImage img = gs.getImage(); assertEquals(20, img.getHeight()); assertEquals(20, img.getWidth()); }
@Test public void testExpressionNil() throws Exception { PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer(); p.getGraphic().setSize(Expression.NIL); StringWriter out = new StringWriter(); Ysld.encode(sld(p), out); // System.out.println(out.toString()); }
@Test public void testUnreachableExternalGraphic() throws Exception { File file = new File(TestData.getResource(this, "draw.png").toURI()); URL resource = new File(file.getParent(), "draw-not-there.png").toURI().toURL(); PointSymbolizer ps = sb.createPointSymbolizer( sb.createGraphic( null, null, sb.createExternalGraphic(resource, "image/png"))); ps.getGraphic().setSize(sb.literalExpression(null)); Style style = sb.createStyle(ps); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(0, rbe.getBuffer()); assertFalse(rbe.isEstimateAccurate()); }
symbol.setSize((Expression) value[i].getValue());
public void visit(Graphic gr) { Graphic copy = null; Displacement displacementCopy = copy(gr.getDisplacement()); ExternalGraphic[] externalGraphicsCopy = copy(gr.getExternalGraphics()); Mark[] marksCopy = copy(gr.getMarks()); Expression opacityCopy = copy(gr.getOpacity()); Expression rotationCopy = copy(gr.getRotation()); Expression sizeCopy = copy(gr.getSize()); AnchorPoint anchorCopy = copy(gr.getAnchorPoint()); // Looks like Symbols are a "view" of marks and external graphics? // Symbol[] symbolCopys = copy( gr.getSymbols() ); copy = sf.createDefaultGraphic(); copy.setDisplacement(displacementCopy); copy.setAnchorPoint(anchorCopy); copy.setExternalGraphics(externalGraphicsCopy); copy.setMarks(marksCopy); copy.setOpacity(opacityCopy); copy.setRotation(rotationCopy); copy.setSize(sizeCopy); // copy.setSymbols(symbolCopys); if (STRICT) { if (!copy.equals(gr)) { throw new IllegalStateException("Was unable to duplicate provided Graphic:" + gr); } } pages.push(copy); }
copy.setOpacity((Expression) opacityCopy); copy.setRotation((Expression) rotationCopy); copy.setSize((Expression) sizeCopy); copy.setSymbols(symbolCopys);
@Test public void testLiteralParseGraphics() { Graphic g = sb.createGraphic(); g.setSize(sb.literalExpression("10.0")); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(g); assertEquals(11, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); } }
private void rescale(Graphic graphic, Unit<Length> unit) { if (graphic != null) { graphic.setSize(rescale(graphic.getSize(), unit)); graphic.setGap(rescale(graphic.getGap(), unit)); Displacement disp = graphic.getDisplacement(); if (disp != null) { disp.setDisplacementX(rescale(disp.getDisplacementX(), unit)); disp.setDisplacementY(rescale(disp.getDisplacementY(), unit)); graphic.setDisplacement(disp); } if (graphic.graphicalSymbols() != null) { for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs instanceof Mark) { Mark mark = (Mark) gs; rescaleStroke(mark.getStroke(), unit); rescaleFill(mark.getFill(), unit); } } } } }
@Test public void testSimpleGraphic() { PointSymbolizer ps = sb.createPointSymbolizer( sb.createGraphic(null, sb.createMark(sb.MARK_CIRCLE), null)); ps.getGraphic().setSize(sb.literalExpression(15)); Style style = sb.createStyle(ps); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(16, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testMarkNoSizeNoStroke() throws Exception { StyleBuilder sb = new StyleBuilder(); Mark mark = sb.createMark("square"); mark.setStroke(null); Graphic graphic = sb.createGraphic(null, mark, null); graphic.setSize(NilExpression.NIL); PointSymbolizer ps = sb.createPointSymbolizer(graphic); Style style = sb.createStyle(ps); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(16, estimator.getBuffer()); }
@Test public void testReachableExternalGraphic() { URL resource = TestData.getResource(this, "draw.png"); PointSymbolizer ps = sb.createPointSymbolizer( sb.createGraphic( null, null, sb.createExternalGraphic(resource, "image/png"))); ps.getGraphic().setSize(sb.literalExpression(null)); Style style = sb.createStyle(ps); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(24, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
/** Test of createPointStyle method, of class org.geotools.renderer.style.SLDStyleFactory. */ public void testCreateCompletePointStyle() { PointSymbolizer symb; Mark myMark; // full symbolizer symb = sf.createPointSymbolizer(); myMark = sf.createMark(); myMark.setFill(sf.createFill(ff.literal("#ffff00"))); symb.getGraphic().setSize(ff.literal(10)); symb.getGraphic().addMark(myMark); symb.getGraphic().setOpacity(ff.literal(1)); symb.getGraphic().setRotation(ff.literal(0)); sld.createPointStyle(null, symb, range); }
@Test public void testMarkStroke() throws Exception { StyleBuilder sb = new StyleBuilder(); Mark mark = sb.createMark("square"); mark.getStroke().setWidth(sb.getFilterFactory().literal(10)); Graphic graphic = sb.createGraphic(null, mark, null); graphic.setSize(NilExpression.NIL); PointSymbolizer ps = sb.createPointSymbolizer(graphic); Style style = sb.createStyle(ps); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(26, estimator.getBuffer()); }
/** * Tests size calculation of dynamically sized feature, using real-world units combined with * DPI-based resizing. */ @Test public void testCombinedResizingDpiUom() { // given: Point with dynamic size in real-world units int sizeNum = 10; double scaleDpi = 2; double scaleUom = 3; PointSymbolizer symbolizer = sb.createPointSymbolizer(); Graphic graphic = sb.createGraphic(); graphic.setSize(ff.function("strConcat", ff.property("size"), ff.literal("m"))); symbolizer.setGraphic(graphic); // when: DPI based resizing is applied RescaleStyleVisitor dpiVisitor = new GraphicsAwareDpiRescaleStyleVisitor(scaleDpi); symbolizer.accept(dpiVisitor); symbolizer = (PointSymbolizer) dpiVisitor.getCopy(); // and: UOM resizing is applied UomRescaleStyleVisitor uomVisitor = new UomRescaleStyleVisitor(scaleUom); uomVisitor.visit(symbolizer); symbolizer = (PointSymbolizer) uomVisitor.getCopy(); SimpleFeature feature = createFeatureSized(sizeNum); // then: only the UOM resizing must have an effect Double size = symbolizer.getGraphic().getSize().evaluate(feature, Double.class); assertEquals(sizeNum * scaleUom, size.doubleValue(), 0d); }
@Override public void handle(YamlObject<?> obj, YamlParseContext context) { graphic(g); YamlMap map = obj.map(); if (map.has("anchor")) { g.setAnchorPoint(Util.anchor(map.get("anchor"), factory)); } if (map.has("opacity")) { g.setOpacity(Util.expression(map.str("opacity"), factory)); } if (map.has("size")) { g.setSize(Util.expression(map.str("size"), factory)); } if (map.has("displacement")) { g.setDisplacement(Util.displacement(map.get("displacement"), factory)); } if (map.has("rotation")) { g.setRotation(Util.expression(map.str("rotation"), factory)); } if (map.has("gap")) { g.setGap(Util.expression(map.str("gap"), factory)); } if (map.has("initial-gap")) { g.setInitialGap(Util.expression(map.str("initial-gap"), factory)); } context.push("symbols", new SymbolsParser()); }
@Test public void testGraphicSizeFunction() throws Exception { StyleBuilder sb = new StyleBuilder(); Mark mark = sb.createMark("square"); mark.setStroke(null); Graphic graphic = sb.createGraphic(null, mark, null); FilterFactory2 ff = sb.getFilterFactory(); graphic.setSize(ff.function("env", ff.literal("test"))); PointSymbolizer ps = sb.createPointSymbolizer(graphic); Style style = sb.createStyle(ps); try { EnvFunction.setGlobalValue("test", 10); MetaBufferEstimator estimator = new MetaBufferEstimator(); style.accept(estimator); assertTrue(estimator.isEstimateAccurate()); assertEquals(10, estimator.getBuffer()); } finally { EnvFunction.clearGlobalValues(); } }