Ticket #3016: wrong_deefault_zoom.patch

File wrong_deefault_zoom.patch, 13.1 KB (added by xeen, 16 years ago)

Adds a default zoom level method for each projection. The center is derived from the world bounds, this is why it doesn't (yet) work with Lambert projections. The comment says we do not handle handle coordinates outside the boundaries correctly, but doesn't go into further detail.

  • src/org/openstreetmap/josm/data/projection/UTM_20N_Guadeloupe_Fort_Marigot.java

     
    3535        return tr("UTM20N Guadeloupe Fort-Marigot 1949");
    3636    }
    3737
     38    public double getDefaultZoomInPPD() {
     39        // this will set the map scaler to about 1000 m
     40        return 10;
     41    }
     42
    3843}
  • src/org/openstreetmap/josm/data/projection/GaussLaborde_Reunion.java

     
    215215        return tr("Gauss-Laborde R\u00E9union 1947");
    216216    }
    217217
     218    public double getDefaultZoomInPPD() {
     219        // this will set the map scaler to about 1000 m
     220        return 10.02;
     221    }
     222
    218223}
  • src/org/openstreetmap/josm/data/projection/UTM_20N_Martinique_Fort_Desaix.java

     
    3434    @Override public String toString() {
    3535        return tr("UTM20N Martinique Fort Desaix 1952");
    3636    }
     37
     38    public double getDefaultZoomInPPD() {
     39        // this will set the map scaler to about 1000 m
     40        return 10.01;
     41    }
    3742}
  • src/org/openstreetmap/josm/data/projection/Epsg4326.java

     
    3737    public Bounds getWorldBoundsLatLon()
    3838    {
    3939        return new Bounds(
    40         new LatLon(-90.0, -180.0),
    41         new LatLon(90.0, 180.0));
     40                new LatLon(-90.0, -180.0),
     41                new LatLon(90.0, 180.0));
     42    }
     43
     44    public double getDefaultZoomInPPD() {
     45        // This will set the scale bar to about 100 km
     46        return 0.009;
    4247    }
    4348}
  • src/org/openstreetmap/josm/data/projection/UTM.java

     
    341341    /* TODO - support all UTM's not only zone 33 */
    342342    public int getzone()
    343343    {
    344       return 33;
     344        return 33;
    345345    }
    346346
    347347    public String toCode() {
     
    355355    public Bounds getWorldBoundsLatLon()
    356356    {
    357357        return new Bounds(
    358         new LatLon(-85.0, UTMCentralMeridianDeg(getzone())-5.0),
    359         new LatLon(85.0, UTMCentralMeridianDeg(getzone())+5.0));
     358                new LatLon(-85.0, UTMCentralMeridianDeg(getzone())-5.0),
     359                new LatLon(85.0, UTMCentralMeridianDeg(getzone())+5.0));
     360    }
     361
     362    public double getDefaultZoomInPPD() {
     363        // this will set the map scaler to about 1000 m
     364        return 10;
    360365    }
    361366}
  • src/org/openstreetmap/josm/data/projection/UTM_20N_Guadeloupe_Ste_Anne.java

     
    3535        return tr("UTM20N Guadeloupe Ste-Anne 1948");
    3636    }
    3737
     38    public double getDefaultZoomInPPD() {
     39        // this will set the map scaler to about 1000 m
     40        return 10.01;
     41    }
     42
    3843}
  • src/org/openstreetmap/josm/data/projection/Lambert.java

     
    288288                new LatLon(45.0, -4.9074074074074059),
    289289                new LatLon(57.0, 10.2));*/
    290290    }
     291
     292    public double getDefaultZoomInPPD() {
     293        // TODO FIXME
     294        return 0;
     295    }
    291296}
  • src/org/openstreetmap/josm/data/projection/Mercator.java

     
    2323
    2424    public EastNorth latlon2eastNorth(LatLon p) {
    2525        return new EastNorth(
    26             p.lon()*Math.PI/180,
    27             Math.log(Math.tan(Math.PI/4+p.lat()*Math.PI/360)));
     26                p.lon()*Math.PI/180,
     27                Math.log(Math.tan(Math.PI/4+p.lat()*Math.PI/360)));
    2828    }
    2929
    3030    public LatLon eastNorth2latlon(EastNorth p) {
    3131        return new LatLon(
    32             Math.atan(Math.sinh(p.north()))*180/Math.PI,
    33             p.east()*180/Math.PI);
     32                Math.atan(Math.sinh(p.north()))*180/Math.PI,
     33                p.east()*180/Math.PI);
    3434    }
    3535
    3636    @Override public String toString() {
     
    4848    public Bounds getWorldBoundsLatLon()
    4949    {
    5050        return new Bounds(
    51         new LatLon(-85.05112877980659, -180.0),
    52         new LatLon(85.05112877980659, 180.0));
     51                new LatLon(-85.05112877980659, -180.0),
     52                new LatLon(85.05112877980659, 180.0));
     53    }
     54
     55    public double getDefaultZoomInPPD() {
     56        // This will set the scale bar to about 100 km
     57        return 0.000158;
    5358    }
    5459}
  • src/org/openstreetmap/josm/data/projection/LambertEST.java

     
    4747
    4848        double t = Math.tan(Math.PI / 4.0 - Math.toRadians(p.lat()) / 2.0)
    4949        / Math.pow(( (1.0 - ee * Math.sin(Math.toRadians(p.lat()))) / (1.0
    50         + ee * Math.sin(Math.toRadians(p.lat())))) ,(ee / 2.0));
     50                + ee * Math.sin(Math.toRadians(p.lat())))) ,(ee / 2.0));
    5151        double r = a * f * Math.pow(t, n);
    5252        double theta = n * (Math.toRadians(p.lon()) - lonf);
    5353
     
    6363        double a2 = 3.1415926535897931;
    6464        double a = 1.5707963267948966;
    6565        double b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
    66         - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
     66                - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
    6767        while (Math.abs(a-b) > epsilon)
    6868        {
    6969            a = a1 + ((a2 - a1) / 2.0);
    7070            b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
    71             - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
     71                    - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
    7272            if (a1 == a2)
    73             {
    7473                return 0.0;
    75             }
    76             if (b > a)
     74            if (b > a) {
    7775                a1 = a;
    78             else
     76            } else {
    7977                a2 = a;
     78            }
    8079        }
    8180        return b;
    8281    }
     
    8483    public LatLon eastNorth2latlon(EastNorth p)
    8584    {
    8685        double r = Math.sqrt(Math.pow((p.getX() - ef), 2.0) + Math.pow((rf
    87         - p.getY() + nf), 2.0) ) * Math.signum(n);
     86                - p.getY() + nf), 2.0) ) * Math.signum(n);
    8887        double T = Math.pow((r / (a * f)), (1.0/ n)) ;
    8988        double theta = Math.atan((p.getX() - ef) / (rf - p.getY() + nf));
    9089        double y = (theta / n + lonf) ;
     
    108107    public Bounds getWorldBoundsLatLon()
    109108    {
    110109        return new Bounds(
    111         new LatLon(-90.0, -180.0),
    112         new LatLon(90.0, 180.0));
     110                new LatLon(-90.0, -180.0),
     111                new LatLon(90.0, 180.0));
     112    }
     113
     114    public double getDefaultZoomInPPD() {
     115        // TODO FIXME
     116        return 0;
    113117    }
    114118}
  • src/org/openstreetmap/josm/data/projection/Projection.java

     
    2323    public static Projection[] allProjections = new Projection[]{
    2424        new Epsg4326(),
    2525        new Mercator(),
    26         new LambertEST(),
    27         new Lambert(),
     26        new LambertEST(), // Still needs proper default zoom
     27        new Lambert(),    // Still needs proper default zoom
    2828        new SwissGrid(),
    2929        new UTM(),
    3030        new UTM_20N_Guadeloupe_Ste_Anne(),
     
    3434    };
    3535
    3636    /**
     37     * Returns the default zoom scale in pixel per degree ({@see #NavigatableComponent#scale}))
     38     */
     39    double getDefaultZoomInPPD();
     40
     41    /**
    3742     * Convert from lat/lon to northing/easting.
    3843     *
    3944     * @param p     The geo point to convert. x/y members of the point are filled.
  • src/org/openstreetmap/josm/data/projection/SwissGrid.java

     
    101101    public Bounds getWorldBoundsLatLon()
    102102    {
    103103        return new Bounds(
    104         new LatLon(45.7, 5.7),
    105         new LatLon(47.9, 10.6));
     104                new LatLon(45.7, 5.7),
     105                new LatLon(47.9, 10.6));
     106    }
     107
     108    public double getDefaultZoomInPPD() {
     109        // This will set the scale bar to about 100 m
     110        return 1.01;
    106111    }
    107112}
  • src/org/openstreetmap/josm/gui/MapSlider.java

     
    2222        this.mv = mv;
    2323        mv.addPropertyChangeListener("scale", this);
    2424        addChangeListener(this);
     25        // Call this manually once so it gets setup correctly
     26        propertyChange(null);
    2527    }
    2628
    2729    public void propertyChange(PropertyChangeEvent evt) {
     
    3941        while(zoom <= 150) {
    4042            e /= 1.1;
    4143            n /= 1.1;
    42             if(e < cur_e && n < cur_n)
     44            if(e < cur_e && n < cur_n) {
    4345                break;
     46            }
    4447            ++zoom;
    4548        }
    4649        preventChange=true;
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

     
    4343     * every physical pixel on screen are 10 x or 10 y units in the
    4444     * northing/easting space of the projection.
    4545     */
    46     private double scale;
     46    private double scale = Main.proj.getDefaultZoomInPPD();
    4747    /**
    4848     * Center n/e coordinate of the desired screen center.
    4949     */
    50     protected EastNorth center = new EastNorth(0, 0);
     50    protected EastNorth center = calculateDefaultCenter();
    5151
    5252    public NavigatableComponent() {
    5353        setLayout(null);
     
    5757        return Main.main.getCurrentDataSet();
    5858    }
    5959
     60    private EastNorth calculateDefaultCenter() {
     61        Bounds b = Main.proj.getWorldBoundsLatLon();
     62        double lat = (b.max.lat() + b.min.lat())/2;
     63        double lon = (b.max.lon() + b.min.lon())/2;
     64
     65        return Main.proj.latlon2eastNorth(new LatLon(lat, lon));
     66    }
     67
    6068    /**
    6169     * Return a ID which is unique as long as viewport dimensions are the same
    6270     */
     
    114122                        new EastNorth(
    115123                                center.east() + getWidth()/2.0*scale,
    116124                                center.north() + getHeight()/2.0*scale));
    117     };
     125    }
    118126
    119127    /* FIXME: replace with better method - used by MapSlider */
    120128    public ProjectionBounds getMaxProjectionBounds() {
    121129        Bounds b = getProjection().getWorldBoundsLatLon();
    122130        return new ProjectionBounds(getProjection().latlon2eastNorth(b.min),
    123131                getProjection().latlon2eastNorth(b.max));
    124     };
     132    }
    125133
    126134    /* FIXME: replace with better method - used by Main to reset Bounds when projection changes, don't use otherwise */
    127135    public Bounds getRealBounds() {
     
    132140                        getProjection().eastNorth2latlon(new EastNorth(
    133141                                center.east() + getWidth()/2.0*scale,
    134142                                center.north() + getHeight()/2.0*scale)));
    135     };
     143    }
    136144
    137145    /**
    138146     * @param x X-Pixelposition to get coordinate from
     
    181189
    182190        Bounds b = getProjection().getWorldBoundsLatLon();
    183191        CachedLatLon cl = new CachedLatLon(newCenter);
    184         boolean changed = false;;
     192        boolean changed = false;
    185193        double lat = cl.lat();
    186194        double lon = cl.lon();
    187195        if(lat < b.min.lat()) {changed = true; lat = b.min.lat(); }