| 143 | | final double size = 180.0 / Math.pow(2, zoom); |
| | 144 | int tileSizeInPixels = 256; |
| | 145 | int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; |
| | 146 | int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; |
| | 147 | double deltaX = screenWidth / 2. / tileSizeInPixels; |
| | 148 | double deltaY = screenHeight / 2. / tileSizeInPixels; |
| | 149 | Pair<Double, Double> center = getTileOfLatLon(lat, lon, zoom); |
| 145 | | new LatLon(lat - size/2, lon - size), |
| 146 | | new LatLon(lat + size/2, lon + size)); |
| | 151 | getLatLonOfTile(center.a - deltaX, center.b - deltaY, zoom), |
| | 152 | getLatLonOfTile(center.a + deltaX, center.b + deltaY, zoom)); |
| | 153 | } |
| | 154 | |
| | 155 | public static Pair<Double, Double> getTileOfLatLon(double lat, double lon, double zoom) { |
| | 156 | double x = Math.floor((lon + 180) / 360 * Math.pow(2.0, zoom)); |
| | 157 | double y = Math.floor((1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) |
| | 158 | / 2 * Math.pow(2.0, zoom)); |
| | 159 | return new Pair<Double, Double>(x, y); |
| | 160 | } |
| | 161 | |
| | 162 | public static LatLon getLatLonOfTile(double x, double y, double zoom) { |
| | 163 | double lon = x / Math.pow(2.0, zoom) * 360.0 - 180; |
| | 164 | double lat = Math.toDegrees(Math.atan(Math.sinh(Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, zoom)))); |
| | 165 | return new LatLon(lat, lon); |