Search in sources :

Example 1 with BoxArea

use of de.fhg.igd.mapviewer.marker.area.BoxArea 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)

Example 2 with BoxArea

use of de.fhg.igd.mapviewer.marker.area.BoxArea in project hale by halestudio.

the class ImageMarker method paintMarker.

/**
 * @see SimpleMarker#paintMarker(java.lang.Object)
 */
@Override
protected Area paintMarker(T context) {
    int width = image.getWidth();
    int height = image.getHeight();
    if (height > maxHeight) {
        float shrink = (float) maxHeight / (float) height;
        height = maxHeight;
        width = (int) (width * shrink);
    }
    int x = -width / 2;
    int y = -height / 2;
    // create graphics for image plus one pixel border
    Graphics2D g = beginPainting(width + 2, height + 2, width / 2 + 1, height / 2 + 1);
    try {
        g.drawImage(image, x, y, x + width, y + height, 0, 0, image.getWidth(), image.getHeight(), null);
        // shadow
        if (!hasAlpha(image)) {
            g.setColor(new Color(0, 0, 0, 180));
            // g.setColor((selected)?(new Color(200, 0, 0, 180)):(new
            // Color(0, 0, 200, 180)));
            g.fillPolygon(new int[] { x + 3, x + width, x + width, x + width + 3, x + width + 3, x + 3 }, new int[] { y + height, y + height, y + 3, y + 3, y + height + 3, y + height + 3 }, 6);
        }
        // selection
        if (context.isSelected()) {
            g.setColor(Color.RED);
            g.drawRect(x - 1, y - 1, width + 1, height + 1);
        }
    } finally {
        endPainting(g);
    }
    return new BoxArea(x, y, x + width, y + height);
}
Also used : Color(java.awt.Color) BoxArea(de.fhg.igd.mapviewer.marker.area.BoxArea) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Graphics2D(java.awt.Graphics2D)

Aggregations

BoxArea (de.fhg.igd.mapviewer.marker.area.BoxArea)2 Area (de.fhg.igd.mapviewer.marker.area.Area)1 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 PathIterator (java.awt.geom.PathIterator)1 GraphicStyle2D (org.geotools.renderer.style.GraphicStyle2D)1 MarkStyle2D (org.geotools.renderer.style.MarkStyle2D)1