Ignore:
Timestamp:
2011-02-01T01:49:32+01:00 (13 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?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.