Changeset 1722 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-03T12:33:32+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1681 r1722 250 250 } 251 251 }; 252 253 static public void setProjection(String name) 254 { 255 Bounds b = (map != null && map.mapView != null) ? map.mapView.getRealBounds() : null; 256 Projection oldProj = Main.proj; 257 try { 258 Main.proj = (Projection)Class.forName(name).newInstance(); 259 } catch (final Exception e) { 260 JOptionPane.showMessageDialog(null, tr("The projection {0} could not be activated. Using Mercator", name)); 261 Main.proj = new Mercator(); 262 } 263 if(!Main.proj.equals(oldProj)) 264 { 265 if(b != null) 266 map.mapView.zoomTo(b); 267 /* TODO - remove layers with fixed projection */ 268 } 269 } 270 252 271 /** 253 272 * Should be called before the main constructor to setup some parameter stuff … … 255 274 */ 256 275 public static void preConstructorInit(Map<String, Collection<String>> args) { 257 try { 258 Main.proj = (Projection)Class.forName(Main.pref.get("projection")).newInstance(); 259 } catch (final Exception e) { 260 e.printStackTrace(); 261 JOptionPane.showMessageDialog(null, tr("The projection could not be read from preferences. Using Mercator")); 262 Main.proj = new Mercator(); 263 } 276 setProjection(Main.pref.get("projection", Mercator.class.getName())); 264 277 265 278 try { -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r1639 r1722 55 55 } 56 56 57 double minEast = 200 .0;58 double maxEast = -200 .0;57 double minEast = 20000000000.0; 58 double maxEast = -20000000000.0; 59 59 for (Node n : nodes) { 60 minEast = Math.min(minEast, n.eastNorth.east()); 61 maxEast = Math.max(maxEast, n.eastNorth.east()); 60 double east = n.getEastNorth().east(); 61 minEast = Math.min(minEast, east); 62 maxEast = Math.max(maxEast, east); 62 63 } 63 64 double middle = (minEast + maxEast) / 2; … … 66 67 67 68 for (Node n : nodes) 68 cmds.add(new MoveCommand(n, 2 * (middle - n. eastNorth.east()), 0.0));69 cmds.add(new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0)); 69 70 70 71 Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds)); -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r1677 r1722 148 148 if(e.getSource() instanceof JPanel) { 149 149 MapView mv = Main.map.mapView; 150 n.set EastNorth(mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY()));150 n.setCoor(mv.getLatLon(mv.lastMEvent.getX(), mv.lastMEvent.getY())); 151 151 } 152 152 -
trunk/src/org/openstreetmap/josm/actions/ZoomInAction.java
r1218 r1722 20 20 public void actionPerformed(ActionEvent e) { 21 21 if (Main.map == null) return; 22 double zoom = Main.map.mapView.getScale(); 23 Main.map.mapView.zoomTo(Main.map.mapView.getCenter(), zoom * .9); 22 Main.map.mapView.zoomToFactor(0.9); 24 23 } 25 24 } -
trunk/src/org/openstreetmap/josm/actions/ZoomOutAction.java
r1218 r1722 20 20 public void actionPerformed(ActionEvent e) { 21 21 if (Main.map == null) return; 22 double zoom = Main.map.mapView.getScale(); 23 Main.map.mapView.zoomTo(Main.map.mapView.getCenter(), zoom /.9); 22 Main.map.mapView.zoomToFactor(1/0.9); 24 23 } 25 24 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1677 r1722 812 812 double c = A.distanceSq(B); 813 813 q = (a - b + c) / (2*c); 814 n.setEastNorth( B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()));814 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()))); 815 815 } 816 816 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r1195 r1722 57 57 */ 58 58 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) { 59 if (r.width >= 3 && r.height >= 3) { 60 double scale = mv.getScale() * r.getWidth()/mv.getWidth(); 61 EastNorth newCenter = mv.getEastNorth(r.x+r.width/2, r.y+r.height/2); 62 mv.zoomTo(newCenter, scale); 63 } 59 if (r.width >= 3 && r.height >= 3) 60 mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth()); 64 61 } 65 62 -
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r1640 r1722 48 48 public static class OldState { 49 49 LatLon latlon; 50 EastNorth eastNorth;51 50 boolean modified; 52 51 } … … 70 69 for (Node n : this.objects) { 71 70 OldState os = new OldState(); 72 os.eastNorth = n.getEastNorth();73 71 os.latlon = n.getCoor(); 74 72 os.modified = n.modified; … … 105 103 for (Node n : objects) { 106 104 OldState os = it.next(); 107 n.set EastNorth(os.eastNorth);105 n.setCoor(os.latlon); 108 106 n.modified = os.modified; 109 107 } -
trunk/src/org/openstreetmap/josm/command/RotateCommand.java
r1640 r1722 14 14 15 15 import org.openstreetmap.josm.data.coor.EastNorth; 16 import org.openstreetmap.josm.data.coor.LatLon; 16 17 import org.openstreetmap.josm.data.osm.Node; 17 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 37 38 38 39 /** 40 * Small helper for holding the interesting part of the old data state of the 41 * objects. 42 */ 43 public static class OldState { 44 LatLon latlon; 45 EastNorth eastNorth; 46 boolean modified; 47 } 48 49 /** 39 50 * angle of rotation starting click to pivot 40 51 */ … … 49 60 * List of all old states of the objects. 50 61 */ 51 private Map<Node, MoveCommand.OldState> oldState = new HashMap<Node, MoveCommand.OldState>();62 private Map<Node, OldState> oldState = new HashMap<Node, OldState>(); 52 63 53 64 /** … … 63 74 64 75 for (Node n : this.objects) { 65 MoveCommand.OldState os = new MoveCommand.OldState(); 76 OldState os = new OldState(); 77 os.latlon = n.getCoor(); 66 78 os.eastNorth = n.getEastNorth(); 67 os.latlon = n.getCoor();68 79 os.modified = n.modified; 69 80 oldState.put(n, os); … … 102 113 double nx = sinPhi * x + cosPhi * y + pivot.east(); 103 114 double ny = -cosPhi * x + sinPhi * y + pivot.north(); 104 n.setEastNorth(n x, ny);115 n.setEastNorth(new EastNorth(nx, ny)); 105 116 if (setModified) 106 117 n.modified = true; … … 115 126 @Override public void undoCommand() { 116 127 for (Node n : objects) { 117 MoveCommand.OldState os = oldState.get(n);118 n.set EastNorth(os.eastNorth);128 OldState os = oldState.get(n); 129 n.setCoor(os.latlon); 119 130 n.modified = os.modified; 120 131 } -
trunk/src/org/openstreetmap/josm/data/Bounds.java
r1169 r1722 25 25 this.min = min; 26 26 this.max = max; 27 }28 29 /**30 * Construct bounds that span the whole world.31 */32 public Bounds() {33 min = new LatLon(-Projection.MAX_LAT, -Projection.MAX_LON);34 max = new LatLon(Projection.MAX_LAT, Projection.MAX_LON);35 27 } 36 28 -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1688 r1722 352 352 put("selectionlist.visible", true); 353 353 put("commandstack.visible", true); 354 put("projection", Mercator.class.getName());355 354 if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") == -1) { 356 355 put("laf", "javax.swing.plaf.metal.MetalLookAndFeel"); -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r1209 r1722 7 7 import org.openstreetmap.josm.data.Bounds; 8 8 import org.openstreetmap.josm.data.projection.Projection; 9 import org.openstreetmap.josm.Main; 9 10 10 11 import java.text.DecimalFormat; … … 87 88 */ 88 89 public boolean isOutSideWorld() { 89 return lat() < -Projection.MAX_LAT || lat() > Projection.MAX_LAT || 90 lon() < -Projection.MAX_LON || lon() > Projection.MAX_LON; 90 Bounds b = Main.proj.getWorldBoundsLatLon(); 91 return lat() < b.min.lat() || lat() > b.max.lat() || 92 lon() < b.min.lon() || lon() > b.max.lon(); 91 93 } 92 94 -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r1677 r1722 40 40 public Collection<WayPoint> waypoints = new LinkedList<WayPoint>(); 41 41 42 public Bounds bounds;43 44 42 public void mergeFrom(GpxData other) { 45 43 if (storageFile == null && other.storageFile != null) { … … 82 80 83 81 // FIXME might perhaps use visitor pattern? 84 public voidrecalculateBounds() {85 bounds = null;82 public Bounds recalculateBounds() { 83 Bounds bounds = null; 86 84 for (WayPoint wpt : waypoints) { 87 85 if (bounds == null) { … … 111 109 } 112 110 } 113 if (bounds == null) { 114 bounds = new Bounds(); 115 } 111 return bounds; 116 112 } 117 113 -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1690 r1722 8 8 import org.openstreetmap.josm.data.coor.LatLon; 9 9 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 10 import org.openstreetmap.josm.data.projection.Projection; 10 11 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 import org.openstreetmap.josm.data.osm.Node; 11 13 12 14 … … 18 20 public final class Node extends OsmPrimitive { 19 21 20 public LatLon coor; 21 public volatile EastNorth eastNorth; 22 private LatLon coor; 23 24 private EastNorth eastNorth; 25 private Projection proj; 26 22 27 23 28 public final void setCoor(LatLon coor) { 24 29 this.coor = coor; 25 this.eastNorth = Main.proj.latlon2eastNorth(coor);30 proj = null; 26 31 } 27 32 … … 31 36 32 37 public final void setEastNorth(EastNorth eastNorth) { 33 this.eastNorth = eastNorth; 34 this.coor = Main.proj.eastNorth2latlon(eastNorth); 35 } 36 37 public final void setEastNorth(double east, double north) { 38 this.setEastNorth(new EastNorth(east, north)); 38 proj = Main.proj; 39 eastNorth = eastNorth; 40 this.coor = proj.eastNorth2latlon(eastNorth); 39 41 } 40 42 41 43 public final EastNorth getEastNorth() { 44 if(proj != Main.proj) 45 { 46 proj = Main.proj; 47 eastNorth = proj.latlon2eastNorth(coor); 48 } 42 49 return eastNorth; 43 50 } … … 45 52 private static CoordinateFormat mCord; 46 53 47 static { 54 static public CoordinateFormat getCoordinateFormat() 55 { 56 return mCord; 57 } 58 59 static public void setCoordinateFormat() 60 { 48 61 try { 49 62 mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates")); 50 63 } catch (IllegalArgumentException iae) { 51 mCord = LatLon.CoordinateFormat.DECIMAL_DEGREES;64 mCord = LatLon.CoordinateFormat.DECIMAL_DEGREES; 52 65 } 66 } 67 68 static { 69 setCoordinateFormat(); 53 70 } 54 71 … … 72 89 } 73 90 91 public Node(EastNorth eastNorth) { 92 setEastNorth(eastNorth); 93 } 94 74 95 @Override public void visit(Visitor visitor) { 75 96 visitor.visit(this); … … 78 99 @Override public void cloneFrom(OsmPrimitive osm) { 79 100 super.cloneFrom(osm); 80 coor = ((Node)osm).coor; 81 eastNorth = ((Node)osm).eastNorth; 101 setCoor(((Node)osm).coor); 82 102 } 83 103 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r1640 r1722 4 4 import org.openstreetmap.josm.Main; 5 5 import org.openstreetmap.josm.data.Bounds; 6 import org.openstreetmap.josm.data.ProjectionBounds; 6 7 import org.openstreetmap.josm.data.coor.EastNorth; 7 8 import org.openstreetmap.josm.data.coor.LatLon; … … 19 20 public class BoundingXYVisitor extends AbstractVisitor { 20 21 21 p ublic EastNorth min, max;22 private ProjectionBounds bounds = null; 22 23 23 24 public void visit(Node n) { … … 38 39 } 39 40 41 public void visit(Bounds b) { 42 if(b != null) 43 { 44 visit(Main.proj.latlon2eastNorth(b.min)); 45 visit(Main.proj.latlon2eastNorth(b.max)); 46 } 47 } 48 49 public void visit(ProjectionBounds b) { 50 if(b != null) 51 bounds = new ProjectionBounds(b.min, b.max); 52 } 53 40 54 public void visit(EastNorth eastNorth) { 41 55 if (eastNorth != null) { 42 if (min == null) 43 min = eastNorth; 44 else if (eastNorth.east() < min.east() || eastNorth.north() < min.north()) 45 min = new EastNorth(Math.min(min.east(), eastNorth.east()), Math.min(min.north(), eastNorth.north())); 56 if (bounds == null) 57 bounds = new ProjectionBounds(eastNorth, eastNorth); 58 else 59 bounds.extend(eastNorth); 60 } 61 } 46 62 47 if (max == null) 48 max = eastNorth; 49 else if (eastNorth.east() > max.east() || eastNorth.north() > max.north()) 50 max = new EastNorth(Math.max(max.east(), eastNorth.east()), Math.max(max.north(), eastNorth.north())); 51 } 63 public boolean hasExtend() 64 { 65 return bounds != null && !bounds.min.equals(bounds.max); 52 66 } 53 67 … … 55 69 * @return The bounding box or <code>null</code> if no coordinates have passed 56 70 */ 57 public Bounds getBounds() { 58 if (min == null || max == null) 59 return null; 60 return new Bounds(Main.proj.eastNorth2latlon(min), Main.proj.eastNorth2latlon(max)); 71 public ProjectionBounds getBounds() { 72 return bounds; 61 73 } 62 74 … … 78 90 */ 79 91 public void enlargeBoundingBox(double enlargeDegree) { 80 if ( min == null || max== null)92 if (bounds == null) 81 93 return; 82 LatLon minLatlon = Main.proj.eastNorth2latlon(min); 83 min = Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)); 84 LatLon maxLatlon = Main.proj.eastNorth2latlon(max); 85 max = Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree)); 94 LatLon minLatlon = Main.proj.eastNorth2latlon(bounds.min); 95 LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.max); 96 bounds = new ProjectionBounds( 97 Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)), 98 Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree))); 86 99 } 87 100 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r1696 r1722 1274 1274 useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false); 1275 1275 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false); 1276 circum = Main.map.mapView.get Scale()*100*Main.proj.scaleFactor()*40041455; /* circumference of the earth in meter */1276 circum = Main.map.mapView.getMapScale(); 1277 1277 styles = MapPaintStyles.getStyles().getStyleSet(); 1278 1278 drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",true); -
trunk/src/org/openstreetmap/josm/data/projection/Epsg4326.java
r1309 r1722 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import org.openstreetmap.josm.data.coor.LatLon; 5 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.data.ProjectionBounds; 6 10 7 11 /** … … 32 36 } 33 37 34 public double scaleFactor() {35 return 1.0/360;36 }37 38 38 @Override public boolean equals(Object o) { 39 39 return o instanceof Epsg4326; 40 40 } 41 41 42 @Override public int hashCode() { 43 return Epsg4326.class.hashCode(); 42 public ProjectionBounds getWorldBounds() 43 { 44 Bounds b = getWorldBoundsLatLon(); 45 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 46 } 47 48 public Bounds getWorldBoundsLatLon() 49 { 50 return new Bounds( 51 new LatLon(-90.0, -180.0), 52 new LatLon(90.0, 180.0)); 44 53 } 45 54 } -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r1583 r1722 12 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.Bounds; 15 import org.openstreetmap.josm.data.ProjectionBounds; 14 16 15 17 public class Lambert implements Projection { … … 104 106 } else { 105 107 outOfLambertZones = true; // possible when MAX_LAT is used 106 if (p.lat() != 0 && Math.abs(p.lat()) != Projection.MAX_LAT107 && p.lon() != 0 && Math.abs(p.lon()) != Projection.MAX_LON108 && dontDisplayErrors == false) {109 JOptionPane.showMessageDialog(Main.parent,110 tr("The projection \"{0}\" is designed for\n"111 + "latitudes between 46.1\u00b0 and 57\u00b0 only.\n"112 + "Use another projection system if you are not using\n"113 + "a French WMS server.\n"114 + "Do not upload any data after this message.", this.toString()));115 dontDisplayErrors = true;116 }117 108 } 118 109 if (!outOfLambertZones) { … … 167 158 } 168 159 169 public double scaleFactor() {170 return 1.0 / 360;171 }172 173 160 @Override 174 161 public boolean equals(Object o) { 175 162 return o instanceof Lambert; 176 }177 178 @Override179 public int hashCode() {180 return Lambert.class.hashCode();181 163 } 182 164 … … 300 282 } 301 283 284 public ProjectionBounds getWorldBounds() 285 { 286 Bounds b = getWorldBoundsLatLon(); 287 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 288 } 289 290 public Bounds getWorldBoundsLatLon() 291 { 292 return new Bounds( 293 new LatLon(-90.0, -180.0), 294 new LatLon(90.0, 180.0)); 295 } 302 296 } -
trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java
r1309 r1722 9 9 import org.openstreetmap.josm.data.coor.EastNorth; 10 10 import org.openstreetmap.josm.data.coor.LatLon; 11 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.data.ProjectionBounds; 11 13 12 14 public class LambertEST implements Projection { … … 105 107 } 106 108 107 public double scaleFactor() {108 return 1.0 / 360;109 }110 111 109 @Override 112 110 public boolean equals(Object o) { … … 114 112 } 115 113 116 @Override 117 public int hashCode() { 118 return LambertEST.class.hashCode(); 114 public ProjectionBounds getWorldBounds() 115 { 116 Bounds b = getWorldBoundsLatLon(); 117 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 118 } 119 120 public Bounds getWorldBoundsLatLon() 121 { 122 return new Bounds( 123 new LatLon(-90.0, -180.0), 124 new LatLon(90.0, 180.0)); 119 125 } 120 126 } -
trunk/src/org/openstreetmap/josm/data/projection/Mercator.java
r1644 r1722 6 6 import org.openstreetmap.josm.data.coor.EastNorth; 7 7 import org.openstreetmap.josm.data.coor.LatLon; 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.data.ProjectionBounds; 8 10 9 11 /** … … 45 47 } 46 48 47 public double scaleFactor() {48 return 1/Math.PI/2;49 }50 51 49 @Override public boolean equals(Object o) { 52 50 return o instanceof Mercator; 53 51 } 54 52 55 @Override public int hashCode() { 56 return Mercator.class.hashCode(); 53 public ProjectionBounds getWorldBounds() 54 { 55 Bounds b = getWorldBoundsLatLon(); 56 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 57 } 58 59 public Bounds getWorldBoundsLatLon() 60 { 61 return new Bounds( 62 new LatLon(-85.05112877980659, -180.0), 63 new LatLon(85.05112877980659, 180.0)); 57 64 } 58 65 } -
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r1582 r1722 4 4 import org.openstreetmap.josm.data.coor.EastNorth; 5 5 import org.openstreetmap.josm.data.coor.LatLon; 6 import org.openstreetmap.josm.data.Bounds; 7 import org.openstreetmap.josm.data.ProjectionBounds; 6 8 7 9 /** … … 12 14 */ 13 15 public interface Projection { 14 15 /**16 * Maximum latitude representable.17 */18 public static final double MAX_LAT = 85.05112877980659; // Mercator squares the world19 20 /**21 * Maximum longditude representable.22 */23 public static final double MAX_LON = 180;24 25 16 /** 26 17 * Minimum difference in location to not be represented as the same position. … … 36 27 new Lambert(), 37 28 new LambertEST(), 38 new SwissGrid() 29 new SwissGrid(), 30 new UTM() 39 31 }; 40 32 … … 69 61 70 62 /** 71 * The factor to multiply with an easting coordinate to get from "easting 72 * units per pixel" to "meters per pixel" 63 * Get the bounds of the world 73 64 */ 74 double scaleFactor(); 65 ProjectionBounds getWorldBounds(); 66 Bounds getWorldBoundsLatLon(); 75 67 } -
trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java
r1583 r1722 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import javax.swing.JOptionPane;8 9 7 import org.openstreetmap.josm.Main; 10 8 import org.openstreetmap.josm.data.coor.EastNorth; 11 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.Bounds; 11 import org.openstreetmap.josm.data.ProjectionBounds; 12 12 13 13 /** … … 19 19 */ 20 20 public class SwissGrid implements Projection { 21 private boolean doAlertOnCoordinatesOufOfRange = true;22 23 /**24 * replies true if if wgs is in or reasonably close to Switzerland. False otherwise.25 *26 * @param wgs lat/lon in WGS8927 * @return28 */29 protected boolean latlonInAcceptableRange(LatLon wgs) {30 // coordinate transformation is invoked for boundary values regardless31 // of current data set.32 //33 if (Math.abs(wgs.lon()) == Projection.MAX_LON && Math.abs(wgs.lat()) == Projection.MAX_LAT) {34 return true;35 }36 return wgs.lon() >= 5.7 && wgs.lon() <= 10.637 && wgs.lat() >= 45.7 && wgs.lat() <= 47.9;38 }39 40 /**41 * displays an alert if lat/lon are not reasonably close to Switzerland.42 */43 protected void alertCoordinatesOutOfRange() {44 JOptionPane.showMessageDialog(Main.parent,45 tr("The projection \"{0}\" is designed for\n"46 + "latitudes between 45.7\u00b0 and 47.9\u00b0\n"47 + "and longitutes between 5.7\u00b0 and 10.6\u00b0 only.\n"48 + "Use another projection system if you are not working\n"49 + "on a data set of Switzerland or Liechtenstein.\n"50 + "Do not upload any data after this message.", this.toString()),51 "Current projection not suitable",52 JOptionPane.WARNING_MESSAGE53 );54 doAlertOnCoordinatesOufOfRange = false;55 }56 57 21 /** 58 22 * @param wgs WGS84 lat/lon (ellipsoid GRS80) (in degree) … … 60 24 */ 61 25 public EastNorth latlon2eastNorth(LatLon wgs) { 62 if (!latlonInAcceptableRange(wgs)) {63 if (doAlertOnCoordinatesOufOfRange) {64 alertCoordinatesOutOfRange();65 }66 }67 68 26 double phi = 3600d * wgs.lat(); 69 27 double lambda = 3600d * wgs.lon(); … … 131 89 } 132 90 133 public double scaleFactor() {134 return 1.0;135 }136 137 91 @Override public String toString() { 138 92 return tr("Swiss Grid (Switzerland)"); … … 152 106 } 153 107 154 @Override 155 public int hashCode() { 156 return SwissGrid.class.hashCode(); 108 public ProjectionBounds getWorldBounds() 109 { 110 Bounds b = getWorldBoundsLatLon(); 111 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max)); 112 } 113 114 public Bounds getWorldBoundsLatLon() 115 { 116 return new Bounds( 117 new LatLon(45.7, 5.7), 118 new LatLon(47.9, 10.6)); 157 119 } 158 120 } -
trunk/src/org/openstreetmap/josm/gui/MapMover.java
r1677 r1722 44 44 EastNorth newcenter = nc.getEastNorth(nc.getWidth()/2+nc.getWidth()/5, nc.getHeight()/2+nc.getHeight()/5); 45 45 if (action.equals("left")) 46 nc.zoomTo(new EastNorth(2*center.east()-newcenter.east(), center.north()) , nc.getScale());46 nc.zoomTo(new EastNorth(2*center.east()-newcenter.east(), center.north())); 47 47 else if (action.equals("right")) 48 nc.zoomTo(new EastNorth(newcenter.east(), center.north()) , nc.getScale());48 nc.zoomTo(new EastNorth(newcenter.east(), center.north())); 49 49 else if (action.equals("up")) 50 nc.zoomTo(new EastNorth(center.east(), 2*center.north()-newcenter.north()) , nc.getScale());50 nc.zoomTo(new EastNorth(center.east(), 2*center.north()-newcenter.north())); 51 51 else if (action.equals("down")) 52 nc.zoomTo(new EastNorth(center.east(), newcenter.north()) , nc.getScale());52 nc.zoomTo(new EastNorth(center.east(), newcenter.north())); 53 53 } 54 54 } … … 123 123 EastNorth center = nc.getCenter(); 124 124 EastNorth mouseCenter = nc.getEastNorth(e.getX(), e.getY()); 125 EastNorth p =new EastNorth(125 nc.zoomTo(new EastNorth( 126 126 mousePosMove.east() + center.east() - mouseCenter.east(), 127 mousePosMove.north() + center.north() - mouseCenter.north()); 128 nc.zoomTo(p, nc.getScale()); 127 mousePosMove.north() + center.north() - mouseCenter.north())); 129 128 } else 130 129 endMovement(); … … 182 181 */ 183 182 public void mouseWheelMoved(MouseWheelEvent e) { 184 double newScale = nc.getScale() * Math.pow(0.8, - e.getWheelRotation()); 185 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); 183 nc.zoomToFactor(e.getX(), e.getY(), Math.pow(0.8, - e.getWheelRotation())); 192 184 } 193 185 -
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r1274 r1722 14 14 import org.openstreetmap.josm.actions.HelpAction.Helpful; 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.data.projection.Projection;17 16 18 17 public class MapScaler extends JComponent implements Helpful { 19 18 20 19 private final NavigatableComponent mv; 21 public MapScaler(NavigatableComponent mv , Projection proj) {20 public MapScaler(NavigatableComponent mv) { 22 21 this.mv = mv; 23 22 setSize(100,30); … … 26 25 27 26 @Override public void paint(Graphics g) { 28 LatLon ll1 = mv.getLatLon(0,0); 29 LatLon ll2 = mv.getLatLon(100,0); 30 double dist = ll1.greatCircleDistance(ll2); 27 double dist = mv.getDist100Pixel(); 31 28 String text = dist >= 2000 ? Math.round(dist/100)/10 +" km" : (dist >= 1 32 29 ? Math.round(dist*10)/10 +" m" : "< 1 m"); -
trunk/src/org/openstreetmap/josm/gui/MapSlider.java
r1677 r1722 11 11 import org.openstreetmap.josm.actions.HelpAction.Helpful; 12 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 import org.openstreetmap.josm.data.ProjectionBounds; 14 import org.openstreetmap.josm.Main; 13 15 14 16 class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful { … … 28 30 if (getModel().getValueIsAdjusting()) return; 29 31 30 double sizex = this.mv.scale * this.mv.getWidth(); 31 double sizey = this.mv.scale * this.mv.getHeight(); 32 for (int zoom = 0; zoom <= 150; zoom++, sizex *= 1.1, sizey *= 1.1) { 33 if (sizex > MapView.world.east() || sizey > MapView.world.north()) { 34 preventChange=true; 35 setValue(zoom); 36 preventChange=false; 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) 37 45 break; 38 }46 ++zoom; 39 47 } 48 preventChange=true; 49 setValue(zoom); 50 preventChange=false; 40 51 } 41 52 42 53 public void stateChanged(ChangeEvent e) { 43 54 if (preventChange) return; 44 EastNorth pos = MapView.world; 45 for (int zoom = 0; zoom < getValue(); zoom++)46 pos = new EastNorth(pos.east()/1.1, pos.north()/1.1);47 if (this.mv.getWidth() < this.mv.getHeight())48 this.mv.zoomTo(this.mv.center, pos.east()/(this.mv.getWidth()-20));49 else 50 this.mv.zoomTo(this.mv.center, pos.north()/(this.mv.getHeight()-20));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)); 51 62 } 52 63 -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r1677 r1722 38 38 import org.openstreetmap.josm.actions.HelpAction.Helpful; 39 39 import org.openstreetmap.josm.data.coor.LatLon; 40 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 40 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 41 42 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 43 import org.openstreetmap.josm.data.osm.Node; 42 44 import org.openstreetmap.josm.tools.GBC; 43 45 import org.openstreetmap.josm.tools.ImageProvider; … … 89 91 } 90 92 } 91 92 LatLon.CoordinateFormat mCord;93 93 94 94 ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11); … … 263 263 this.mv = mapFrame.mapView; 264 264 265 try {266 mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));267 } catch (IllegalArgumentException iae) {268 mCord =LatLon.CoordinateFormat.DECIMAL_DEGREES;269 }270 265 // Listen for mouse movements and set the position text field 271 266 mv.addMouseMotionListener(new MouseMotionListener(){ … … 278 273 // Do not update the view if ctrl is pressed. 279 274 if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == 0) { 275 CoordinateFormat mCord = Node.getCoordinateFormat(); 280 276 LatLon p = mv.getLatLon(e.getX(),e.getY()); 281 277 latText.setText(p.latToString(mCord)); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r1685 r1722 30 30 import org.openstreetmap.josm.actions.MoveAction; 31 31 import org.openstreetmap.josm.data.Bounds; 32 import org.openstreetmap.josm.data.ProjectionBounds; 32 33 import org.openstreetmap.josm.data.SelectionChangedListener; 33 34 import org.openstreetmap.josm.data.coor.EastNorth; … … 95 96 zoomSlider.setBounds(3, 0, 114, 30); 96 97 97 MapScaler scaler = new MapScaler(MapView.this , Main.proj);98 MapScaler scaler = new MapScaler(MapView.this); 98 99 add(scaler); 99 100 scaler.setLocation(10,30); … … 197 198 } 198 199 199 200 200 /** 201 201 * Remove the layer from the mapview. If the layer was in the list before, … … 289 289 // draw world borders 290 290 tempG.setColor(Color.WHITE); 291 Bounds b = newBounds();292 Point min = getPoint( getProjection().latlon2eastNorth(b.min));293 Point max = getPoint( getProjection().latlon2eastNorth(b.max));291 ProjectionBounds b = getProjection().getWorldBounds(); 292 Point min = getPoint(b.min); 293 Point max = getPoint(b.max); 294 294 int x1 = Math.min(min.x, max.x); 295 295 int y1 = Math.min(min.y, max.y); … … 307 307 308 308 /** 309 * Set the new dimension to the projection class. Also adjust the components 310 * scale, if in autoScale mode. 309 * Set the new dimension to the view. 311 310 */ 312 311 public void recalculateCenterScale(BoundingXYVisitor box) { 313 // -20 to leave some border 314 int w = getWidth()-20; 315 if (w < 20) 316 w = 20; 317 int h = getHeight()-20; 318 if (h < 20) 319 h = 20; 320 321 EastNorth oldCenter = center; 322 double oldScale = this.scale; 323 324 if (box == null || box.min == null || box.max == null) { 325 // no bounds means whole world 326 center = getProjection().latlon2eastNorth(new LatLon(0,0)); 327 EastNorth world = getProjection().latlon2eastNorth(new LatLon(Projection.MAX_LAT,Projection.MAX_LON)); 328 double scaleX = world.east()*2/w; 329 double scaleY = world.north()*2/h; 330 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 331 } else { 332 if(box.min.equals(box.max)) 333 box.enlargeBoundingBox(); 334 center = new EastNorth(box.min.east()/2+box.max.east()/2, box.min.north()/2+box.max.north()/2); 335 double scaleX = (box.max.east()-box.min.east())/w; 336 double scaleY = (box.max.north()-box.min.north())/h; 337 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 338 } 339 340 if (!center.equals(oldCenter)) 341 firePropertyChange("center", oldCenter, center); 342 if (oldScale != scale) 343 firePropertyChange("scale", oldScale, scale); 344 repaint(); 312 if(box == null) 313 box = new BoundingXYVisitor(); 314 if(box.getBounds() == null) 315 box.visit(getProjection().getWorldBounds()); 316 if(!box.hasExtend()) 317 box.enlargeBoundingBox(); 318 319 zoomTo(box.getBounds()); 345 320 } 346 321 … … 392 367 393 368 /** 394 * In addition to the base class funcitonality, this keep trak of the autoscale395 * feature.396 */397 @Override public void zoomTo(EastNorth newCenter, double scale) {398 EastNorth oldCenter = center;399 double oldScale = this.scale;400 super.zoomTo(newCenter, scale);401 if ((oldCenter == null && center != null) || !oldCenter.equals(center))402 firePropertyChange("center", oldCenter, center);403 if (oldScale != scale)404 firePropertyChange("scale", oldScale, scale);405 }406 407 /**408 369 * Tries to zoom to the download boundingbox[es] of the current edit layer 409 370 * (aka {@link OsmDataLayer}). If the edit layer has multiple download bounding … … 420 381 BoundingXYVisitor bbox = new BoundingXYVisitor(); 421 382 for (DataSource ds : dataSources) { 422 if (ds.bounds != null) { 423 bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.max)); 424 bbox.visit(Main.proj.latlon2eastNorth(ds.bounds.min)); 425 } 426 if (bbox.max != null && bbox.min != null && !bbox.max.equals(bbox.min)) { 383 bbox.visit(ds.bounds); 384 if (bbox.hasExtend()) { 427 385 // ... we zoom to it's bounding box 428 386 recalculateCenterScale(bbox); -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r1640 r1722 16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.actions.HelpAction.Helpful; 18 import org.openstreetmap.josm.data.Bounds; 19 import org.openstreetmap.josm.data.ProjectionBounds; 18 20 import org.openstreetmap.josm.data.coor.EastNorth; 19 21 import org.openstreetmap.josm.data.coor.LatLon; … … 24 26 import org.openstreetmap.josm.data.osm.WaySegment; 25 27 import org.openstreetmap.josm.data.projection.Projection; 28 import org.openstreetmap.josm.data.projection.Mercator; 26 29 27 30 /** … … 33 36 public class NavigatableComponent extends JComponent implements Helpful { 34 37 35 public static final EastNorth world = Main.proj.latlon2eastNorth(new LatLon(Projection.MAX_LAT, Projection.MAX_LON));36 38 public static final int snapDistance = sqr(Main.pref.getInteger("node.snap-distance", 10)); 37 39 … … 42 44 * northing/easting space of the projection. 43 45 */ 44 pr otecteddouble scale;46 private double scale; 45 47 /** 46 48 * Center n/e coordinate of the desired screen center. … … 58 60 59 61 /** 60 * Return the OSM-conform zoom factor (0 for whole world, 1 for half, 2 for quarter...)61 */62 public int zoom() {63 double sizex = scale * getWidth();64 double sizey = scale * getHeight();65 for (int zoom = 0; zoom <= 32; zoom++, sizex *= 2, sizey *= 2)66 if (sizex > world.east() || sizey > world.north())67 return zoom;68 return 32;69 }70 71 /**72 62 * Return a ID which is unique as long as viewport dimensions are the same 73 63 */ … … 75 65 { 76 66 String x = center.east() + "_" + center.north() + "_" + scale + "_" + 77 getWidth() + "_" + getHeight() ;67 getWidth() + "_" + getHeight() + "_" + getProjection().toString(); 78 68 java.util.zip.CRC32 id = new java.util.zip.CRC32(); 79 69 id.update(x.getBytes()); … … 81 71 } 82 72 83 /** 84 * Return the current scale value. 85 * @return The scale value currently used in display 86 */ 87 public double getScale() { 88 return scale; 73 public double getMapScale() { 74 /* TODO: we assume a pixel is 0.025mm */ 75 return getDist100Pixel()/(0.00025*100); 76 } 77 78 public double getDist100Pixel() 79 { 80 LatLon ll1 = getLatLon(0,0); 81 LatLon ll2 = getLatLon(100,0); 82 return ll1.greatCircleDistance(ll2); 89 83 } 90 84 … … 110 104 } 111 105 106 public ProjectionBounds getProjectionBounds() { 107 return new ProjectionBounds( 108 new EastNorth( 109 center.east() - getWidth()/2.0*scale, 110 center.north() - getHeight()/2.0*scale), 111 new EastNorth( 112 center.east() + getWidth()/2.0*scale, 113 center.north() + getHeight()/2.0*scale)); 114 }; 115 116 public Bounds getRealBounds() { 117 return new Bounds( 118 getProjection().eastNorth2latlon(new EastNorth( 119 center.east() - getWidth()/2.0*scale, 120 center.north() - getHeight()/2.0*scale)), 121 getProjection().eastNorth2latlon(new EastNorth( 122 center.east() + getWidth()/2.0*scale, 123 center.north() + getHeight()/2.0*scale))); 124 }; 125 112 126 /** 113 127 * @param x X-Pixelposition to get coordinate from … … 118 132 */ 119 133 public LatLon getLatLon(int x, int y) { 120 121 134 return getProjection().eastNorth2latlon(getEastNorth(x, y)); 122 135 } … … 141 154 * @param scale The scale to use. 142 155 */ 143 public void zoomTo(EastNorth newCenter, double scale) { 144 center = newCenter; 145 getProjection().eastNorth2latlon(center); 146 this.scale = scale; 147 repaint(); 156 private void zoomTo(EastNorth newCenter, double newScale) { 157 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */ 158 boolean rep = false; 159 if(!newCenter.equals(center)) 160 { 161 EastNorth oldCenter = center; 162 center = newCenter; 163 rep = true; 164 firePropertyChange("center", oldCenter, newCenter); 165 } 166 if(scale != newScale) 167 { 168 double oldScale = scale; 169 scale = newScale; 170 rep = true; 171 firePropertyChange("scale", oldScale, newScale); 172 } 173 if(rep) 174 repaint(); 175 } 176 177 public void zoomTo(EastNorth newCenter) { 178 zoomTo(newCenter, scale); 179 } 180 181 public void zoomToFactor(double x, double y, double factor) { 182 double newScale = scale*factor; 183 // New center position so that point under the mouse pointer stays the same place as it was before zooming 184 // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom 185 zoomTo(new EastNorth( 186 center.east() - (x - getWidth()/2.0) * (newScale - scale), 187 center.north() + (y - getHeight()/2.0) * (newScale - scale)), 188 newScale); 189 } 190 191 public void zoomToFactor(EastNorth newCenter, double factor) { 192 zoomTo(newCenter, scale*factor); 193 } 194 195 public void zoomToFactor(double factor) { 196 zoomTo(center, scale*factor); 197 } 198 199 public void zoomTo(ProjectionBounds box) { 200 // -20 to leave some border 201 int w = getWidth()-20; 202 if (w < 20) 203 w = 20; 204 int h = getHeight()-20; 205 if (h < 20) 206 h = 20; 207 208 double scaleX = (box.max.east()-box.min.east())/w; 209 double scaleY = (box.max.north()-box.min.north())/h; 210 double newScale = Math.max(scaleX, scaleY); 211 212 zoomTo(box.getCenter(), newScale); 213 } 214 215 public void zoomTo(Bounds box) { 216 zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min), 217 getProjection().latlon2eastNorth(box.max))); 148 218 } 149 219 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r1677 r1722 207 207 ((OsmPrimitive) o).visit(box); 208 208 } 209 if (box. max == null || box.min== null)209 if (box.getBounds() == null) 210 210 return; 211 211 box.enlargeBoundingBox(); -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r1677 r1722 21 21 22 22 import org.openstreetmap.josm.data.Bounds; 23 import org.openstreetmap.josm.data.coor.LatLon; 23 24 import org.openstreetmap.josm.tools.GBC; 24 25 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … 162 163 163 164 private void updateUrl(DownloadDialog gui) { 164 double lat = (gui.minlat + gui.maxlat)/2; 165 double lon = (gui.minlon + gui.maxlon)/2; 166 // convert to mercator (for calculation of zoom only) 167 double latMin = Math.log(Math.tan(Math.PI/4.0+gui.minlat/180.0*Math.PI/2.0))*180.0/Math.PI; 168 double latMax = Math.log(Math.tan(Math.PI/4.0+gui.maxlat/180.0*Math.PI/2.0))*180.0/Math.PI; 169 double size = Math.max(Math.abs(latMax-latMin), Math.abs(gui.maxlon-gui.minlon)); 170 int zoom = 0; 171 while (zoom <= 20) { 172 if (size >= 180) 173 break; 174 size *= 2; 175 zoom++; 176 } 177 // Truncate lat and lon to something more sensible 178 int decimals = (int) Math.pow(10, (zoom / 3)); 179 lat = Math.round(lat * decimals); 180 lat /= decimals; 181 lon = Math.round(lon * decimals); 182 lon /= decimals; 183 showUrl.setText("http://www.openstreetmap.org/?lat="+lat+"&lon="+lon+"&zoom="+zoom); 165 showUrl.setText(OsmUrlToBounds.getURL(new Bounds( 166 new LatLon(gui.minlat, gui.minlon), new LatLon(gui.maxlat, gui.maxlon)))); 184 167 } 185 168 } -
trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r1704 r1722 536 536 537 537 if (centerToggle.getModel().isSelected()) 538 Main.map.mapView.zoomTo(currentImageEntry.pos , Main.map.mapView.getScale());538 Main.map.mapView.zoomTo(currentImageEntry.pos); 539 539 540 540 dlg.setTitle(currentImageEntry.image + -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r1180 r1722 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.projection.Mercator; 15 16 import org.openstreetmap.josm.data.projection.Projection; 16 17 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 18 import org.openstreetmap.josm.data.osm.Node; 17 19 import org.openstreetmap.josm.tools.GBC; 18 20 … … 28 30 29 31 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 30 if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection" ))) {32 if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection", Mercator.class.getName()))) { 31 33 projectionCombo.setSelectedIndex(i); 32 34 break; … … 54 56 55 57 public boolean ok() { 56 boolean restart = Main.pref.put("projection", 57 projectionCombo.getSelectedItem().getClass().getName()); 58 String projname = projectionCombo.getSelectedItem().getClass().getName(); 59 if(Main.pref.put("projection", projname)) 60 Main.setProjection(projname); 58 61 if(Main.pref.put("coordinates", 59 62 ((CoordinateFormat)coordinatesCombo.getSelectedItem()).name())) 60 restart = true;61 return restart;63 Node.setCoordinateFormat(); 64 return false; 62 65 } 63 66 } -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r1677 r1722 121 121 if (attr.containsKey(GpxData.META_KEYWORDS)) simpleTag("keywords", (String)attr.get(GpxData.META_KEYWORDS)); 122 122 123 data.recalculateBounds(); 124 Bounds bounds = data.bounds; 125 String b = "minlat=\"" + bounds.min.lat() + "\" minlon=\"" + bounds.min.lon() + 126 "\" maxlat=\"" + bounds.max.lat() + "\" maxlon=\"" + bounds.max.lon() + "\"" ; 127 inline("bounds", b); 123 Bounds bounds = data.recalculateBounds(); 124 if(bounds != null) 125 { 126 String b = "minlat=\"" + bounds.min.lat() + "\" minlon=\"" + bounds.min.lon() + 127 "\" maxlat=\"" + bounds.max.lat() + "\" maxlon=\"" + bounds.max.lon() + "\"" ; 128 inline("bounds", b); 129 } 128 130 129 131 closeln("metadata"); -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r1689 r1722 55 55 return Double.parseDouble(map.get("m"+key)); 56 56 } 57 58 static public int getZoom(Bounds b) 59 { 60 // convert to mercator (for calculation of zoom only) 61 double latMin = Math.log(Math.tan(Math.PI/4.0+b.min.lat()/180.0*Math.PI/2.0))*180.0/Math.PI; 62 double latMax = Math.log(Math.tan(Math.PI/4.0+b.max.lat()/180.0*Math.PI/2.0))*180.0/Math.PI; 63 double size = Math.max(Math.abs(latMax-latMin), Math.abs(b.max.lon()-b.min.lon())); 64 int zoom = 0; 65 while (zoom <= 20) { 66 if (size >= 180) 67 break; 68 size *= 2; 69 zoom++; 70 } 71 return zoom; 72 } 73 74 static public String getURL(Bounds b) 75 { 76 return getURL(b.center(), getZoom(b)); 77 } 78 79 static public String getURL(LatLon pos, int zoom) 80 { 81 // Truncate lat and lon to something more sensible 82 int decimals = (int) Math.pow(10, (zoom / 3)); 83 double lat = (Math.round(pos.lat() * decimals))/decimals; 84 double lon = (Math.round(pos.lon() * decimals))/decimals; 85 return new String("http://www.openstreetmap.org/?lat="+lat+"&lon="+lon+"&zoom="+zoom); 86 } 57 87 }
Note:
See TracChangeset
for help on using the changeset viewer.