Search in sources :

Example 1 with GraphicStyle2D

use of org.geotools.renderer.style.GraphicStyle2D in project hale by halestudio.

the class StyledInstanceMarker method paintPoint.

/**
 * @see InstanceMarker#paintPoint(Point, Graphics2D, CRSDefinition,
 *      InstanceWaypoint, PixelConverter, int, CoordinateReferenceSystem,
 *      boolean)
 */
@Override
protected Area paintPoint(Point geometry, Graphics2D g, CRSDefinition crsDefinition, InstanceWaypoint context, PixelConverter converter, int zoom, CoordinateReferenceSystem mapCRS, boolean calculateArea) {
    initStyle(context);
    Area area = null;
    try {
        if (pointSymbolizer == null || (SLD.mark(pointSymbolizer) == null && pointSymbolizer.getGraphic().graphicalSymbols().isEmpty())) {
            // generic
            return super.paintFallback(g, context, converter, zoom, null, calculateArea);
        }
        // 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);
        Coordinate coordinate = new Coordinate(point.getX(), point.getY());
        Point newPoint = geometry.getFactory().createPoint(coordinate);
        // create a LiteShape and instantiate the Painter and the
        // StyleFactory
        LiteShape2 lites = new LiteShape2(newPoint, null, null, false);
        StyledShapePainter ssp = new StyledShapePainter();
        SLDStyleFactory styleFactory = new SLDStyleFactory();
        Range<Double> range = new Range<Double>(Double.class, 0.5, 1.5);
        PointSymbolizer pointS;
        // is the Waypoint selected?
        if (context.isSelected()) {
            // switch to the SelectionSymbolizer
            pointS = getSelectionSymbolizer(pointSymbolizer);
        } else
            // use the specific PointSymbolizer
            pointS = pointSymbolizer;
        // Create the Style2D object for painting with the use of a
        // DummyFeature wich extends SimpleFeatures
        // because Geotools can only work with that
        DummyFeature dummy = new DummyFeature();
        Style2D style2d = styleFactory.createStyle(dummy, pointS, range);
        // create the area object of the painted image for further use
        area = getArea(point, style2d, lites);
        // actually paint
        ssp.paint(g, lites, style2d, 1);
        // graphic)
        if (context.isSelected() && style2d instanceof GraphicStyle2D) {
            GraphicStyle2D gs2d = (GraphicStyle2D) style2d;
            // get minX and minY for the drawn rectangle arround the image
            int minX = (int) point.getX() - gs2d.getImage().getWidth() / 2;
            int minY = (int) point.getY() - gs2d.getImage().getHeight() / 2;
            // apply the specification of the selection rectangle
            applyFill(g, context);
            applyStroke(g, context);
            // draw the selection rectangle
            g.drawRect(minX - 1, minY - 1, gs2d.getImage().getWidth() + 1, gs2d.getImage().getHeight() + 1);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return area;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Range(org.geotools.util.Range) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GraphicStyle2D(org.geotools.renderer.style.GraphicStyle2D) MarkStyle2D(org.geotools.renderer.style.MarkStyle2D) Style2D(org.geotools.renderer.style.Style2D) BoxArea(de.fhg.igd.mapviewer.marker.area.BoxArea) Area(de.fhg.igd.mapviewer.marker.area.Area) GraphicStyle2D(org.geotools.renderer.style.GraphicStyle2D) CRSConverter(eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter) Point2D(java.awt.geom.Point2D) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point3D(de.fhg.igd.geom.Point3D) SLDStyleFactory(org.geotools.renderer.style.SLDStyleFactory) LiteShape2(org.geotools.geometry.jts.LiteShape2) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) StyledShapePainter(org.geotools.renderer.lite.StyledShapePainter)

Example 2 with GraphicStyle2D

use of org.geotools.renderer.style.GraphicStyle2D in project hale by halestudio.

the class StyledInstanceMarker method getArea.

/**
 * Returns the area of the drawn point.
 *
 * @param point the point
 * @param style the Style2D object
 * @param shape the Light Shape
 * @return the area, which should equal the space of the drawn object
 */
private Area getArea(Point2D point, Style2D style, LiteShape2 shape) {
    // if it is a mark style
    if (style instanceof MarkStyle2D) {
        PathIterator citer = getPathIterator(shape);
        float[] coords = new float[2];
        MarkStyle2D ms2d = (MarkStyle2D) style;
        Shape transformedShape;
        while (!(citer.isDone())) {
            citer.currentSegment(coords);
            transformedShape = ms2d.getTransformedShape(coords[0], coords[1]);
            if (transformedShape != null) {
                java.awt.geom.Area areatemp = new java.awt.geom.Area(transformedShape);
                Rectangle rec = areatemp.getBounds();
                AdvancedBoxArea area = new AdvancedBoxArea(areatemp, rec.x, rec.y, rec.x + rec.width, rec.y + rec.height);
                return area;
            }
        }
    } else // if it is an external graphic style
    if (style instanceof GraphicStyle2D) {
        GraphicStyle2D gs2d = (GraphicStyle2D) style;
        int minX = (int) point.getX() - gs2d.getImage().getWidth() / 2;
        int minY = (int) point.getY() - gs2d.getImage().getHeight() / 2;
        int maxX = (int) point.getX() + gs2d.getImage().getWidth() / 2;
        int maxY = (int) point.getX() + gs2d.getImage().getHeight() / 2;
        BoxArea area = new BoxArea(minX, minY, maxX, maxY);
        return area;
    }
    return null;
}
Also used : Shape(java.awt.Shape) PathIterator(java.awt.geom.PathIterator) BoxArea(de.fhg.igd.mapviewer.marker.area.BoxArea) Rectangle(java.awt.Rectangle) MarkStyle2D(org.geotools.renderer.style.MarkStyle2D) BoxArea(de.fhg.igd.mapviewer.marker.area.BoxArea) Area(de.fhg.igd.mapviewer.marker.area.Area) GraphicStyle2D(org.geotools.renderer.style.GraphicStyle2D)

Aggregations

Area (de.fhg.igd.mapviewer.marker.area.Area)2 BoxArea (de.fhg.igd.mapviewer.marker.area.BoxArea)2 GraphicStyle2D (org.geotools.renderer.style.GraphicStyle2D)2 MarkStyle2D (org.geotools.renderer.style.MarkStyle2D)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 Point (com.vividsolutions.jts.geom.Point)1 Point3D (de.fhg.igd.geom.Point3D)1 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)1 CRSConverter (eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 PathIterator (java.awt.geom.PathIterator)1 Point2D (java.awt.geom.Point2D)1 LiteShape2 (org.geotools.geometry.jts.LiteShape2)1 StyledShapePainter (org.geotools.renderer.lite.StyledShapePainter)1 SLDStyleFactory (org.geotools.renderer.style.SLDStyleFactory)1 Style2D (org.geotools.renderer.style.Style2D)1 PointSymbolizer (org.geotools.styling.PointSymbolizer)1 Range (org.geotools.util.Range)1