public void drawFeature( ViewportGraphics graphics, SimpleFeature feature, AffineTransform worldToScreenTransform, boolean drawVertices, Symbolizer symbolizer, MathTransform mathTransform, LiteShape shape) { if (symbolizer instanceof RasterSymbolizer) { // TODO } else { Geometry g = findGeometry(feature, symbolizer); if (g == null) return; if (mathTransform != null) { try { g = JTS.transform(g, mathTransform); } catch (Exception e) { // do nothing } } shape.setGeometry(g); paint(graphics, feature, shape, symbolizer); if (drawVertices) { double averageDistance = 0; Coordinate[] coords = g.getCoordinates(); java.awt.Point oldP = worldToPixel(coords[0], worldToScreenTransform); for (int i = 1; i < coords.length; i++) { Coordinate coord = coords[i]; java.awt.Point p = worldToPixel(coord, worldToScreenTransform); averageDistance += p.distance(oldP) / i; oldP = p; } int pixels = 1; if (averageDistance > 20) pixels = 3; if (averageDistance > 60) pixels = 5; if (pixels > 1) { graphics.setColor(Color.RED); for (int i = 0; i < coords.length; i++) { Coordinate coord = coords[i]; java.awt.Point p = worldToPixel(coord, worldToScreenTransform); graphics.fillRect(p.x - (pixels - 1) / 2, p.y - (pixels - 1) / 2, pixels, pixels); } } } } }
/** Unsure if this is the paint for the border, or the fill? */ private void paint(ViewportGraphics g, SimpleFeature feature, LiteShape shape, Symbolizer symb) { if (symb instanceof PolygonSymbolizer) { PolygonSymbolizer polySymb = (PolygonSymbolizer) symb; double opacity = SLDs.polyFillOpacity(polySymb); Color fillColor = SLDs.polyFill(polySymb); Stroke stroke = SLDs.stroke(polySymb); Color strokeColor = SLDs.polyColor(polySymb); int width = SLDs.width(stroke); if (width == SLDs.NOTFOUND) width = 1; if (Double.isNaN(opacity)) opacity = 1.0; if (fillColor != null) { fillColor = new Color( fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), (int) (255 * opacity)); g.setColor(fillColor); g.fill(shape); } if (stroke != null && strokeColor != null) { Graphics2D g2d = g.getGraphics(Graphics2D.class); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(strokeColor); float[] dashArray = stroke.getDashArray(); Float dashOffset = stroke.getDashOffset().evaluate(null, Float.class); if (dashOffset == null) { dashOffset = 0f; } String cap = stroke.getLineCap().evaluate(null, String.class); int capInt = Utilities.sld2awtCap(cap); String join = stroke.getLineJoin().evaluate(null, String.class); int joinInt = Utilities.sld2awtJoin(join); BasicStroke bStroke = new BasicStroke(width, capInt, joinInt, 1f, dashArray, dashOffset); g2d.setStroke(bStroke); g2d.draw(shape); } } if (symb instanceof LineSymbolizer) { LineSymbolizer lineSymbolizer = (LineSymbolizer) symb; Color c = SLDs.color(lineSymbolizer); int w = SLDs.width(lineSymbolizer); Stroke stroke = SLDs.stroke(lineSymbolizer); if (c != null && w > 0) { Graphics2D g2d = g.getGraphics(Graphics2D.class); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(c); float[] dashArray = stroke.getDashArray(); Float dashOffset = stroke.getDashOffset().evaluate(null, Float.class); if (dashOffset == null) { dashOffset = 0f; } String cap = stroke.getLineCap().evaluate(null, String.class); int capInt = Utilities.sld2awtCap(cap); String join = stroke.getLineJoin().evaluate(null, String.class); int joinInt = Utilities.sld2awtJoin(join); BasicStroke bStroke = new BasicStroke(w, capInt, joinInt, 1f, dashArray, dashOffset); g2d.setStroke(bStroke); g2d.draw(shape); } } if (symb instanceof PointSymbolizer) { PointSymbolizer pointSymbolizer = (PointSymbolizer) symb; AffineTransform transform = g.getTransform(); // offset Point2D offset = Utilities.getOffset(pointSymbolizer); if (offset != null) { java.awt.Point off = new java.awt.Point((int) offset.getX(), -1 * (int) offset.getY()); g.translate(off); } // rotation Graphic graphic = SLDs.graphic(pointSymbolizer); Double rotation = graphic.getRotation().evaluate(null, Double.class); Double gSize = graphic.getSize().evaluate(null, Double.class); if (gSize != null && rotation != null) { g.setTransform( AffineTransform.getRotateInstance(toRadians(rotation), gSize / 2, gSize / 2)); } Color c = SLDs.pointStrokeColorWithAlpha(pointSymbolizer); Color fill = SLDs.pointFillWithAlpha(pointSymbolizer); int width = SLDs.width(SLDs.stroke(pointSymbolizer)); if (width < 0) { width = 0; } float[] point = new float[6]; PathIterator pathIterator = shape.getPathIterator(null); pathIterator.currentSegment(point); SLDStyleFactory styleFactory = new SLDStyleFactory(); Style2D tmp = null; try { tmp = styleFactory.createStyle( feature, pointSymbolizer, new NumberRange(Double.class, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); } catch (Exception e) { PointSymbolizerWrapper tmpPs = new PointSymbolizerWrapper(pointSymbolizer, null); tmp = styleFactory.createStyle( feature, pointSymbolizer, new NumberRange(Double.class, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); } if (tmp instanceof MarkStyle2D) { MarkStyle2D style = (MarkStyle2D) tmp; Shape shape2 = style.getTransformedShape(point[0], point[1]); if (c == null && fill == null) { // g.setColor(Color.GRAY); // g.fill(shape2); } if (fill != null) { g.setColor(fill); g.fill(shape2); } // else { // g.setColor(Color.GRAY); // g.fill(shape2); // } if (c != null) { g.setStroke(ViewportGraphics.LINE_SOLID, width); g.setColor(c); g.draw(shape2); } // else { // g.setStroke(ViewportGraphics.LINE_SOLID, width); // g.setColor(Color.DARK_GRAY); // g.draw(shape2); // } } else if (tmp instanceof GraphicStyle2D) { GraphicStyle2D style = (GraphicStyle2D) tmp; RenderedImage image = (RenderedImage) style.getImage(); g.drawImage( image, (int) (point[0] - ((double) image.getWidth()) / (double) 2), (int) (point[1] - ((double) image.getHeight()) / (double) 2)); } } }