use of eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter in project hale by halestudio.
the class InstanceMarker method paintPoint.
/**
* Paint a point geometry.
*
* @param geometry the point
* @param g the graphics object to paint on
* @param crsDefinition the CRS definition associated to the geometry
* @param context the context
* @param converter the pixel converter
* @param zoom the zoom level
* @param mapCRS the map coordinate reference system
* @param calculateArea if the area representing the marker should be
* calculated, if <code>false</code> is given here the return
* value is ignored and should be <code>null</code>
* @return the point marker area or <code>null</code> if painting failed
*/
protected Area paintPoint(Point geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
try {
/*
* Conversion to map pixel coordinates: Though most of the time the
* result will be the origin (0,0), e.g. for way-points representing
* a single point, the coordinates may also be different, e.g. for
* MultiPoint way-points.
*/
// get CRS converter
CRSConverter conv = CRSConverter.getConverter(crsDefinition.getCRS(), mapCRS);
// manually convert to map CRS
Point3D mapPoint = conv.convert(geometry.getX(), geometry.getY(), 0);
GeoPosition pos = new GeoPosition(mapPoint.getX(), mapPoint.getY(), converter.getMapEpsg());
// determine pixel coordinates
Point2D point = converter.geoToPixel(pos, zoom);
int x = (int) point.getX();
int y = (int) point.getY();
// fall-back: circle
if (applyFill(g, context)) {
g.fillOval(x - defaultPointSize / 2, y - defaultPointSize / 2, defaultPointSize, defaultPointSize);
}
if (applyStroke(g, context)) {
// TODO respect stroke width?
g.drawOval(x - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, defaultPointSize + 1, defaultPointSize + 1);
}
if (calculateArea) {
return new PolygonArea(new java.awt.Polygon(new int[] { x - defaultPointSize / 2 - 1, x + defaultPointSize / 2 + 1, x + defaultPointSize / 2 + 1, x - defaultPointSize / 2 - 1 }, new int[] { y - defaultPointSize / 2 - 1, y - defaultPointSize / 2 - 1, y + defaultPointSize / 2 + 1, y + defaultPointSize / 2 + 1 }, 4));
} else {
return null;
}
} catch (Exception e) {
log.error("Error painting instance point geometry", e);
return null;
}
}
Aggregations