/** * Retrieves the well known name of the first Mark that has one in a PointSymbolizer object * * <p>If you are using something fun like symbols you will need to do your own thing. * * @param symbolizer Point symbolizer information. * @return well known name of the first Mark or null if unavailable. */ public static String pointWellKnownName(PointSymbolizer symbolizer) { if (symbolizer == null) { return null; } Graphic graphic = symbolizer.getGraphic(); if (graphic == null) { return null; } for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs != null && gs instanceof Mark) { Mark mark = (Mark) gs; String s = wellKnownName(mark); if (s != null) { return s; } } } return null; }
@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))); }
@Test public void testPointSimple() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Simple Point With Stroke</Title> // <FeatureTypeStyle> // <Rule> // <PointSymbolizer> // <Graphic> // <Mark> // <WellKnownName>circle</WellKnownName> // <Fill> // <CssParameter name="fill">#FF0000</CssParameter> // </Fill> // </Mark> // <Size>6</Size> // </Graphic> // </PointSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("point", "simple.sld"); assertEquals("SLD Cook Book: Simple Point With Stroke", style.getTitle()); PointSymbolizer point = SLD.pointSymbolizer(style); assertEquals("circle", SLD.wellKnownName(SLD.mark(point))); assertEquals(1, point.getGraphic().graphicalSymbols().size()); assertEquals(Color.red, SLD.color(SLD.fill(point))); assertEquals(6, SLD.pointSize(point)); }
assertEquals("circle", SLD.wellKnownName(SLD.mark(point))); assertEquals(color("CC3300"), SLD.color(SLD.fill(point))); assertEquals(12, SLD.pointSize(point)); assertEquals("circle", SLD.wellKnownName(SLD.mark(point))); assertEquals(color("CC3300"), SLD.color(SLD.fill(point))); assertEquals(8, SLD.pointSize(point)); assertEquals("circle", SLD.wellKnownName(SLD.mark(point))); assertEquals(color("CC3300"), SLD.color(SLD.fill(point))); assertEquals(4, SLD.pointSize(point));
assertEquals("circle", SLD.wellKnownName(SLD.mark(point))); assertEquals(1, point.getGraphic().graphicalSymbols().size()); assertEquals(Color.red, SLD.color(SLD.fill(point)));
/** * 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())); }
/** * Retrieves the well known name of the first Mark that has one in a * PointSymbolizer object * <p> * If you are using something fun like symbols you will need to do your * own thing. * * @param symbolizer Point symbolizer information. * * @return well known name of the first Mark or null if unavailable. */ public static String pointWellKnownName(PointSymbolizer symbolizer) { if (symbolizer == null) { return null; } Graphic graphic = symbolizer.getGraphic(); if (graphic == null) { return null; } for (GraphicalSymbol gs : graphic.graphicalSymbols()) { if (gs != null && gs instanceof Mark) { Mark mark = (Mark) gs; String s = wellKnownName(mark); if (s != null) { return s; } } } return null; }
assertEquals("shape://vertline", SLD.wellKnownName(mark)); assertEquals(color("333333"), SLD.color(mark.getStroke())); assertEquals(1, SLD.width(mark.getStroke()));
String string = wellKnownName(mark);
assertEquals("circle", SLD.wellKnownName(mark)); assertEquals(Color.red, SLD.color(mark.getFill())); assertEquals(Color.black, SLD.color(mark.getStroke()));
assertEquals("triangle", SLD.wellKnownName(SLD.mark(point))); assertEquals(color("009900"), SLD.color(SLD.fill(point))); assertEquals(0.2, SLD.opacity(SLD.fill(point)), 0.1);
assertEquals("circle", SLD.wellKnownName(mark)); assertEquals(color("000033"), SLD.color(mark.getStroke())); assertEquals(1, SLD.width(mark.getStroke()));
assertEquals("circle", SLD.wellKnownName(mark)); assertEquals(color("666666"), SLD.color(mark.getFill())); assertEquals(color("333333"), SLD.color(mark.getStroke()));