Search in sources :

Example 6 with IllegalGeoPositionException

use of org.jdesktop.swingx.mapviewer.IllegalGeoPositionException in project hale by halestudio.

the class CustomWaypointPainter method processWaypoint.

private void processWaypoint(W w, int minX, int minY, int width, int height, PixelConverter converter, int zoom, Graphics2D g) {
    try {
        Point2D point = converter.geoToPixel(w.getPosition(), zoom);
        int x = (int) (point.getX() - minX);
        int y = (int) (point.getY() - minY);
        PixelConverter converterWrapper = new TranslationPixelConverterDecorator(converter, (int) point.getX(), (int) point.getY());
        g.translate(x, y);
        Rectangle gBounds = new Rectangle(minX - (int) point.getX(), minY - (int) point.getY(), width, height);
        renderer.paintWaypoint(g, converterWrapper, zoom, w, gBounds);
        g.translate(-x, -y);
    } catch (IllegalGeoPositionException e) {
    // waypoint not in map bounds or position invalid
    // log.warn("Error painting waypoint", e);
    }
}
Also used : Point2D(java.awt.geom.Point2D) PixelConverter(org.jdesktop.swingx.mapviewer.PixelConverter) Rectangle(java.awt.Rectangle) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point)

Example 7 with IllegalGeoPositionException

use of org.jdesktop.swingx.mapviewer.IllegalGeoPositionException in project hale by halestudio.

the class InstanceTool method click.

/**
 * @see AbstractMapTool#click(MouseEvent, GeoPosition)
 */
@Override
public void click(MouseEvent me, GeoPosition pos) {
    if (me.getClickCount() == 2) {
        mapKit.setCenterPosition(pos);
        mapKit.setZoom(mapKit.getMainMap().getZoom() - 1);
    } else if (me.getClickCount() == 1) {
        if (me.isAltDown() && getPositions().size() < 1) {
            // add pos
            addPosition(pos);
        } else if (getPositions().size() == 1) {
            // finish box selection
            // action & reset
            addPosition(pos);
            // action
            try {
                List<Point2D> points = getPoints();
                Rectangle rect = new Rectangle((int) points.get(0).getX(), (int) points.get(0).getY(), 0, 0);
                rect.add(points.get(1));
                updateSelection(rect, me.isControlDown() || me.isMetaDown(), true);
            } catch (IllegalGeoPositionException e) {
                // $NON-NLS-1$
                log.error("Error calculating selection box", e);
            }
            reset();
        } else {
            // click selection
            reset();
            updateSelection(me.getPoint(), me.isControlDown() || me.isMetaDown(), true);
        }
    }
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle(java.awt.Rectangle) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)

Example 8 with IllegalGeoPositionException

use of org.jdesktop.swingx.mapviewer.IllegalGeoPositionException in project hale by halestudio.

the class BasicMapKit method equalizeEpsg.

private static Set<GeoPosition> equalizeEpsg(Collection<GeoPosition> positions) {
    if (positions.isEmpty())
        return new HashSet<GeoPosition>(positions);
    int epsg = -1;
    Set<GeoPosition> result = new HashSet<GeoPosition>();
    for (GeoPosition pos : positions) {
        if (epsg == -1) {
            epsg = pos.getEpsgCode();
            result.add(pos);
        } else if (epsg != pos.getEpsgCode()) {
            GeoPosition altPos;
            try {
                altPos = GeotoolsConverter.getInstance().convert(pos, epsg);
                result.add(altPos);
            } catch (IllegalGeoPositionException e) {
                // $NON-NLS-1$
                log.warn("Error converting GeoPosition, ignoring this position");
            }
        } else {
            result.add(pos);
        }
    }
    return result;
}
Also used : GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point) HashSet(java.util.HashSet)

Example 9 with IllegalGeoPositionException

use of org.jdesktop.swingx.mapviewer.IllegalGeoPositionException in project hale by halestudio.

the class BasicMapKit method zoomToPositions.

/**
 * Zoom in and center on the given {@link GeoPosition}s
 *
 * @param positions the {@link GeoPosition}s
 */
