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