Ignore:
Timestamp:
2009-07-03T12:33:32+02:00 (16 years ago)
Author:
stoecker
Message:

Large rework in projection handling - now allows only switching and more specific projections
TODO:

  • allow subprojections (i.e. settings for projections)
  • setup preferences for subprojections
  • better support of the new projection depending world bounds (how to handle valid data outside of world)
  • do not allow to zoom out of the world - zoom should stop when whole world is displayed
  • fix Lambert and SwissGrid to handle new OutOfWorld style and subprojections
  • fix new UTM projection
  • handle layers with fixed projection on projection change
  • allow easier projection switching (e.g. in menu)

NOTE:
This checkin very likely will cause problems. Please report or fix them. Older plugins may have trouble. The SVN plugins
have been fixed but may have problems nevertheless. This is a BIG change, but will make JOSMs internal structure much cleaner
and reduce lots of projection related problems.

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r1690 r1722  
    88import org.openstreetmap.josm.data.coor.LatLon;
    99import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
     10import org.openstreetmap.josm.data.projection.Projection;
    1011import org.openstreetmap.josm.data.osm.visitor.Visitor;
     12import org.openstreetmap.josm.data.osm.Node;
    1113
    1214
     
    1820public final class Node extends OsmPrimitive {
    1921
    20     public LatLon coor;
    21     public volatile EastNorth eastNorth;
     22    private LatLon coor;
     23
     24    private EastNorth eastNorth;
     25    private Projection proj;
     26
    2227
    2328    public final void setCoor(LatLon coor) {
    2429        this.coor = coor;
    25         this.eastNorth = Main.proj.latlon2eastNorth(coor);
     30        proj = null;
    2631    }
    2732
     
    3136
    3237    public final void setEastNorth(EastNorth eastNorth) {
    33         this.eastNorth = eastNorth;
    34         this.coor = Main.proj.eastNorth2latlon(eastNorth);
    35     }
    36 
    37     public final void setEastNorth(double east, double north) {
    38         this.setEastNorth(new EastNorth(east, north));
     38        proj = Main.proj;
     39        eastNorth = eastNorth;
     40        this.coor = proj.eastNorth2latlon(eastNorth);
    3941    }
    4042
    4143    public final EastNorth getEastNorth() {
     44        if(proj != Main.proj)
     45        {
     46            proj = Main.proj;
     47            eastNorth = proj.latlon2eastNorth(coor);
     48        }
    4249        return eastNorth;
    4350    }
     
    4552    private static CoordinateFormat mCord;
    4653
    47     static {
     54    static public CoordinateFormat getCoordinateFormat()
     55    {
     56        return mCord;
     57    }
     58
     59    static public void setCoordinateFormat()
     60    {
    4861        try {
    4962            mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));
    5063        } catch (IllegalArgumentException iae) {
    51             mCord =LatLon.CoordinateFormat.DECIMAL_DEGREES;
     64            mCord = LatLon.CoordinateFormat.DECIMAL_DEGREES;
    5265        }
     66    }
     67
     68    static {
     69        setCoordinateFormat();
    5370    }
    5471
     
    7289    }
    7390
     91    public Node(EastNorth eastNorth) {
     92        setEastNorth(eastNorth);
     93    }
     94
    7495    @Override public void visit(Visitor visitor) {
    7596        visitor.visit(this);
     
    7899    @Override public void cloneFrom(OsmPrimitive osm) {
    79100        super.cloneFrom(osm);
    80         coor = ((Node)osm).coor;
    81         eastNorth = ((Node)osm).eastNorth;
     101        setCoor(((Node)osm).coor);
    82102    }
    83103
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r1640 r1722  
    44import org.openstreetmap.josm.Main;
    55import org.openstreetmap.josm.data.Bounds;
     6import org.openstreetmap.josm.data.ProjectionBounds;
    67import org.openstreetmap.josm.data.coor.EastNorth;
    78import org.openstreetmap.josm.data.coor.LatLon;
     
    1920public class BoundingXYVisitor extends AbstractVisitor {
    2021
    21     public EastNorth min, max;
     22    private ProjectionBounds bounds = null;
    2223
    2324    public void visit(Node n) {
     
    3839    }
    3940
     41    public void visit(Bounds b) {
     42        if(b != null)
     43        {
     44            visit(Main.proj.latlon2eastNorth(b.min));
     45            visit(Main.proj.latlon2eastNorth(b.max));
     46        }
     47    }
     48
     49    public void visit(ProjectionBounds b) {
     50        if(b != null)
     51            bounds = new ProjectionBounds(b.min, b.max);
     52    }
     53
    4054    public void visit(EastNorth eastNorth) {
    4155        if (eastNorth != null) {
    42             if (min == null)
    43                 min = eastNorth;
    44             else if (eastNorth.east() < min.east() || eastNorth.north() < min.north())
    45                 min = new EastNorth(Math.min(min.east(), eastNorth.east()), Math.min(min.north(), eastNorth.north()));
     56            if (bounds == null)
     57                bounds = new ProjectionBounds(eastNorth, eastNorth);
     58            else
     59                bounds.extend(eastNorth);
     60        }
     61    }
    4662
    47             if (max == null)
    48                 max = eastNorth;
    49             else if (eastNorth.east() > max.east() || eastNorth.north() > max.north())
    50                 max = new EastNorth(Math.max(max.east(), eastNorth.east()), Math.max(max.north(), eastNorth.north()));
    51         }
     63    public boolean hasExtend()
     64    {
     65        return bounds != null && !bounds.min.equals(bounds.max);
    5266    }
    5367
     
    5569     * @return The bounding box or <code>null</code> if no coordinates have passed
    5670     */
    57     public Bounds getBounds() {
    58         if (min == null || max == null)
    59             return null;
    60         return new Bounds(Main.proj.eastNorth2latlon(min), Main.proj.eastNorth2latlon(max));
     71    public ProjectionBounds getBounds() {
     72        return bounds;
    6173    }
    6274
     
    7890     */
    7991    public void enlargeBoundingBox(double enlargeDegree) {
    80         if (min == null || max == null)
     92        if (bounds == null)
    8193            return;
    82         LatLon minLatlon = Main.proj.eastNorth2latlon(min);
    83         min = Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree));
    84         LatLon maxLatlon = Main.proj.eastNorth2latlon(max);
    85         max = Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree));
     94        LatLon minLatlon = Main.proj.eastNorth2latlon(bounds.min);
     95        LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.max);
     96        bounds = new ProjectionBounds(
     97        Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)),
     98        Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree)));
    8699    }
    87100}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1696 r1722  
    12741274        useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false);
    12751275        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false);
    1276         circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; /* circumference of the earth in meter */
     1276        circum = Main.map.mapView.getMapScale();
    12771277        styles = MapPaintStyles.getStyles().getStyleSet();
    12781278        drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",true);
Note: See TracChangeset for help on using the changeset viewer.