Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r9576 r11299 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.data.coor.EastNorth; 12 13 import org.openstreetmap.josm.data.coor.LatLon; 13 14 import org.openstreetmap.josm.data.projection.Ellipsoid; 15 import org.openstreetmap.josm.data.projection.Projection; 16 import org.openstreetmap.josm.data.projection.Projections; 14 17 import org.openstreetmap.josm.gui.util.GuiHelper; 15 18 … … 33 36 if (b != null) 34 37 return b; 35 int i = url.indexOf("#map"); 36 if (i >= 0) { 38 if (url.contains("#map")) { 37 39 // probably it's a URL following the new scheme? 38 40 return parseHashURLs(url); 39 41 } 40 i = url.indexOf('?');42 final int i = url.indexOf('?'); 41 43 if (i == -1) { 42 44 return null; … … 201 203 double deltaX = width / 2.0 / scale; 202 204 double deltaY = height / 2.0 / scale; 203 double x = Math.toRadians(lon) * Ellipsoid.WGS84.a;204 double y = mercatorY(lat);205 final Projection mercator = Projections.getProjectionByCode("EPSG:3857"); 206 final EastNorth projected = mercator.latlon2eastNorth(new LatLon(lat, lon)); 205 207 return new Bounds( 206 invMercatorY(y - deltaY), Math.toDegrees(x - deltaX) / Ellipsoid.WGS84.a, 207 invMercatorY(y + deltaY), Math.toDegrees(x + deltaX) / Ellipsoid.WGS84.a); 208 } 209 210 public static double mercatorY(double lat) { 211 return Math.log(Math.tan(Math.PI/4 + Math.toRadians(lat)/2)) * Ellipsoid.WGS84.a; 212 } 213 214 public static double invMercatorY(double north) { 215 return Math.toDegrees(Math.atan(Math.sinh(north / Ellipsoid.WGS84.a))); 208 mercator.eastNorth2latlon(projected.add(-deltaX, -deltaY)), 209 mercator.eastNorth2latlon(projected.add(deltaX, deltaY))); 216 210 } 217 211 -
trunk/test/unit/org/openstreetmap/josm/tools/OsmUrlToBoundsTest.java
r10626 r11299 3 3 4 4 import org.junit.Assert; 5 import org.junit.Rule; 5 6 import org.junit.Test; 6 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 8 12 9 13 /** … … 11 15 */ 12 16 public class OsmUrlToBoundsTest { 17 18 /** 19 * Setup test. 20 */ 21 @Rule 22 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules test = new JOSMTestRules(); 24 25 /** 26 * Test for {@link OsmUrlToBounds#positionToBounds}. 27 */ 28 @Test 29 public void testPositionToBounds() { 30 Assert.assertEquals(new Bounds(51.7123487,8.7552027,51.7251104,8.7680773), 31 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)); 32 Assert.assertEquals(new Bounds(40.8582551,-75.7534187,40.8660446,-75.7469813), 33 OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)); 34 } 35 13 36 /** 14 37 * data for {@link #testParse}
Note:
See TracChangeset
for help on using the changeset viewer.