3 import tim.prune.gui.map.MapCanvas;
4 import tim.prune.gui.map.MapPosition;
5 import tim.prune.gui.map.MapUtils;
8 * Class to provide access to current viewport
9 * The point of this class is to decouple the view from the MapCanvas object
10 * so that when the GetGpsies function needs to know the area currently viewed, it doesn't
11 * need to have a direct connection to the MapCanvas. Instead it asks the App for the viewport,
12 * which is then able to get the map position from the MapCanvas.
13 * I'm still not sure whether this is ugly or not, but it's more efficient than constantly listening.
17 /** Map canvas object */
18 private MapCanvas _mapCanvas = null;
22 * @param inCanvas map canvas object
24 public Viewport(MapCanvas inCanvas)
26 _mapCanvas = inCanvas;
30 * @return coordinate bounds of current viewport
32 public double[] getBounds()
34 int width = _mapCanvas.getWidth();
35 int height = _mapCanvas.getHeight();
36 MapPosition mapPosition = _mapCanvas.getMapPosition();
37 double minLat = MapUtils.getLatitudeFromY(mapPosition.getYFromPixels(height, height));
38 double maxLat = MapUtils.getLatitudeFromY(mapPosition.getYFromPixels(0, height));
39 double minLon = MapUtils.getLongitudeFromX(mapPosition.getXFromPixels(0, width));
40 double maxLon = MapUtils.getLongitudeFromX(mapPosition.getXFromPixels(width, width));
41 return new double[] {minLat, minLon, maxLat, maxLon};