public void mapChanged(MapEvent mapEvent) {
restrictPanning();
}
public void restrictPanning() {
Location mapTopLeft = map.getTopLeftBorder();
Location mapBottomRight = map.getBottomRightBorder();
ScreenPosition mapTopLeftPos = map.getScreenPosition(mapTopLeft);
ScreenPosition boundTopLeftPos = map.getScreenPosition(boundTopLeft);
if (boundTopLeft.getLon() > mapTopLeft.getLon()) {
map.panBy(mapTopLeftPos.x - boundTopLeftPos.x, 0);
}
if (boundTopLeft.getLat() < mapTopLeft.getLat()) {
map.panBy(0, mapTopLeftPos.y - boundTopLeftPos.y);
}
ScreenPosition mapBottomRightPos = map.getScreenPosition(mapBottomRight);
ScreenPosition boundBottomRightPos = map.getScreenPosition(boundBottomRight);
if (boundBottomRight.getLon() < mapBottomRight.getLon()) {
map.panBy(mapBottomRightPos.x - boundBottomRightPos.x, 0);
}
if (boundBottomRight.getLat() > mapBottomRight.getLat()) {
map.panBy(0, mapBottomRightPos.y - boundBottomRightPos.y);
}
}