@Override public Shape getShape(Graphics2D graphics, Expression symbolUrl, Feature feature) throws Exception { RenderableSVG svg = cache.getRenderableSVG(feature, symbolUrl, "image/svg"); if (svg == null) { return null; } Shape shape = getShape(svg.node); final Rectangle2D bounds = shape.getBounds2D(); double maxSize = Math.max(bounds.getWidth(), bounds.getHeight()); // flip and center the shape double scaleToOne = 1 / maxSize; final AffineTransform at = new AffineTransform(scaleToOne, 0, 0, -scaleToOne, -0.5, 0.5); TransformedShape ts = new TransformedShape(shape, at); return ts; }
@Test public void testBounds() { GeneralPath gp = new GeneralPath(); gp.moveTo(0f, 0f); gp.lineTo(1, 0.3); gp.lineTo(0f, 0.6f); gp.closePath(); AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5); TransformedShape ts = new TransformedShape(gp, at); assertEquals(new Rectangle(0, 0, 2, 1), ts.getBounds()); } }
: bounds.getHeight()); double scale = size / shapeSize; TransformedShape ts = new TransformedShape(); ts.shape = shape;
TransformedShape tss = new TransformedShape(); tss.shape = original; tss.setTransform(
result = new TransformedShape(result, transform);
/** * Returns a shape that can be used to draw the mark at the x, y coordinates * with appropriated rotation and size (according to the current style) * * @param x the x coordinate where the mark will be drawn * @param y the y coordinate where the mark will be drawn * @param rotation a custom rotation, other than the mark build in one * * @return a shape that can be used to draw the mark */ public Shape getTransformedShape(float x, float y, float rotation) { if (shape != null) { Rectangle2D bounds = shape.getBounds2D(); double shapeSize = (maxMarkSizeEnabled ? Math.max(bounds.getWidth(), bounds.getHeight()) : bounds.getHeight()); double scale = size / shapeSize; TransformedShape ts = new TransformedShape(); ts.shape = shape; ts.translate(x, y); ts.rotate(rotation); // flip the symbol to take into account the screen orientation // where the y grows from top to bottom ts.scale(scale, -scale); return ts; } else { return null; } }
/** * Returns a shape that can be used to draw the mark at the x, y coordinates * with appropriated rotation and size (according to the current style) * * @param x the x coordinate where the mark will be drawn * @param y the y coordinate where the mark will be drawn * * @return a shape that can be used to draw the mark */ public Shape getTransformedShape(float x, float y) { if (shape != null) { Rectangle2D bounds = shape.getBounds2D(); double shapeSize = Math.max(bounds.getWidth(), bounds.getHeight()); double scale = size / shapeSize; TransformedShape ts = new TransformedShape(); ts.shape = shape; ts.translate(x, y); ts.rotate(rotation); ts.scale(scale, -scale); return ts; } else { return null; } }
TransformedShape tss = new TransformedShape(); tss.shape = original; tss.setTransform(AffineTransform.getScaleInstance(width / bounds.getWidth(), height / bounds.getHeight()));