source: josm/trunk/src/org/openstreetmap/josm/gui/MapSlider.java@ 1724

Last change on this file since 1724 was 1722, checked in by stoecker, 15 years ago

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.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.beans.PropertyChangeEvent;
5import java.beans.PropertyChangeListener;
6
7import javax.swing.JSlider;
8import javax.swing.event.ChangeEvent;
9import javax.swing.event.ChangeListener;
10
11import org.openstreetmap.josm.actions.HelpAction.Helpful;
12import org.openstreetmap.josm.data.coor.EastNorth;
13import org.openstreetmap.josm.data.ProjectionBounds;
14import org.openstreetmap.josm.Main;
15
16class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful {
17
18 private final MapView mv;
19 boolean preventChange = false;
20
21 public MapSlider(MapView mv) {
22 super(35, 150);
23 setOpaque(false);
24 this.mv = mv;
25 mv.addPropertyChangeListener("scale", this);
26 addChangeListener(this);
27 }
28
29 public void propertyChange(PropertyChangeEvent evt) {
30 if (getModel().getValueIsAdjusting()) return;
31
32 ProjectionBounds world = Main.proj.getWorldBounds();
33 ProjectionBounds current = this.mv.getProjectionBounds();
34
35 double cur_e = current.max.east()-current.min.east();
36 double cur_n = current.max.north()-current.min.north();
37 double e = world.max.east()-world.min.east();
38 double n = world.max.north()-world.min.north();
39 int zoom = 0;
40
41 while(zoom <= 150) {
42 e /= 1.1;
43 n /= 1.1;
44 if(e < cur_e && n < cur_n)
45 break;
46 ++zoom;
47 }
48 preventChange=true;
49 setValue(zoom);
50 preventChange=false;
51 }
52
53 public void stateChanged(ChangeEvent e) {
54 if (preventChange) return;
55
56 ProjectionBounds world = Main.proj.getWorldBounds();
57 double fact = Math.pow(1.1, getValue());
58 double es = world.max.east()-world.min.east();
59 double n = world.max.north()-world.min.north();
60
61 this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
62 }
63
64 public String helpTopic() {
65 return "MapView/Slider";
66 }
67}
Note: See TracBrowser for help on using the repository browser.