/** * create a default stroke with the supplied width * * @param width the width of the line * @return the stroke created */ public Stroke createStroke(double width) { return createStroke(Color.BLACK, width); }
/** * Create a default stroke with the supplied color * * @param color the color of the line * @return the created stroke */ public Stroke createStroke(Color color) { return createStroke(color, 1); }
/** * create a new line symbolizer * * @param width the width of the line * @return the new line symbolizer */ public LineSymbolizer createLineSymbolizer(double width) { return createLineSymbolizer(createStroke(width), null); }
/** * create a LineSymbolizer * * @param color - the color of the line * @param width - the width of the line * @param geometryPropertyName - the name of the geometry to be drawn * @return the new line symbolizer */ public LineSymbolizer createLineSymbolizer( Color color, double width, String geometryPropertyName) { return createLineSymbolizer(createStroke(color, width), geometryPropertyName); }
/** * create a dashed line of color and width * * @param color the color of the line * @param width the width of the line * @param dashArray an array of floats describing the length of line and spaces * @return the stroke created */ public Stroke createStroke(Color color, double width, float[] dashArray) { Stroke stroke = createStroke(color, width); stroke.setDashArray(dashArray); return stroke; }
/** * create a LineSymbolizer * * @param color - the color of the line * @return the new line symbolizer */ public LineSymbolizer createLineSymbolizer(Color color) { return createLineSymbolizer(createStroke(color), null); }
/** * create a LineSymbolizer * * @param color - the color of the line * @param width - the width of the line * @return the new line symbolizer */ public LineSymbolizer createLineSymbolizer(Color color, double width) { return createLineSymbolizer(createStroke(color, width), null); }
/** * create a polygon symbolizer * * @param borderColor - the outline color of the polygon * @param borderWidth - the width of the outline * @return the new polygon symbolizer */ public PolygonSymbolizer createPolygonSymbolizer(Color borderColor, double borderWidth) { return createPolygonSymbolizer(createStroke(borderColor, borderWidth), null); }
/** * create a default polygon symbolizer * * @return the new polygon symbolizer */ public PolygonSymbolizer createPolygonSymbolizer() { PolygonSymbolizer ps = sf.createPolygonSymbolizer(); ps.setFill(createFill()); ps.setStroke(createStroke()); return ps; }
@Test public void testMultiSymbolizers() { Symbolizer ls = sb.createLineSymbolizer(sb.createStroke(10.8)); Symbolizer ps = sb.createPolygonSymbolizer(sb.createStroke(12), sb.createFill()); Rule r = sb.createRule(new Symbolizer[] {ls, ps}); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(r); assertEquals(12, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testDynamicStroke() throws Exception { Stroke original = sb.createStroke(Color.RED, 2); original.setDashArray(Arrays.asList((Expression) ff.literal("5 10"))); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals(4.0d, Double.valueOf((String) clone.getWidth().evaluate(null)), 0.001); assertNotNull(original.dashArray()); assertEquals(1, original.dashArray().size()); assertEquals("10.0 20.0", ((Expression) clone.dashArray().get(0)).evaluate(null)); }
@Test public void testRescaleLocalUOM() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.setWidth(ff.literal("2m")); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals("4m", clone.getWidth().evaluate(null, String.class)); }
@Test public void testConstantFunction() { Function cos = ff.function("cos", ff.literal(Math.toRadians(Math.PI))); Symbolizer ls = sb.createLineSymbolizer(sb.createStroke(sb.colorExpression(Color.BLACK), cos)); Rule r = sb.createRule(new Symbolizer[] {ls}); MetaBufferEstimator rbe = new MetaBufferEstimator(); // cos(pi) == 1 rbe.visit(r); assertEquals(1, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testSimpleStroke() { Style style = sb.createStyle(sb.createLineSymbolizer(sb.createStroke(10.0))); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(10, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testRescalePerpendicularOffset() throws Exception { Stroke stroke = sb.createStroke(Color.RED, 2, new float[] {5, 10}); LineSymbolizer ls = sb.createLineSymbolizer(stroke); ls.setPerpendicularOffset(ff.literal(2)); ls.accept(visitor); LineSymbolizer clone = (LineSymbolizer) visitor.getCopy(); assertEquals("4", clone.getPerpendicularOffset().evaluate(null, String.class)); }
@Test public void testStroke() throws Exception { Stroke original = sb.createStroke(Color.RED, 2, new float[] {5, 10}); original.accept(visitor); Stroke clone = (Stroke) visitor.getCopy(); assertEquals(4.0d, clone.getWidth().evaluate(null, Double.class), 0d); assertEquals(10.0f, clone.getDashArray()[0], 0d); assertEquals(20.0f, clone.getDashArray()[1], 0d); }
@Test public void testRescaleLocalPixelInPixelSymbolizer() throws Exception { Stroke stroke = sb.createStroke(Color.RED, 2, new float[] {5, 10}); stroke.setWidth(ff.literal("2px")); LineSymbolizer ls = sb.createLineSymbolizer(stroke); ls.accept(visitor); LineSymbolizer clone = (LineSymbolizer) visitor.getCopy(); assertEquals("4", clone.getStroke().getWidth().evaluate(null, String.class)); }
@Test public void testRescaleLocalPixelInMetersSymbolizer() throws Exception { Stroke stroke = sb.createStroke(Color.RED, 2, new float[] {5, 10}); stroke.setWidth(ff.literal("2px")); LineSymbolizer ls = sb.createLineSymbolizer(stroke); ls.setUnitOfMeasure(SI.METRE); ls.accept(visitor); LineSymbolizer clone = (LineSymbolizer) visitor.getCopy(); assertEquals("4px", clone.getStroke().getWidth().evaluate(null, String.class)); }
@Test public void testNpePreventionStroke() { Style style = sb.createStyle( sb.createLineSymbolizer( sb.createStroke( sb.colorExpression(Color.BLACK), sb.literalExpression(null)))); MetaBufferEstimator rbe = new MetaBufferEstimator(); rbe.visit(style); assertEquals(1, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }
@Test public void testMath() { Add add = ff.add(ff.literal("5"), ff.literal("-2")); Symbolizer ls = sb.createLineSymbolizer(sb.createStroke(sb.colorExpression(Color.BLACK), add)); Rule r = sb.createRule(new Symbolizer[] {ls}); MetaBufferEstimator rbe = new MetaBufferEstimator(); // 5-2 = 3 rbe.visit(r); assertEquals(3, rbe.getBuffer()); assertTrue(rbe.isEstimateAccurate()); }