/** * Retrieves the first Mark used in a PointSymbolizer object. * * @param sym the PointSymbolizer * @return the first Mark object or null if unavailable. */ public static Mark mark(PointSymbolizer sym) { return mark(graphic(sym)); }
@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()); }
/** * Retrieves the first Mark used in a PointSymbolizer object. * * @param sym the PointSymbolizer * * @return the first Mark object or null if unavailable. */ public static Mark mark(PointSymbolizer sym) { return mark(graphic(sym)); }
public static Mark mark(PointSymbolizer sym) { return mark(graphic(sym)); }
/** * Uses the supplied style to define point rendering. * Currently it gets WellKnownName from a Mark (circle is the only value correctly rendered by now). * It also uses the Size parameter to define circle radius. */ protected void processSymbolizer(SimpleFeature ft, Rule rule,Symbolizer symbolizer) throws IOException{ super.processSymbolizer(ft, rule,symbolizer); if(symbolizer instanceof PointSymbolizer) { Mark mark=SLD.mark((PointSymbolizer)symbolizer); Graphic graphic=SLD.graphic((PointSymbolizer)symbolizer); if(graphic!=null && mark!=null) { Object oSize=graphic.getSize().evaluate(null); if(oSize!=null) size=Double.parseDouble(oSize.toString()); asCircle=SLD.wellKnownName(mark).toLowerCase().equals("circle"); if(!asCircle) symbol=SLD.wellKnownName(mark).toLowerCase(); } } }
@Test public void testPointWithRotation() throws Exception { // <UserStyle> // <Title>GeoServer SLD Cook Book: Rotated square</Title> // <FeatureTypeStyle> // <Rule> // <PointSymbolizer> // <Graphic> // <Mark> // <WellKnownName>square</WellKnownName> // <Fill> // <CssParameter name="fill">#009900</CssParameter> // </Fill> // </Mark> // <Size>12</Size> // <Rotation>45</Rotation> // </Graphic> // </PointSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("point", "rotated-square.sld"); PointSymbolizer point = SLD.pointSymbolizer(style); assertEquals("square", SLD.wellKnownName(SLD.mark(point))); assertEquals(color("009900"), SLD.color(SLD.fill(point))); assertEquals(12, SLD.pointSize(point)); assertEquals(45, Filters.asInt(SLD.graphic(point).getRotation())); }
@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); } }