[geotk] Drawing rotated circles. Question on
AffineTransform2D.createTransformedShape()
Thys Meintjes
sthysel at gmail.com
Wed Aug 3 02:46:44 EDT 2011
Hi All,
In my Graphic below I'm drawing range rings from a center. To scale the
range rings geographically I calculate the circles' bounding boxes and then
transform to screen coordinates.
See below. When I now use the map rotate widget the rings get drawn with the
bounding box untransformed. Passing the circle to
AffineTransform2D.createTransformedShape()
and drawing that shape doesn't draw anything at all... Could anyone spot the
bug in my code ?
public class RadarGraphic extends AbstractGraphicJ2D {
private final static Logger logger =
LoggerFactory.getLogger(RadarGraphic.class);
private GeodeticCalculator calc;
private Radar radar;
public RadarGraphic(J2DCanvas canvas, Radar radar) {
super(canvas, canvas.getObjectiveCRS2D());
this.radar = radar;
calc = new GeodeticCalculator(DefaultGeographicCRS.WGS84);
}
@Override
public void paint(RenderingContext2D context) {
final Graphics2D g2d = context.getGraphics();
// transform from geographic to screen space
final AffineTransform2D transformer =
context.getObjectiveToDisplay();
//transformer.setToRotation(context.getCanvas().getController().getRotation());
final DirectPosition radarPosition = radar.getAntennaPosition();
if (radarPosition == null) {
logger.debug("Radar " + radar.getName() + " antenna position not
set");
return;
}
Point2D.Double center = new
Point2D.Double(radarPosition.getOrdinate(0), radarPosition.getOrdinate(1));
for (Double range : radar.getRangeList()) {
drawRangeRing(g2d, center, range, transformer);
}
drawRadar(g2d, center, transformer);
}
private void drawRangeRing(Graphics2D g2d, Point2D.Double center, Double
range, AffineTransform2D transformer) {
// topLeft
calc.setStartingGeographicPoint(center);
calc.setDirection(-45.0, Math.sqrt(2.0) * range);
Point2D.Double topLeft = (Point2D.Double)
calc.getDestinationGeographicPoint();
// bottomRight
calc.setStartingGeographicPoint(center);
calc.setDirection(135.0, Math.sqrt(2.0) * range);
Point2D.Double bottomRight = (Point2D.Double)
calc.getDestinationGeographicPoint();
transformer.transform(topLeft, topLeft);
transformer.transform(bottomRight, bottomRight);
g2d.setStroke(new BasicStroke(4));
Shape circle = new Ellipse2D.Double(
topLeft.x,
topLeft.y,
bottomRight.x - topLeft.x,
bottomRight.y - topLeft.y);
g2d.setPaint(Color.GREEN);
g2d.draw(circle);
}
--
Thys Meintjes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20110803/5c0a080c/attachment.html
More information about the Geotoolkit
mailing list