Changeset 1823 in josm


Ignore:
Timestamp:
Jul 22, 2009 8:33:41 PM (4 years ago)
Author:
stoecker
Message:

some projection and zoom cleanups - projection classes still need better handling of outside-world coordinates

Location:
trunk/src/org/openstreetmap/josm
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r1821 r1823  
    628628     */ 
    629629    private void computeHelperLine() { 
     630        MapView mv = Main.map.mapView; 
    630631        if (mousePos == null) { 
    631632            // Don't draw the line. 
     
    651652 
    652653        if (!ctrl && mousePos != null) { 
    653             currentMouseNode = Main.map.mapView.getNearestNode(mousePos); 
     654            currentMouseNode = mv.getNearestNode(mousePos); 
    654655        } 
    655656 
     
    657658        // *and* there is no node nearby (because nodes beat ways when re-using) 
    658659        if(!ctrl && currentMouseNode == null) { 
    659             List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(mousePos); 
     660            List<WaySegment> wss = mv.getNearestWaySegments(mousePos); 
    660661            for(WaySegment ws : wss) { 
    661662                mouseOnExistingWays.add(ws.way); 
     
    670671        } else { 
    671672            // no node found in clicked area 
    672             currentMouseEastNorth = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y); 
     673            currentMouseEastNorth = mv.getEastNorth(mousePos.x, mousePos.y); 
    673674        } 
    674675 
     
    708709 
    709710        // find out the distance, in metres, between the base point and the mouse cursor 
    710         LatLon mouseLatLon = Main.proj.eastNorth2latlon(currentMouseEastNorth); 
     711        LatLon mouseLatLon = mv.getProjection().eastNorth2latlon(currentMouseEastNorth); 
    711712        distance = currentBaseNode.getCoor().greatCircleDistance(mouseLatLon); 
    712713        double hdg = Math.toDegrees(currentBaseNode.getCoor().heading(mouseLatLon)); 
  • trunk/src/org/openstreetmap/josm/data/projection/Epsg4326.java

    r1805 r1823  
    3636    } 
    3737 
    38     public ProjectionBounds getWorldBounds() 
    39     { 
    40         Bounds b = getWorldBoundsLatLon(); 
    41         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    42     } 
    43  
    4438    public Bounds getWorldBoundsLatLon() 
    4539    { 
  • trunk/src/org/openstreetmap/josm/data/projection/Lambert.java

    r1724 r1823  
    277277    } 
    278278 
    279     public ProjectionBounds getWorldBounds() 
    280     { 
    281         Bounds b = getWorldBoundsLatLon(); 
    282         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    283     } 
    284  
    285279    public Bounds getWorldBoundsLatLon() 
    286280    { 
  • trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java

    r1724 r1823  
    107107    } 
    108108 
    109     public ProjectionBounds getWorldBounds() 
    110     { 
    111         Bounds b = getWorldBoundsLatLon(); 
    112         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    113     } 
    114  
    115109    public Bounds getWorldBoundsLatLon() 
    116110    { 
  • trunk/src/org/openstreetmap/josm/data/projection/Mercator.java

    r1724 r1823  
    4747    } 
    4848 
    49     public ProjectionBounds getWorldBounds() 
    50     { 
    51         Bounds b = getWorldBoundsLatLon(); 
    52         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    53     } 
    54  
    5549    public Bounds getWorldBoundsLatLon() 
    5650    { 
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r1722 r1823  
    6363     * Get the bounds of the world 
    6464     */ 
    65     ProjectionBounds getWorldBounds(); 
    6665    Bounds getWorldBoundsLatLon(); 
    6766} 
  • trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java

    r1724 r1823  
    101101    } 
    102102 
    103     public ProjectionBounds getWorldBounds() 
    104     { 
    105         Bounds b = getWorldBoundsLatLon(); 
    106         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    107     } 
    108  
    109103    public Bounds getWorldBoundsLatLon() 
    110104    { 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r1743 r1823  
    354354    } 
    355355 
    356     public ProjectionBounds getWorldBounds() 
    357     { 
    358         Bounds b = getWorldBoundsLatLon(); 
    359         return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 
    360     } 
    361  
    362356    public Bounds getWorldBoundsLatLon() 
    363357    { 
  • trunk/src/org/openstreetmap/josm/gui/MapSlider.java

    r1722 r1823  
    3030        if (getModel().getValueIsAdjusting()) return; 
    3131 
    32         ProjectionBounds world = Main.proj.getWorldBounds(); 
     32        ProjectionBounds world = this.mv.getMaxProjectionBounds(); 
    3333        ProjectionBounds current = this.mv.getProjectionBounds(); 
    3434 
     
    5454        if (preventChange) return; 
    5555 
    56         ProjectionBounds world = Main.proj.getWorldBounds(); 
     56        ProjectionBounds world = this.mv.getMaxProjectionBounds(); 
    5757        double fact = Math.pow(1.1, getValue()); 
    5858        double es = world.max.east()-world.min.east(); 
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r1820 r1823  
    1313import java.awt.event.MouseEvent; 
    1414import java.awt.event.MouseMotionListener; 
     15import java.awt.geom.GeneralPath; 
    1516import java.awt.image.BufferedImage; 
    1617import java.util.ArrayList; 
     
    2930import org.openstreetmap.josm.actions.MoveAction; 
    3031import org.openstreetmap.josm.actions.mapmode.MapMode; 
     32import org.openstreetmap.josm.data.Bounds; 
    3133import org.openstreetmap.josm.data.ProjectionBounds; 
    3234import org.openstreetmap.josm.data.SelectionChangedListener; 
     
    3537import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    3638import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 
     39import org.openstreetmap.josm.data.coor.LatLon; 
    3740import org.openstreetmap.josm.gui.layer.Layer; 
    3841import org.openstreetmap.josm.gui.layer.MapViewPaintable; 
     
    295298        // draw world borders 
    296299        tempG.setColor(Color.WHITE); 
    297         ProjectionBounds b = getProjection().getWorldBounds(); 
    298         Point min = getPoint(b.min); 
    299         Point max = getPoint(b.max); 
    300         int x1 = Math.min(min.x, max.x); 
    301         int y1 = Math.min(min.y, max.y); 
    302         int x2 = Math.max(min.x, max.x); 
    303         int y2 = Math.max(min.y, max.y); 
    304         if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) { 
    305             tempG.drawRect(x1, y1, x2-x1+1, y2-y1+1); 
     300        GeneralPath path = new GeneralPath(); 
     301        Bounds b = getProjection().getWorldBoundsLatLon(); 
     302        double lat = b.min.lat(); 
     303        double lon = b.min.lon(); 
     304 
     305        Point p = getPoint(b.min); 
     306        path.moveTo(p.x, p.y); 
     307 
     308        double max = b.max.lat(); 
     309        for(; lat <= max; lat += 1.0) 
     310        { 
     311            p = getPoint(new LatLon(lat >= max ? max : lat, lon)); 
     312            path.lineTo(p.x, p.y); 
     313        } 
     314        lat = max; max = b.max.lon(); 
     315        for(; lon <= max; lon += 1.0) 
     316        { 
     317            p = getPoint(new LatLon(lat, lon >= max ? max : lon)); 
     318            path.lineTo(p.x, p.y); 
     319        } 
     320        lon = max; max = b.min.lat(); 
     321        for(; lat >= max; lat -= 1.0) 
     322        { 
     323            p = getPoint(new LatLon(lat <= max ? max : lat, lon)); 
     324            path.lineTo(p.x, p.y); 
     325        } 
     326        lat = max; max = b.min.lon(); 
     327        for(; lon >= max; lon -= 1.0) 
     328        { 
     329            p = getPoint(new LatLon(lat, lon <= max ? max : lon)); 
     330            path.lineTo(p.x, p.y); 
    306331        } 
    307332 
     
    309334            playHeadMarker.paint(tempG, this); 
    310335        } 
     336        tempG.draw(path); 
    311337 
    312338        g.drawImage(offscreenBuffer, 0, 0, null); 
     
    322348        } 
    323349        if (box.getBounds() == null) { 
    324             box.visit(getProjection().getWorldBounds()); 
     350            box.visit(getProjection().getWorldBoundsLatLon()); 
    325351        } 
    326352        if (!box.hasExtend()) { 
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r1814 r1823  
    7272    public double getDist100Pixel() 
    7373    { 
    74         LatLon ll1 = getLatLon(0,0); 
    75         LatLon ll2 = getLatLon(100,0); 
     74        int w = getWidth()/2; 
     75        int h = getHeight()/2; 
     76        LatLon ll1 = getLatLon(w-50,h); 
     77        LatLon ll2 = getLatLon(w+50,h); 
    7678        return ll1.greatCircleDistance(ll2); 
    7779    } 
     
    103105                        center.east() - getWidth()/2.0*scale, 
    104106                        center.north() - getHeight()/2.0*scale), 
    105                         new EastNorth( 
    106                                 center.east() + getWidth()/2.0*scale, 
    107                                 center.north() + getHeight()/2.0*scale)); 
     107                new EastNorth( 
     108                        center.east() + getWidth()/2.0*scale, 
     109                        center.north() + getHeight()/2.0*scale)); 
    108110    }; 
    109111 
     112    /* FIXME: replace with better method - used by MapSlider */ 
     113    public ProjectionBounds getMaxProjectionBounds() { 
     114        Bounds b = getProjection().getWorldBoundsLatLon(); 
     115        return new ProjectionBounds(getProjection().latlon2eastNorth(b.min), 
     116            getProjection().latlon2eastNorth(b.max)); 
     117    }; 
     118 
     119    /* FIXME: replace with better method - used by Main to reset Bounds when projection changes, don't use otherwise */ 
    110120    public Bounds getRealBounds() { 
    111121        return new Bounds( 
     
    113123                        center.east() - getWidth()/2.0*scale, 
    114124                        center.north() - getHeight()/2.0*scale)), 
    115                         getProjection().eastNorth2latlon(new EastNorth( 
    116                                 center.east() + getWidth()/2.0*scale, 
    117                                 center.north() + getHeight()/2.0*scale))); 
     125                getProjection().eastNorth2latlon(new EastNorth( 
     126                        center.east() + getWidth()/2.0*scale, 
     127                        center.north() + getHeight()/2.0*scale))); 
    118128    }; 
    119129 
     
    161171     */ 
    162172    private void zoomTo(EastNorth newCenter, double newScale) { 
    163         /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */ 
    164173        boolean rep = false; 
     174 
     175        Bounds b = getProjection().getWorldBoundsLatLon(); 
     176        CachedLatLon cl = new CachedLatLon(newCenter); 
     177        boolean changed = false;; 
     178        double lat = cl.lat(); 
     179        double lon = cl.lon(); 
     180        if(lat < b.min.lat()) {changed = true; lat = b.min.lat(); } 
     181        else if(lat > b.max.lat()) {changed = true; lat = b.max.lat(); } 
     182        if(lon < b.min.lon()) {changed = true; lon = b.min.lon(); } 
     183        else if(lon > b.max.lon()) {changed = true; lon = b.max.lon(); } 
     184        if(changed) 
     185          newCenter = new CachedLatLon(lat, lon).getEastNorth(); 
    165186        if (!newCenter.equals(center)) { 
    166187            EastNorth oldCenter = center; 
     
    169190            firePropertyChange("center", oldCenter, newCenter); 
    170191        } 
     192 
     193        int width = getWidth()/2; 
     194        int height = getHeight()/2; 
     195        LatLon l1 = new LatLon(b.min.lat(), lon); 
     196        LatLon l2 = new LatLon(b.max.lat(), lon); 
     197        EastNorth e1 = getProjection().latlon2eastNorth(l1); 
     198        EastNorth e2 = getProjection().latlon2eastNorth(l2); 
     199        double d = e2.north() - e1.north(); 
     200        if(d < height*newScale) 
     201        { 
     202            double newScaleH = d/height; 
     203            e1 = getProjection().latlon2eastNorth(new LatLon(lat, b.min.lon())); 
     204            e2 = getProjection().latlon2eastNorth(new LatLon(lat, b.max.lon())); 
     205            d = e2.east() - e1.east(); 
     206            if(d < width*newScale) 
     207                newScale = Math.max(newScaleH, d/width); 
     208        } 
     209        else 
     210        { 
     211            d = d/(l1.greatCircleDistance(l2)*height*10); 
     212            if(newScale < d) 
     213                newScale = d; 
     214        } 
    171215        if (scale != newScale) { 
    172216            double oldScale = scale; 
     
    175219            firePropertyChange("scale", oldScale, newScale); 
    176220        } 
     221 
    177222        if(rep) { 
    178223            repaint(); 
     
    461506     * @return The projection to be used in calculating stuff. 
    462507     */ 
    463     protected Projection getProjection() { 
     508    public Projection getProjection() { 
    464509        return Main.proj; 
    465510    } 
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1808 r1823  
    196196     */ 
    197197    @Override public void paint(final Graphics g, final MapView mv) { 
    198         boolean active = Main.map.mapView.getActiveLayer() == this; 
     198        boolean active = mv.getActiveLayer() == this; 
    199199        boolean inactive = !active && Main.pref.getBoolean("draw.data.inactive_color", true); 
    200         boolean virtual = !inactive && Main.map.mapView.isVirtualNodesEnabled(); 
     200        boolean virtual = !inactive && mv.isVirtualNodesEnabled(); 
    201201 
    202202        // draw the hatched area for non-downloaded region. only draw if we're the active 
     
    204204        if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data.dataSources.isEmpty()) { 
    205205            // initialize area with current viewport 
    206             Rectangle b = Main.map.mapView.getBounds(); 
     206            Rectangle b = mv.getBounds(); 
    207207            // on some platforms viewport bounds seem to be offset from the left, 
    208208            // over-grow it just to be sure 
     
    213213            for (DataSource src : data.dataSources) { 
    214214                if (src.bounds != null && !src.bounds.min.equals(src.bounds.max)) { 
    215                     EastNorth en1 = Main.proj.latlon2eastNorth(src.bounds.min); 
    216                     EastNorth en2 = Main.proj.latlon2eastNorth(src.bounds.max); 
     215                    EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.min); 
     216                    EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.max); 
    217217                    Point p1 = mv.getPoint(en1); 
    218218                    Point p2 = mv.getPoint(en2); 
     
    536536    /** 
    537537     * replies the set of conflicts currently managed in this layer 
    538      *  
     538     * 
    539539     * @return the set of conflicts currently managed in this layer 
    540540     */ 
Note: See TracChangeset for help on using the changeset viewer.