Search in sources :

Example 6 with CRSConverter

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;
    }
}
Also used : PolygonArea(de.fhg.igd.mapviewer.marker.area.PolygonArea) CRSConverter(eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter) Point2D(java.awt.geom.Point2D) Point3D(de.fhg.igd.geom.Point3D) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) Point(com.vividsolutions.jts.geom.Point) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) TransformException(org.opengis.referencing.operation.TransformException)

Aggregations

CRSConverter (eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter)6 Point (com.vividsolutions.jts.geom.Point)5 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)5 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)5 Point3D (de.fhg.igd.geom.Point3D)4 Area (de.fhg.igd.mapviewer.marker.area.Area)4 PolygonArea (de.fhg.igd.mapviewer.marker.area.PolygonArea)4 Point2D (java.awt.geom.Point2D)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 MultiArea (de.fhg.igd.mapviewer.marker.area.MultiArea)3 ArrayList (java.util.ArrayList)3 IllegalGeoPositionException (org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)3 TransformException (org.opengis.referencing.operation.TransformException)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)2 LineString (com.vividsolutions.jts.geom.LineString)2 Polygon (com.vividsolutions.jts.geom.Polygon)2 BoundingBox (de.fhg.igd.geom.BoundingBox)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 BoxArea (de.fhg.igd.mapviewer.marker.area.BoxArea)1