Ignore:
Timestamp:
2016-11-23T23:39:44+01:00 (7 years ago)
Author:
simon04
Message:

Use Projection inside OsmUrlToBounds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r9576 r11299  
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.data.Bounds;
     12import org.openstreetmap.josm.data.coor.EastNorth;
    1213import org.openstreetmap.josm.data.coor.LatLon;
    1314import org.openstreetmap.josm.data.projection.Ellipsoid;
     15import org.openstreetmap.josm.data.projection.Projection;
     16import org.openstreetmap.josm.data.projection.Projections;
    1417import org.openstreetmap.josm.gui.util.GuiHelper;
    1518
     
    3336        if (b != null)
    3437            return b;
    35         int i = url.indexOf("#map");
    36         if (i >= 0) {
     38        if (url.contains("#map")) {
    3739            // probably it's a URL following the new scheme?
    3840            return parseHashURLs(url);
    3941        }
    40         i = url.indexOf('?');
     42        final int i = url.indexOf('?');
    4143        if (i == -1) {
    4244            return null;
     
    201203        double deltaX = width / 2.0 / scale;
    202204        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));
    205207        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)));
    216210    }
    217211
Note: See TracChangeset for help on using the changeset viewer.