/** * Retrieves the color of the first Mark in a PointSymbolizer object. This method is identical * to {@linkplain #color(org.geotools.styling.PointSymbolizer)}. * * <p>If you are using something fun like symbols you will need to do your own thing. * * @param symbolizer Point symbolizer information. * @return Color of the point's mark, or null if unavailable. */ public static Color pointColor(PointSymbolizer symbolizer) { return color(symbolizer); }
/** * Retrieve the color of a stroke object * * @param stroke a Stroke object * @return color or null if stroke was null */ public static Color color(Stroke stroke) { if (stroke == null) { return null; } return color(stroke.getColor()); }
/** * Retrieve the color of a fill object * * @param fill a Fill object * @return color or null if fill was null */ public static Color color(Fill fill) { if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieve linestring color from linesymbolizer if available. * * @param symbolizer Line symbolizer information. * @return Color of linestring, or null if unavailable. */ public static Color lineColor(LineSymbolizer symbolizer) { if (symbolizer == null) { return null; } Stroke stroke = symbolizer.getStroke(); return color(stroke); }
/** * Retrieves the colour of the font fill from a TextSymbolizer. * * @param symbolizer Text symbolizer information. * @return Color of the font's fill, or null if unavailable. */ public static Color textFontFill(TextSymbolizer symbolizer) { if (symbolizer == null) { return null; } Fill fill = symbolizer.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieves the fill colour from a PolygonSymbolizer. * * <p>If you are using something fun like rules you will need to do your own thing. * * @param symbolizer Polygon symbolizer information. * @return Color of the polygon's fill, or null if unavailable. */ public static Color polyFill(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return null; } Fill fill = symbolizer.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieves the outline (stroke) color from a PolygonSymbolizer. * * <p>If you are using something fun like rules you will need to do your own thing. * * @param symbolizer Polygon symbolizer information. * @return Color of the polygon's stroke, or null if unavailable. */ public static Color polyColor(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return null; } Stroke stroke = symbolizer.getStroke(); if (stroke == null) { return null; } Color colour = color(stroke.getColor()); if (colour != null) { return colour; } return null; }
/** * Retrieves the colour of the halo fill a TextSymbolizer. * * @param symbolizer Text symbolizer information. * @return Color of the halo's fill, or null if unavailable. */ public static Color textHaloFill(TextSymbolizer symbolizer) { Halo halo = symbolizer.getHalo(); if (halo == null) { return null; } Fill fill = halo.getFill(); if (fill == null) { return null; } return color(fill.getColor()); }
/** * Retrieves the color from the first Mark 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 Color of the point's mark, or null if unavailable. */ public static Color color(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; Stroke stroke = mark.getStroke(); if (stroke != null) { Color colour = color(stroke); if (colour != null) { return colour; } } } } return null; }
/** * We should have a test case for the expected default values so we can be sure of correct SLD * rendering. */ public void testDefaults() { Stroke stroke = sf.getDefaultStroke(); assertEquals("default stroke width is one", 1, SLD.width(stroke)); assertEquals("default stroke color is black", Color.BLACK, SLD.color(stroke)); } /** See http://jira.codehaus.org/browse/UDIG-1374 */
@Test public void testAnchor() throws Exception { String yaml = "blue: &blue rgb(0,0,255)\n" + "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: *blue\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertEquals(Color.BLUE, SLD.color(SLD.fill(p))); }
@Test public void testNamedColor() throws Exception { String yaml = "point: \n" + " symbols: \n" + " - mark: \n" + " fill-color: blue\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PointSymbolizer p = SLD.pointSymbolizer(SLD.defaultStyle(sld)); assertEquals(Color.BLUE, SLD.color(SLD.fill(p))); }
@Test public void testPolygonSimple() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Simple polygon</Title> // <FeatureTypeStyle> // <Rule> // <PolygonSymbolizer> // <Fill> // <CssParameter name="fill">#000080</CssParameter> // </Fill> // </PolygonSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("poly", "simple.sld"); PolygonSymbolizer poly = SLD.polySymbolizer(style); assertEquals(color("000080"), SLD.color(poly.getFill())); }
@Test public void testParseNoStrokeFillDefaults() throws Exception { String yaml = "polygon: \n" + " fill-color: blue\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); PolygonSymbolizer p = (PolygonSymbolizer) SLD.symbolizers(SLD.defaultStyle(sld))[0]; assertEquals(Color.BLUE, SLD.color(SLD.fill(p))); assertNull(SLD.stroke(p)); yaml = "polygon: \n" + " stroke-color: blue\n"; sld = Ysld.parse(yaml); p = (PolygonSymbolizer) SLD.symbolizers(SLD.defaultStyle(sld))[0]; assertEquals(Color.BLUE, SLD.color(SLD.stroke(p))); assertNull(SLD.fill(p)); }
@Test public void testPolygonWithStroke() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Simple polygon with stroke</Title> // <FeatureTypeStyle> // <Rule> // <PolygonSymbolizer> // <Fill> // <CssParameter name="fill">#000080</CssParameter> // </Fill> // <Stroke> // <CssParameter name="stroke">#FFFFFF</CssParameter> // <CssParameter name="stroke-width">2</CssParameter> // </Stroke> // </PolygonSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("poly", "stroke.sld"); PolygonSymbolizer poly = SLD.polySymbolizer(style); assertEquals(color("000080"), SLD.color(poly.getFill())); assertEquals(color("FFFFFF"), SLD.color(poly.getStroke())); assertEquals(2, SLD.width(poly.getStroke())); }
@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 testPolygonWithTransparent() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Transparent polygon</Title> // <FeatureTypeStyle> // <Rule> // <PolygonSymbolizer> // <Fill> // <CssParameter name="fill">#000080</CssParameter> // <CssParameter name="fill-opacity">0.5</CssParameter> // </Fill> // <Stroke> // <CssParameter name="stroke">#FFFFFF</CssParameter> // <CssParameter name="stroke-width">2</CssParameter> // </Stroke> // </PolygonSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("poly", "transparent.sld"); PolygonSymbolizer poly = SLD.polySymbolizer(style); assertEquals(color("000080"), SLD.color(poly.getFill())); assertEquals(0.5, SLD.opacity(poly.getFill()), 0.1); assertEquals(color("FFFFFF"), SLD.color(poly.getStroke())); assertEquals(2, SLD.width(poly.getStroke())); }
/** See http://jira.codehaus.org/browse/UDIG-1374 */ public void testStroke() { Stroke stroke = sf.createStroke(ff.literal("#FF0000"), ff.literal("3")); assertEquals("width", 3, SLD.width(stroke)); assertEquals("color", Color.RED, SLD.color(stroke)); stroke = sf.createStroke(ff.literal("#FF0000"), ff.literal("3.0")); assertEquals("width", 3, SLD.width(stroke)); }
@Test public void testLineWithDashedline() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Dashed line</Title> // <FeatureTypeStyle> // <Rule> // <LineSymbolizer> // <Stroke> // <CssParameter name="stroke">#0000FF</CssParameter> // <CssParameter name="stroke-width">3</CssParameter> // <CssParameter name="stroke-dasharray">5 2</CssParameter> // </Stroke> // </LineSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("line", "dashed-line.sld"); LineSymbolizer line = SLD.lineSymbolizer(style); assertEquals(Color.blue, SLD.color(line)); assertEquals(3, SLD.width(line)); assertEquals(5f, SLD.lineDash(line)[0], 0.1); assertEquals(2f, SLD.lineDash(line)[1], 0.1); }
@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)); }