Search in sources :

Example 16 with GeoPosition

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

the class CustomWaypointPainter method findWaypoints.

/**
 * Find the way-points in a given rectangular area
 *
 * @param rect the area
 * @return the way-points in the area
 */
public Set<W> findWaypoints(Rectangle rect) {
    Rectangle viewPort = getMapKit().getMainMap().getViewportBounds();
    final Rectangle worldRect = new Rectangle(viewPort.x + rect.x, viewPort.y + rect.y, rect.width, rect.height);
    final int zoom = getMapKit().getMainMap().getZoom();
    final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter();
    final GeoPosition topLeft = converter.pixelToGeo(new Point(worldRect.x, worldRect.y), zoom);
    final GeoPosition bottomRight = converter.pixelToGeo((new Point(worldRect.x + worldRect.width, worldRect.y + worldRect.height)), zoom);
    return findWaypoints(topLeft, bottomRight, worldRect, converter, zoom);
}
Also used : Rectangle(java.awt.Rectangle) PixelConverter(org.jdesktop.swingx.mapviewer.PixelConverter) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) Point(java.awt.Point) Point(java.awt.Point)

Example 17 with GeoPosition

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

the class CustomWaypointPainter method findWaypoints.

/**
 * Find the way-points in a given polygon
 *
 * @param poly the polygon
 * @return the way-points in the polygon area
 */
public Set<W> findWaypoints(final Polygon poly) {
    Rectangle viewPort = getMapKit().getMainMap().getViewportBounds();
    final int zoom = getMapKit().getMainMap().getZoom();
    final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter();
    de.fhg.igd.geom.Point2D[] points = new de.fhg.igd.geom.Point2D[poly.npoints];
    // create a metamodel polygon
    for (int i = 0; i < poly.npoints; i++) {
        int worldX = viewPort.x + poly.xpoints[i];
        int worldY = viewPort.y + poly.ypoints[i];
        // convert to geo position
        GeoPosition pos = converter.pixelToGeo(new Point(worldX, worldY), zoom);
        // convert to common CRS
        try {
            pos = GeotoolsConverter.getInstance().convert(pos, SelectableWaypoint.COMMON_EPSG);
        } catch (IllegalGeoPositionException e) {
            // $NON-NLS-1$
            log.warn("Error converting polygon point for query");
            return new HashSet<W>();
        }
        points[i] = new de.fhg.igd.geom.Point2D(pos.getX(), pos.getY());
    }
    final de.fhg.igd.geom.shape.Polygon verifyPolygon = new de.fhg.igd.geom.shape.Polygon(points);
    // we need a 3D search bounding box for the R-Tree
    BoundingBox searchBox = verifyPolygon.getBoundingBox();
    searchBox.setMinZ(-2.0);
    searchBox.setMaxZ(2.0);
    poly.translate(viewPort.x, viewPort.y);
    try {
        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox second) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);
                    int dx = (int) wpPixel.getX();
                    int dy = (int) wpPixel.getY();
                    poly.translate(-dx, -dy);
                    try {
                        Area area = wp.getMarker().getArea(zoom);
                        if (area != null) {
                            return area.containedIn(poly);
                        } else {
                            // not be selected
                            return false;
                        }
                    } finally {
                        poly.translate(dx, dy);
                    }
                } catch (IllegalGeoPositionException e) {
                    log.warn("Could not convert waypoint position to pixel", e);
                    // fall back to simple method
                    return verifyPolygon.contains(wp.getBoundingBox().toExtent());
                }
            }
        });
        if (wps == null) {
            return new HashSet<W>();
        } else {
            return wps;
        }
    } finally {
        poly.translate(-viewPort.x, -viewPort.y);
    }
}
Also used : Rectangle(java.awt.Rectangle) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point) Point(java.awt.Point) Area(de.fhg.igd.mapviewer.marker.area.Area) Point2D(java.awt.geom.Point2D) BoundingBox(de.fhg.igd.geom.BoundingBox) PixelConverter(org.jdesktop.swingx.mapviewer.PixelConverter) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) Polygon(java.awt.Polygon) HashSet(java.util.HashSet)

Example 18 with GeoPosition

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

the class CustomWaypointPainter method repaintTile.

/**
 * @see AbstractTileOverlayPainter#repaintTile(int, int, int, int,
 *      PixelConverter, int)
 */
