Changeset 1722 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2009-07-03T12:33:32+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.