Ignore:
Timestamp:
2015-12-14T14:14:23+01:00 (4 years ago)
Author:
bastiK
Message:

more stable zoom&move for extreme scales and unusual world bounds

Location:
trunk/src/org/openstreetmap/josm/data/projection
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java

    r9105 r9118  
    22package org.openstreetmap.josm.data.projection;
    33
     4import org.openstreetmap.josm.data.Bounds;
     5import org.openstreetmap.josm.data.ProjectionBounds;
    46import org.openstreetmap.josm.data.coor.EastNorth;
    57import org.openstreetmap.josm.data.coor.LatLon;
     
    3133    protected double pm;       /* prime meridian */
    3234    protected double k0 = 1.0; /* general scale factor */
     35
     36    private volatile ProjectionBounds projectionBoundsBox;
    3337
    3438    public final Ellipsoid getEllipsoid() {
     
    105109        return degree + (minute/60.0) + (second/3600.0);
    106110    }
     111
     112    @Override
     113    public final ProjectionBounds getWorldBoundsBoxEastNorth() {
     114        ProjectionBounds result = projectionBoundsBox;
     115        if (result == null) {
     116            synchronized (this) {
     117                result = projectionBoundsBox;
     118                if (result == null) {
     119                    Bounds b = getWorldBoundsLatLon();
     120                    // add 4 corners
     121                    result = new ProjectionBounds(latlon2eastNorth(b.getMin()));
     122                    result.extend(latlon2eastNorth(b.getMax()));
     123                    result.extend(latlon2eastNorth(new LatLon(b.getMinLat(), b.getMaxLon())));
     124                    result.extend(latlon2eastNorth(new LatLon(b.getMaxLat(), b.getMinLon())));
     125                    // and trace along the outline
     126                    double dLon = (b.getMaxLon() - b.getMinLon()) / 1000;
     127                    double dLat = (b.getMaxLat() - b.getMinLat()) / 1000;
     128                    for (double lon=b.getMinLon(); lon<b.getMaxLon(); lon += dLon) {
     129                        result.extend(latlon2eastNorth(new LatLon(b.getMinLat(), lon)));
     130                        result.extend(latlon2eastNorth(new LatLon(b.getMaxLat(), lon)));
     131                    }
     132                    for (double lat=b.getMinLat(); lat<b.getMaxLat(); lat += dLat) {
     133                        result.extend(latlon2eastNorth(new LatLon(lat, b.getMinLon())));
     134                        result.extend(latlon2eastNorth(new LatLon(lat, b.getMaxLat())));
     135                    }
     136                    projectionBoundsBox = result;
     137                }
     138            }
     139        }
     140        return projectionBoundsBox;
     141    }
    107142}
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r8584 r9118  
    33
    44import org.openstreetmap.josm.data.Bounds;
     5import org.openstreetmap.josm.data.ProjectionBounds;
    56import org.openstreetmap.josm.data.coor.EastNorth;
    67import org.openstreetmap.josm.data.coor.LatLon;
     
    7071
    7172    /**
     73     * Get an approximate EastNorth box around the lat/lon world bounds.
     74     *
     75     * Note: The projection is only valid within the bounds returned by
     76     * {@link #getWorldBoundsLatLon()}. The lat/lon bounds need not be a
     77     * rectangular shape in east/north space. This method returns a box that
     78     * contains this shape.
     79     *
     80     * @return EastNorth box around the lat/lon world bounds
     81     */
     82    ProjectionBounds getWorldBoundsBoxEastNorth();
     83
     84    /**
    7285     * Get the number of meters per unit of this projection. This more
    7386     * defines the scale of the map, than real conversion of unit to meters
Note: See TracChangeset for help on using the changeset viewer.