Changeset 3837 in josm


Ignore:
Timestamp:
2011-02-01T01:49:32+01:00 (10 years ago)
Author:
framm
Message:

new viewport following function; moves the viewport so that the last placed
node is in the center. the idea is to greatly improve tracing of long, linear
features from imagery or tracks (no need to right-click and pan all the time),
however the execution still leaves to be desired; problem is that after you
have placed a node you have to wait for the movement to finish before you can
place the next node. possible enhancements: only scroll if placed node is on
the outer rim of viewport?

Location:
trunk
Files:
2 added
5 edited

Legend:

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

    r3416 r3837  
    559559        getCurrentDataSet().setSelected(newSelection);
    560560
     561        // "viewport following" mode for tracing long features
     562        // from aerial imagery or GPS tracks.
     563        if (n != null && Main.map.mapView.viewportFollowing) {
     564            Main.map.mapView.smoothScrollTo(n.getEastNorth());
     565        };
    561566        computeHelperLine();
    562567        removeHighlighting();
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r1724 r3837  
    3434    public EastNorth getCenter(EastNorth en2) {
    3535        return new EastNorth((this.x + en2.x)/2.0, (this.y + en2.y)/2.0);
     36    }
     37
     38    public double distance(EastNorth en2) {
     39        return Math.sqrt((this.x-en2.x)*(this.x-en2.x) + (this.y-en2.y)*(this.y-en2.y));
    3640    }
    3741
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r3737 r3837  
    7474import org.openstreetmap.josm.actions.UploadAction;
    7575import org.openstreetmap.josm.actions.UploadSelectionAction;
     76import org.openstreetmap.josm.actions.ViewportFollowToggleAction;
    7677import org.openstreetmap.josm.actions.WireframeToggleAction;
    7778import org.openstreetmap.josm.actions.ZoomInAction;
     
    286287        }
    287288
     289        // -- viewport follow toggle action
     290        ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
     291        final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
     292        viewMenu.add(vft);
     293        vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
     294        viewportFollowToggleAction.addButtonModel(vft.getModel());
     295
    288296        // -- changeset manager toggle action
    289297        ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r3705 r3837  
    8282    }
    8383
     84    public boolean viewportFollowing = false;
     85
    8486    /**
    8587     * the layer listeners
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r3652 r3837  
    2323
    2424import javax.swing.JComponent;
     25import javax.swing.SwingUtilities;
    2526
    2627import org.openstreetmap.josm.Main;
     
    356357    }
    357358
     359    public void smoothScrollTo(LatLon newCenter) {
     360        if (newCenter instanceof CachedLatLon) {
     361            smoothScrollTo(((CachedLatLon)newCenter).getEastNorth());
     362        } else {
     363            smoothScrollTo(getProjection().latlon2eastNorth(newCenter));
     364        }
     365    }
     366
     367    /**
     368     * Create a thread that moves the viewport to the given center in an
     369     * animated fashion.
     370     */
     371    public void smoothScrollTo(EastNorth newCenter) {
     372        // fixme make these configurable.
     373        final int fps = 20;     // animation frames per second
     374        final int speed = 1500; // milliseconds for full-screen-width pan
     375        if (!newCenter.equals(center)) {
     376            final EastNorth oldCenter = center;
     377            final double distance = newCenter.distance(oldCenter) / scale;
     378            final double milliseconds = distance / getWidth() * speed;
     379            final double frames = milliseconds * fps / 1000;
     380            final EastNorth finalNewCenter = newCenter;
     381
     382            // we attempt to smooth-scroll at 10 fps, and use 2 seconds to scroll one
     383            // screen width.
     384
     385            new Thread(
     386                new Runnable() {
     387                    public void run() {
     388                        for (int i=0; i<frames; i++)
     389                        {
     390                            // fixme - not use zoom history here
     391                            zoomTo(oldCenter.interpolate(finalNewCenter, (double) (i+1) / (double) frames));
     392                            try { Thread.sleep(1000 / fps); } catch (InterruptedException ex) { };
     393                        }
     394                    }
     395                }
     396            ).start();
     397        }
     398    }
     399
    358400    public void zoomToFactor(double x, double y, double factor) {
    359401        double newScale = scale*factor;
Note: See TracChangeset for help on using the changeset viewer.