X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2FViewport.java;fp=src%2Ftim%2Fprune%2Fgui%2FViewport.java;h=25eba2fb1847306d41aed63021c7cbe3e4ed2cf0;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/Viewport.java b/src/tim/prune/gui/Viewport.java new file mode 100644 index 0000000..25eba2f --- /dev/null +++ b/src/tim/prune/gui/Viewport.java @@ -0,0 +1,43 @@ +package tim.prune.gui; + +import tim.prune.gui.map.MapCanvas; +import tim.prune.gui.map.MapPosition; +import tim.prune.gui.map.MapUtils; + +/** + * Class to provide access to current viewport + * The point of this class is to decouple the view from the MapCanvas object + * so that when the GetGpsies function needs to know the area currently viewed, it doesn't + * need to have a direct connection to the MapCanvas. Instead it asks the App for the viewport, + * which is then able to get the map position from the MapCanvas. + * I'm still not sure whether this is ugly or not, but it's more efficient than constantly listening. + */ +public class Viewport +{ + /** Map canvas object */ + private MapCanvas _mapCanvas = null; + + /** + * Constructor + * @param inCanvas map canvas object + */ + public Viewport(MapCanvas inCanvas) + { + _mapCanvas = inCanvas; + } + + /** + * @return coordinate bounds of current viewport + */ + public double[] getBounds() + { + int width = _mapCanvas.getWidth(); + int height = _mapCanvas.getHeight(); + MapPosition mapPosition = _mapCanvas.getMapPosition(); + double minLat = MapUtils.getLatitudeFromY(mapPosition.getYFromPixels(height, height)); + double maxLat = MapUtils.getLatitudeFromY(mapPosition.getYFromPixels(0, height)); + double minLon = MapUtils.getLongitudeFromX(mapPosition.getXFromPixels(0, width)); + double maxLon = MapUtils.getLongitudeFromX(mapPosition.getXFromPixels(width, width)); + return new double[] {minLat, minLon, maxLat, maxLon}; + } +}