Search in sources :

Example 26 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition 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 27 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition 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 28 with GeoPosition

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

the class BasicMapKit method centerOnPositions.

/**
 * Center on the given {@link GeoPosition}s
 *
 * @param positions the {@link GeoPosition}s
 */
public void centerOnPositions(Set<GeoPosition> positions) {
    if (positions.size() == 0)
        return;
    positions = equalizeEpsg(positions);
    double minX = 0, maxX = 0, minY = 0, maxY = 0;
    boolean init = false;
    int epsg = positions.iterator().next().getEpsgCode();
    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();
        }
    }
    setCenterPosition(new GeoPosition((minX + maxX) / 2.0, (minY + maxY) / 2.0, epsg));
}
Also used : GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) Point(java.awt.Point)

Example 29 with GeoPosition

use of org.jdesktop.swingx.mapviewer.GeoPosition 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)

Example 30 with GeoPosition

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

the class HoverMapTip method showTip.

private void showTip(final MouseEvent e, final String text) {
    synchronized (HoverMapTip.this) {
        PixelConverter converter = getMap().getTileFactory().getTileProvider().getConverter();
        int zoom = getMap().getZoom();
        Rectangle viewPort = getMap().getViewportBounds();
        GeoPosition pos = converter.pixelToGeo(new Point(viewPort.x + e.getX(), viewPort.y + e.getY()), zoom);
        setTipText(text, pos);
        if (closeTimer != null) {
            closeTimer.cancel(true);
        }
        closeTimer = scheduleService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                hideTip();
            }
        }, 5 * HOVER_DELAY, 1000, TimeUnit.MILLISECONDS);
    }
}
Also used : PixelConverter(org.jdesktop.swingx.mapviewer.PixelConverter) Rectangle(java.awt.Rectangle) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)33 BoundingBox (de.fhg.igd.geom.BoundingBox)11 Point (java.awt.Point)10 IllegalGeoPositionException (org.jdesktop.swingx.mapviewer.IllegalGeoPositionException)10 ArrayList (java.util.ArrayList)9 Point2D (java.awt.geom.Point2D)8 Point3D (de.fhg.igd.geom.Point3D)6 HashSet (java.util.HashSet)6 Area (de.fhg.igd.mapviewer.marker.area.Area)5 SelectableWaypoint (de.fhg.igd.mapviewer.waypoints.SelectableWaypoint)5 CRSConverter (eu.esdihumboldt.hale.ui.views.styledmap.util.CRSConverter)5 Rectangle (java.awt.Rectangle)5 Point (com.vividsolutions.jts.geom.Point)4 PixelConverter (org.jdesktop.swingx.mapviewer.PixelConverter)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 PolygonArea (de.fhg.igd.mapviewer.marker.area.PolygonArea)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)2 MultiArea (de.fhg.igd.mapviewer.marker.area.MultiArea)2