public void zoomToPositions(Set<GeoPosition> positions) {
    if (positions.size() == 0)
        return;
    positions = equalizeEpsg(positions);
    int epsg = positions.iterator().next().getEpsgCode();
    double minX = 0, maxX = 0, minY = 0, maxY = 0;
    boolean init = false;
    for (GeoPosition pos : positions) {
        if (!init) {
            // first pos
            minY = maxY = pos.getY();
            minX = maxX = pos.getX();
            init = true;
        } else {
            if (pos.getY() < minY)
                minY = pos.getY();
            else if (pos.getY() > maxY)
                maxY = pos.getY();
            if (pos.getX() < minX)
                minX = pos.getX();
            else if (pos.getX() > maxX)
                maxX = pos.getX();
        }
    }
    // center on positions
    setCenterPosition(new GeoPosition((minX + maxX) / 2.0, (minY + maxY) / 2.0, epsg));
    // initial zoom
    int zoom = getMainMap().getTileFactory().getTileProvider().getMinimumZoom();
    try {
        if (positions.size() >= 2) {
            int viewWidth = (int) getMainMap().getViewportBounds().getWidth();
            int viewHeight = (int) getMainMap().getViewportBounds().getHeight();
            Rectangle2D rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom);
            while ((viewWidth < rect.getWidth() || viewHeight < rect.getHeight()) && zoom < getMainMap().getTileFactory().getTileProvider().getMaximumZoom()) {
                zoom++;
                rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom);
            }
        }
        setZoom(zoom);
    } catch (IllegalGeoPositionException e) {
        // , e); //$NON-NLS-1$
        log.warn("Error zooming to positions");
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point)

Example 10 with IllegalGeoPositionException

use of org.jdesktop.swingx.mapviewer.IllegalGeoPositionException in project hale by halestudio.

the class BoundingBoxMarker method paintMarker.

/**
 * @see AbstractMarker#paintMarker(Graphics2D, Object, PixelConverter, int,
 *      Rectangle, boolean)
 */
@Override
protected Area paintMarker(Graphics2D g, T context, PixelConverter converter, int zoom, Rectangle gBounds, boolean calculateArea) {
    if (context.isPoint()) {
        return paintFallback(g, context, converter, zoom, gBounds, calculateArea);
    }
    BoundingBox bb = context.getBoundingBox();
    int code = SelectableWaypoint.COMMON_EPSG;
    GeoPosition pos1 = new GeoPosition(bb.getMinX(), bb.getMinY(), code);
    GeoPosition pos2 = new GeoPosition(bb.getMaxX(), bb.getMaxY(), code);
    try {
        Point2D p1 = converter.geoToPixel(pos1, zoom);
        Point2D p2 = converter.geoToPixel(pos2, zoom);
        int minX = (int) Math.min(p1.getX(), p2.getX());
        int minY = (int) Math.min(p1.getY(), p2.getY());
        int maxX = (int) Math.max(p1.getX(), p2.getX());
        int maxY = (int) Math.max(p1.getY(), p2.getY());
        int width = maxX - minX;
        int height = maxY - minY;
        // decide whether it is to small to paint
        if (isToSmall(width, height, zoom)) {
            return paintFallback(g, context, converter, zoom, gBounds, calculateArea);
        }
        return doPaintMarker(g, context, converter, zoom, minX, minY, maxX, maxY, gBounds, calculateArea);
    } catch (IllegalGeoPositionException e) {
        // use fallback marker instead
        return paintFallback(g, context, converter, zoom, gBounds, calculateArea);
    }
}
Also used : Point2D(java.awt.geom.Point2D) BoundingBox(de.fhg.igd.geom.BoundingBox) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)

Aggregations

IllegalGeoPositionException (org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)13 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)8 Point (java.awt.Point)7 BoundingBox (de.fhg.igd.geom.BoundingBox)6 Point2D (java.awt.geom.Point2D)6 Rectangle (java.awt.Rectangle)4 Area (de.fhg.igd.mapviewer.marker.area.Area)3 HashSet (java.util.HashSet)3 PixelConverter (org.jdesktop.swingx.mapviewer.PixelConverter)3 ArrayList (java.util.ArrayList)2 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Polygon (java.awt.Polygon)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 Length (javax.measure.quantity.Length)1 GeotoolsConverter (org.jdesktop.swingx.mapviewer.GeotoolsConverter)1 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)1 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)1