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);
}
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);
}
}
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;
}
}
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);
}
}
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);
}
Aggregations