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