Changeset 1518 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-03-30T16:26:45+02:00 (16 years ago)
Author:
stoecker
Message:

fixed #2098 - different zoom steps on zooming in or out - patch by jttt

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapMover.java

    r1169 r1518  
    182182     */
    183183    public void mouseWheelMoved(MouseWheelEvent e) {
    184         int w = nc.getWidth();
    185         int h = nc.getHeight();
     184        double newScale = nc.getScale() * Math.pow(0.8, - e.getWheelRotation());
    186185
    187         double zoom = Math.max(0.1, 1 + e.getWheelRotation()/5.0);
    188         double zoomfactor = (zoom-1)/2+1;
    189 
    190         double newHalfWidth = w*zoomfactor - w/2;
    191         double newHalfHeight = h*zoomfactor - h/2;
    192         double centerx = e.getX() - (e.getX()-w/2)*newHalfWidth*2/w;
    193         double centery = e.getY() - (e.getY()-h/2)*newHalfHeight*2/h;
    194         EastNorth newCenter = nc.getEastNorth((int)centerx, (int)centery);
    195 
    196         nc.zoomTo(newCenter, nc.getScale()*zoom);
     186        // New center position so that point under the mouse pointer stays the same place as it was before zooming
     187        // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom
     188        double newX = nc.center.east() - (e.getX() - nc.getWidth()/2.0) * (newScale - nc.scale);
     189        double newY = nc.center.north() + (e.getY() - nc.getHeight()/2.0) * (newScale - nc.scale);
     190                     
     191        nc.zoomTo(new EastNorth(newX, newY), newScale);
    197192    }
    198193
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r1418 r1518  
    8989            @Override public void componentResized(ComponentEvent e) {
    9090                removeComponentListener(this);
     91               
     92                MapSlider zoomSlider = new MapSlider(MapView.this);
     93                add(zoomSlider);
     94                zoomSlider.setBounds(3, 0, 114, 30);
     95
     96                MapScaler scaler = new MapScaler(MapView.this, Main.proj);
     97                add(scaler);
     98                scaler.setLocation(10,30);
    9199
    92100                if (!zoomToEditLayerBoundingBox())
     
    115123                    Main.contentPane.getActionMap().put("RIGHT", mv);
    116124                }
    117 
    118                 MapSlider zoomSlider = new MapSlider(MapView.this);
    119                 add(zoomSlider);
    120                 zoomSlider.setBounds(3, 0, 114, 30);
    121 
    122                 MapScaler scaler = new MapScaler(MapView.this, Main.proj);
    123                 add(scaler);
    124                 scaler.setLocation(10,30);
    125125            }
    126126        });
Note: See TracChangeset for help on using the changeset viewer.