@Override
public BufferedImage repaintTile(int posX, int posY, int width, int height, PixelConverter converter, int zoom) {
    if (renderer == null) {
        return null;
    }
    int overlap = getMaxOverlap();
    // overlap pixel coordinates
    Point topLeftPixel = new Point(Math.max(posX - overlap, 0), Math.max(posY - overlap, 0));
    // TODO
    Point bottomRightPixel = new Point(posX + width + overlap, posY + height + overlap);
    // check
    // against
    // map
    // size
    // overlap geo positions
    GeoPosition topLeft = converter.pixelToGeo(topLeftPixel, zoom);
    GeoPosition bottomRight = converter.pixelToGeo(bottomRightPixel, zoom);
    // overlap geo positions in RTree CRS
    try {
        BoundingBox tileBounds = createSearchBB(topLeft, bottomRight);
        synchronized (waypoints) {
            Set<W> candidates = waypoints.query(tileBounds, matchTileVerifier);
            if (candidates != null) {
                // sort way-points
                List<W> sorted = new ArrayList<W>(candidates);
                Collections.sort(sorted, paintFirstComparator);
                BufferedImage image = createImage(width, height);
                Graphics2D gfx = image.createGraphics();
                configureGraphics(gfx);
                try {
                    // for each way-point within these bounds
                    for (W w : sorted) {
                        processWaypoint(w, posX, posY, width, height, converter, zoom, gfx);
                    }
                /*
						 * DEBUG String test = getClass().getSimpleName() +
						 * " - x=" + posX + ", y=" + posY + ": " +
						 * candidates.size() + " WPs"; gfx.setColor(Color.BLUE);
						 * gfx.drawString(test, 4, height - 4);
						 * 
						 * gfx.drawString("minX: " + tileBounds.getMinX(), 4,
						 * height - 84); gfx.drawString("maxX: " +
						 * tileBounds.getMaxX(), 4, height - 64);
						 * gfx.drawString("minY: " + tileBounds.getMinY(), 4,
						 * height - 44); gfx.drawString("maxY: " +
						 * tileBounds.getMaxY(), 4, height - 24);
						 * 
						 * gfx.drawRect(0, 0, width - 1, height - 1);
						 */
                } finally {
                    gfx.dispose();
                }
                return image;
            } else {
                return null;
            }
        }
    } catch (IllegalGeoPositionException e) {
        // $NON-NLS-1$
        log.warn("Error painting waypoint tile: " + e.getMessage());
        return null;
    }
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox) ArrayList(java.util.ArrayList) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) IllegalGeoPositionException(org.jdesktop.swingx.mapviewer.IllegalGeoPositionException) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 19 with GeoPosition

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

the class SelectableWaypoint method addToRefresher.

/**
 * Add a way-point to the refresher
 *
 * @param refresher the refresher
 */
public void addToRefresher(Refresher refresher) {
    if (isPoint()) {
        refresher.addPosition(getPosition());
    } else {
        BoundingBox bb = getBoundingBox();
        GeoPosition bottomRight = new GeoPosition(bb.getMaxX(), bb.getMaxY(), COMMON_EPSG);
        GeoPosition topLeft = new GeoPosition(bb.getMinX(), bb.getMinY(), COMMON_EPSG);
        refresher.addArea(topLeft, bottomRight);
    }
}
Also used : BoundingBox(de.fhg.igd.geom.BoundingBox) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition)

Example 20 with GeoPosition

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

the class BBOXPage method createContent.

@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(page);
    SwingComposite wrapper = new SwingComposite(page);
    GridDataFactory.fillDefaults().grab(true, true).hint(600, 400).applyTo(wrapper);
    wrapper.getContentPane().setLayout(new BorderLayout());
    // create map kit
    mapKit = new BasicMapKit();
    // configure map
    updateMap(null);
    // mapKit.addCustomPainter(mypainter);
    // add map kit
    wrapper.getContentPane().add(mapKit, BorderLayout.CENTER);
    // create tool
    final Display display = Display.getCurrent();
    final Runnable updateRunner = new Runnable() {

        @Override
        public void run() {
            updateState();
        }
    };
    bboxTool = new BBoxTool() {

        @Override
        protected void addPosition(GeoPosition pos) {
            super.addPosition(pos);
            display.asyncExec(updateRunner);
        }

        @Override
        public void reset() {
            super.reset();
            display.asyncExec(updateRunner);
        }
    };
    // activate tool
    new MapToolAction(bboxTool, mapKit, true);
    setControl(page);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SwingComposite(eu.esdihumboldt.hale.ui.util.swing.SwingComposite) BorderLayout(java.awt.BorderLayout) BasicMapKit(de.fhg.igd.mapviewer.BasicMapKit) BBoxTool(eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.BBoxTool) MapToolAction(de.fhg.igd.mapviewer.view.MapToolAction) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) SwingComposite(eu.esdihumboldt.hale.ui.util.swing.SwingComposite) Display(org.eclipse.swt.widgets.Display)

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