I trying to integrate JxMapViewer into my swing application.
I have drawn a line on the map between two way points. Now I wish to implement a functionality like:
Wherever I am on a map, whatever zoom level is set, whenever i click on a button (or some external event), focus should be shifted to line i have drawn (i.e. indirectly on the two waypoints)
Secondly, the zoom level should be set such that portion of a map containing those two waypoints should be visible.
I see that we have getViewportBounds
method inside JxMApViewer
class. Similarly we do not have setViewportBounds
. In that case we could have calculated a rectangle which encompasses those two waypoints and set it.
Any hint would be appreciated
I have modified existing calculateZoomFrom
method as:
int zoom = mainMap.getZoom();
Rectangle2D inner = generateBoundedRectangleForLine(positionSet, mainMap.getZoom());
int count = 0;
Rectangle outer = mainMap.getViewportBounds();
while(!outer.contains(inner) || (outer.contains(inner) && !(inner.getHeight() >= mainMap.getHeight() - 50))) {
Point2D center = new Point2D.Double(
inner.getX() + inner.getWidth()/2,
inner.getY() + inner.getHeight()/2);
GeoPosition px = mainMap.getTileFactory().pixelToGeo(center,zoom);
mainMap.setCenterPosition(px);
count++;
if(count > 30) break;
if(outer.contains(inner)) {
if (!(inner.getHeight() >= mainMap.getHeight() - 50)) {
zoom = zoom - 1;
if(zoom < 1) {
break;
}
} else {
break;
}
} else {
zoom = zoom + 1;
if(zoom > 15) {
break;
}
}
mainMap.setZoom(zoom);
inner = generateBoundedRectangleForLine(positionSet, zoom);
}
But it is not working.