graphic.setSymbols(symbols); graphic.graphicalSymbols().addAll(Arrays.asList(externalGraphics)); graphic.graphicalSymbols().addAll(Arrays.asList(marks)); opacity = Graphic.DEFAULT.getOpacity(); graphic.setOpacity(opacity); size = Graphic.DEFAULT.getSize(); graphic.setSize(size); rotation = Graphic.DEFAULT.getRotation(); graphic.setRotation(rotation);
/** * Null safe graphic copy * * @param graphic * @return copy of graphic or null if not provided */ protected Graphic copy(Graphic graphic) { if (graphic == null) return null; graphic.accept(this); return (Graphic) pages.pop(); }
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); }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Graphic) */ public void visit(Graphic gr) { if (gr.getSymbols() != null) { Symbol[] symbols = gr.getSymbols(); for (int i = 0; i < symbols.length; i++) { Symbol symbol = symbols[i]; symbol.accept(this); } } if (gr.getOpacity() != null) { gr.getOpacity().accept(this, null); } if (gr.getRotation() != null) { gr.getRotation().accept(this, null); } if (gr.getSize() != null) { gr.getSize().accept(this, null); } if (gr.getDisplacement() != null) gr.getDisplacement().accept(this); if (gr.getAnchorPoint() != null) gr.getAnchorPoint().accept(this); }
@Override public void visit(Graphic gr) { if (gr.getAnchorPoint() != null) { gr.getAnchorPoint().accept(this); } if (gr.getDisplacement() != null) { gr.getDisplacement().accept(this); } for (ExternalGraphic eg : gr.getExternalGraphics()) { eg.accept(this); } for (Mark m : gr.getMarks()) { m.accept(this); } }
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); } } } } }
if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("parsing extgraphic " + child); if (firstGraphic) { graphic.graphicalSymbols().clear(); firstGraphic = false; graphic.graphicalSymbols().add(parseExternalGraphic(child)); } else if (childName.equalsIgnoreCase("Mark")) { if (firstGraphic) { graphic.graphicalSymbols().clear(); firstGraphic = false; graphic.graphicalSymbols().add(parseMark(child)); } else if (childName.equalsIgnoreCase(opacityString)) { graphic.setOpacity(parseCssParameter(child)); } else if (childName.equalsIgnoreCase("size")) { graphic.setSize(parseCssParameter(child)); } else if (childName.equalsIgnoreCase("displacement")) { graphic.setDisplacement(parseDisplacement(child)); } else if (childName.equalsIgnoreCase("anchorPoint")) { graphic.setAnchorPoint(parseAnchorPoint(child)); } else if (childName.equalsIgnoreCase("rotation")) { graphic.setRotation(parseCssParameter(child));
@Override protected void encode(Graphic g) { if (!flatten) push("graphic"); inline(new AnchorPointEncoder(g.getAnchorPoint())); inline(new DisplacementEncoder(g.getDisplacement())); put("gap", nullIf(g.getGap(), 0d), nullIf(g.getInitialGap(), 0d)); put("opacity", nullIf(g.getOpacity(), 1)); put("size", g.getSize()); put("rotation", nullIf(g.getRotation(), 0d)); put("symbols", new SymbolsEncoder(g)); } }
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; }
float opacity = evalOpacity(sldGraphic.getOpacity(), feature); Displacement displacement = sldGraphic.getDisplacement(); if (displacement != null) { displacementX = evalToFloat(displacement.getDisplacementX(), feature, 0f); AnchorPoint anchorPoint = sldGraphic.getAnchorPoint(); if (anchorPoint != null) { anchorPointX = evalToFloat(anchorPoint.getAnchorPointX(), feature, 0.5f); if (sldGraphic.getSize() != null && !Expression.NIL.equals(sldGraphic.getSize())) size = evalToDouble(sldGraphic.getSize(), feature, 0); } catch (NumberFormatException nfe) { float rotation = (float) Math.toRadians(evalToDouble(sldGraphic.getRotation(), feature, 0)); List<GraphicalSymbol> symbols = sldGraphic.graphicalSymbols(); if (symbols == null || symbols.isEmpty()) { return null;
@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 testParsedStyle() throws IOException { File styleDir = new File(dataDir.root(), "styles"); styleDir.mkdir(); // Copy the sld to the temp style dir File styleFile = new File(styleDir, "external.sld"); Files.copy(this.getClass().getResourceAsStream("external.sld"), styleFile.toPath()); File iconFile = new File(styleDir, "icon.png"); assertFalse(iconFile.exists()); StyleInfoImpl si = new StyleInfoImpl(null); si.setName(""); si.setId(""); si.setFormat("sld"); si.setFormatVersion(new Version("1.0.0")); si.setFilename(styleFile.getName()); Style s = dataDir.parsedStyle(si); // Verify style is actually parsed correctly Symbolizer symbolizer = s.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); assertTrue(symbolizer instanceof PointSymbolizer); GraphicalSymbol graphic = ((PointSymbolizer) symbolizer).getGraphic().graphicalSymbols().get(0); assertTrue(graphic instanceof ExternalGraphic); assertEquals(((ExternalGraphic) graphic).getLocation(), iconFile.toURI().toURL()); // GEOS-7025: verify the icon file is not created if it doesn't already exist assertFalse(iconFile.exists()); }
public void setEdited(Graphic graphic) { if (graphic != null) { guiDisplacement.setEdited(graphic.getDisplacement()); guiGeom.setGeom(graphic.getGeometryPropertyName()); guiOpacity.setExpression(graphic.getOpacity()); guiRotation.setExpression(graphic.getRotation()); guiSize.setExpression(graphic.getSize()); // marks and external graphics are symbols so no need to handle this method //graphic.getSymbols(); guiMark.setEdited(graphic.getMarks()); guiExternal.setEdited(graphic.getExternalGraphics()); } this.graphic = graphic; }
public void addGraphicProperties(String prefix, Graphic g, Map<String,String> props) { if (g.getOpacity() != null && !isStatic(g.getOpacity())) { props.put(prefix + OPACITY, g.getOpacity().evaluate(feature, String.class)); } if (g.getRotation() != null && !isStatic(g.getRotation())) { props.put(prefix + ROTATION, g.getRotation().evaluate(feature, String.class)); } if (g.getSize() != null && !isStatic(g.getSize())) { props.put(prefix + SIZE, g.getSize().evaluate(feature, String.class)); } if (!g.graphicalSymbols().isEmpty()) { if (g.graphicalSymbols().get(0) instanceof Mark) { Mark mark = (Mark) g.graphicalSymbols().get(0); addMarkProperties(prefix, mark, props); } else if (g.graphicalSymbols().get(0) instanceof ExternalGraphic) { ExternalGraphic exGraphic = (ExternalGraphic) g.graphicalSymbols().get(0); addExternalGraphicProperties(prefix, exGraphic, props); } } }
@Test public void testGraphicFallbacks() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); Style style = SLD.createPointStyle("circle", Color.RED, Color.yellow, 0.5f, 10f); Graphic g = SLD.graphic(SLD.pointSymbolizer(style)); g.setRotation(ff.literal(45)); g.setOpacity(ff.literal(0.5)); Map<String, String> props = new HashMap<String, String>(); props.put("0.0.0", ""); style = IconPropertyInjector.injectProperties(style, props); g = SLD.graphic(SLD.pointSymbolizer(style)); assertEquals(10.0, g.getSize().evaluate(null, Double.class), 0.1); assertEquals(45.0, g.getRotation().evaluate(null, Double.class), 0.1); assertEquals(0.5, g.getOpacity().evaluate(null, Double.class), 0.1); } }
graphic.setGeometryPropertyName(parseGeometryName(child)); graphic.addExternalGraphic(parseExternalGraphic(child)); graphic.addMark(parseMark(child)); graphic.setOpacity(parseCssParameter(child)); graphic.setSize(parseCssParameter(child)); graphic.setDisplacement(parseDisplacement(child)); graphic.setRotation(parseCssParameter(child));
public void apply() { if (graphic != null) { graphic.setDisplacement(guiDisplacement.getEdited()); graphic.setGeometryPropertyName(guiGeom.getGeom()); graphic.setOpacity(guiOpacity.getExpression()); graphic.setRotation(guiRotation.getExpression()); graphic.setSize(guiSize.getExpression()); graphic.setMarks(guiMark.getEdited()); graphic.setExternalGraphics(guiExternal.getEdited()); } }
public void visit(Graphic gr) { start("Graphic"); encodeGeometryProperty(gr.getGeometryPropertyName()); Symbol[] symbols = gr.getSymbols(); for (int i = 0; i < symbols.length; i++) { symbols[i].accept(this); } element("Opacity", gr.getOpacity()); element("Size", gr.getSize()); element("Rotation", gr.getRotation()); end("Graphic"); }
@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 testPointWithGraphic() throws Exception { // <UserStyle> // <Title>GeoServer SLD Cook Book: Point as graphic</Title> // <FeatureTypeStyle> // <Rule> // <PointSymbolizer> // <Graphic> // <ExternalGraphic> // <OnlineResource // xlink:type="simple" // xlink:href="smileyface.png" /> // <Format>image/png</Format> // </ExternalGraphic> // <Size>32</Size> // </Graphic> // </PointSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("point", "graphic.sld"); Graphic graphic = SLD.graphic(SLD.pointSymbolizer(style)); assertEquals(32, Filters.asInt(graphic.getSize())); ExternalGraphic external = (ExternalGraphic) graphic.graphicalSymbols().get(0); assertEquals("smileyface.png", external.getLocation().getPath()); assertEquals("image/png", external.getFormat()); }