Changeset 4706 in josm for trunk/src/org
 Timestamp:
 20111224T00:24:50+01:00 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r4298 r4706 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.Toolkit; 4 5 import java.io.UnsupportedEncodingException; 5 6 import java.net.URLDecoder; … … 141 142 142 143 public static Bounds positionToBounds(final double lat, final double lon, final int zoom) { 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); 144 150 return new Bounds( 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); 147 166 } 148 167
Note: See TracChangeset
for help on using the changeset viewer.