/** * Retrieves the Stroke from a PolygonSymbolizer. * * @param sym the symbolizer * @return the Stroke or null if not found. */ public static Stroke stroke(PolygonSymbolizer sym) { if (sym == null) { return null; } return sym.getStroke(); }
/** * Retrieves the border (stroke) opacity 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 double of the polygon's border opacity, or NaN if unavailable. */ public static double polyBorderOpacity(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return Double.NaN; } Stroke stroke = symbolizer.getStroke(); if (stroke == null) { return Double.NaN; } return opacity(stroke); }
/** * Retrieves the outline width 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 outline width or {@linkplain #NOTFOUND} if unavailable. */ public static int polyWidth(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return NOTFOUND; } Stroke stroke = symbolizer.getStroke(); if (stroke != null) { return Filters.asInt(stroke.getWidth()); } return NOTFOUND; }
PolygonStyle2D createPolygonStyle( Object feature, PolygonSymbolizer symbolizer, Range scaleRange) { PolygonStyle2D style = new PolygonStyle2D(); setScaleRange(style, scaleRange); style.setStroke(getStroke(symbolizer.getStroke(), feature)); style.setGraphicStroke( getGraphicStroke(symbolizer, symbolizer.getStroke(), feature, scaleRange)); style.setContour(getStrokePaint(symbolizer.getStroke(), feature)); style.setContourComposite(getStrokeComposite(symbolizer.getStroke(), feature)); setPolygonStyleFill(feature, style, symbolizer, scaleRange); return style; }
/** * 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; }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.PolygonSymbolizer) */ public void visit(PolygonSymbolizer poly) { if (symbolizerGeometriesVisitEnabled) { if (poly.getGeometry() != null) { poly.getGeometry().accept(this, null); } else { this.defaultGeometryUsed = true; // they want the default geometry (see GEOS-469) } } if (poly.getStroke() != null) { poly.getStroke().accept(this); } if (poly.getFill() != null) { poly.getFill().accept(this); } }
public void visit(PolygonSymbolizer poly) { PolygonSymbolizer copy = sf.createPolygonSymbolizer(); copy.setFill(copy(poly.getFill())); copy.setGeometry(copy(poly.getGeometry())); copy.setUnitOfMeasure(poly.getUnitOfMeasure()); copy.setStroke(copy(poly.getStroke())); copy.getOptions().putAll(poly.getOptions()); if (STRICT && !copy.equals(poly)) { throw new IllegalStateException( "Was unable to duplicate provided PolygonSymbolizer:" + poly); } pages.push(copy); }
@Override public void visit(PolygonSymbolizer poly) { if (poly.getDescription() != null) { poly.getDescription().accept(this); } if (poly.getDisplacement() != null) { poly.getDisplacement().accept(this); } if (poly.getFill() != null) { poly.getFill().accept(this); } if (poly.getStroke() != null) { poly.getStroke().accept(this); } }
@Override public void visit(PolygonSymbolizer poly) { super.visit(poly); PolygonSymbolizer copy = (PolygonSymbolizer) pages.peek(); Unit<Length> uom = copy.getUnitOfMeasure(); rescaleStroke(copy.getStroke(), uom); rescaleFill(copy.getFill(), uom); scaleIntArrayOption(copy.getOptions(), PolygonSymbolizer.GRAPHIC_MARGIN_KEY, uom); copy.setUnitOfMeasure(Units.PIXEL); }
public PolygonSymbolizerBuilder reset(PolygonSymbolizer symbolizer) { if (symbolizer == null) { return unset(); } stroke.reset(symbolizer.getStroke()); fill.reset(symbolizer.getFill()); uom = symbolizer.getUnitOfMeasure(); geometry = symbolizer.getGeometry(); unset = false; return this; }
public void visit(PolygonSymbolizer poly) { // adds the uom attribute according to the OGC SE specification AttributesImpl atts = new AttributesImpl(); Unit<Length> uom = poly.getUnitOfMeasure(); if (uom != null) atts.addAttribute("", "uom", "uom", "", UomOgcMapping.get(uom).getSEString()); start("PolygonSymbolizer", atts); encodeGeometryExpression(poly.getGeometry()); if (poly.getFill() != null) { poly.getFill().accept(this); } if (poly.getStroke() != null) { poly.getStroke().accept(this); } if (poly.getOptions() != null) { encodeVendorOptions(poly.getOptions()); } end("PolygonSymbolizer"); }
@Override protected void encode(PolygonSymbolizer sym) { inline(new StrokeEncoder(sym.getStroke())); inline(new FillEncoder(sym.getFill())); put("offset", sym.getPerpendicularOffset()); inline(new DisplacementEncoder(sym.getDisplacement())); super.encode(sym); } }
/** * Sets the colour to use for outline (stroke) and fill in a polygon symbolizer * * @param symbolizer the polygon symbolizer * @param colour the colour for polygon outlines and fill */ public static void setPolyColour(PolygonSymbolizer symbolizer, Color colour) { if (symbolizer == null || colour == null) { return; } Expression colourExp = ff.literal(colour); Stroke stroke = symbolizer.getStroke(); if (stroke == null) { stroke = sf.createStroke(colourExp, Stroke.DEFAULT.getWidth()); symbolizer.setStroke(stroke); } else { stroke.setColor(ff.literal(colour)); } Fill fill = symbolizer.getFill(); if (fill != null) { fill.setColor(colourExp); } }
@Test public void testVisitPolygonSymbolizer_NullStroke() { try { UomRescaleStyleVisitor visitor = null; StyleBuilder styleBuilder = new StyleBuilder(); Fill fill = styleBuilder.createFill(Color.RED); PolygonSymbolizerImpl polySymb = (PolygonSymbolizerImpl) styleBuilder.createPolygonSymbolizer(null, fill); visitor = new UomRescaleStyleVisitor(10); polySymb.accept(visitor); PolygonSymbolizer rescaledPolySymb = (PolygonSymbolizer) visitor.getCopy(); assertEquals(polySymb.getFill(), rescaledPolySymb.getFill()); assertNull(rescaledPolySymb.getStroke()); assertNotSame(rescaledPolySymb, polySymb); } catch (Exception e2) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e2); fail(e2.getClass().getSimpleName() + " should not be thrown."); } }
@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 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())); }
case MULTIPOLYGON: PolygonSymbolizer polySym = (PolygonSymbolizer) sym; setLineColorItems(SLD.color(polySym.getStroke())); setFillColorItems(SLD.color(polySym.getFill())); setFillOpacityItems(SLD.opacity(polySym.getFill()));