 Timestamp:
 20111228T22:33:01+01:00 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r4706 r4736 8 8 import java.util.Map; 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.data.Bounds; 11 12 import org.openstreetmap.josm.data.coor.LatLon; … … 60 61 } 61 62 } catch (NumberFormatException x) { 63 x.printStackTrace(); 62 64 } catch (NullPointerException x) { 65 x.printStackTrace(); 63 66 } catch (ArrayIndexOutOfBoundsException x) { 67 x.printStackTrace(); 64 68 } 65 69 return b; … … 141 145 } 142 146 147 public static final double R = 6378137.0; 148 143 149 public static Bounds positionToBounds(final double lat, final double lon, final int zoom) { 144 150 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); 150 return new Bounds( 151 getLatLonOfTile(center.a  deltaX, center.b  deltaY, zoom), 152 getLatLonOfTile(center.a + deltaX, center.b + deltaY, zoom)); 151 int height = Toolkit.getDefaultToolkit().getScreenSize().height; 152 int width = Toolkit.getDefaultToolkit().getScreenSize().width; 153 if (Main.map != null && Main.map.mapView != null) { 154 height = Main.map.mapView.getHeight(); 155 width = Main.map.mapView.getWidth(); 156 } 157 double scale = (1 << zoom) * tileSizeInPixels / (2 * Math.PI * R); 158 double deltaX = width / 2.0 / scale; 159 double deltaY = height / 2.0 / scale; 160 double x = Math.toRadians(lon) * R; 161 double y = mercatorY(lat); 162 return new Bounds(invMercatorY(y  deltaY), Math.toDegrees(x  deltaX) / R, invMercatorY(y + deltaY), Math.toDegrees(x + deltaX) / R); 163 } 164 165 public static double mercatorY(double lat) { 166 return Math.log(Math.tan(Math.PI/4 + Math.toRadians(lat)/2)) * R; 167 } 168 169 public static double invMercatorY(double north) { 170 return Math.toDegrees(Math.atan(Math.sinh(north / R))); 153 171 } 154 172
Note: See TracChangeset
for help on using the changeset viewer.