Changeset 1724 in josm for trunk/src/org
- Timestamp:
- 2009-07-03T22:19:22+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r1722 r1724 27 27 } 28 28 29 public Bounds(LatLon b) { 30 this.min = b; 31 this.max = b; 32 } 33 29 34 @Override public String toString() { 30 35 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; … … 34 39 * @return Center of the bounding box. 35 40 */ 36 public LatLon center() { 37 // FIXME: not sure whether this calculation is right; maybe there is some 38 // more complex calculation needed to get a center of a spherical 39 // dimension? 40 return new LatLon((min.lat()+max.lat())/2, (min.lon()+max.lon())/2); 41 public LatLon getCenter() 42 { 43 return min.getCenter(max); 41 44 } 42 45 -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r1722 r1724 25 25 this.max = max; 26 26 } 27 public ProjectionBounds(EastNorth p) { 28 this.min = p; 29 this.max = p; 30 } 27 31 public ProjectionBounds(EastNorth center, double east, double north) { 28 32 this.min = new EastNorth(center.east()-east/2.0, center.north()-north/2.0); … … 32 36 { 33 37 if (e.east() < min.east() || e.north() < min.north()) 34 min = e;35 elseif (e.east() > max.east() || e.north() > max.north())36 max = e;38 min = new EastNorth(Math.min(e.east(), min.east()), Math.min(e.north(), min.north())); 39 if (e.east() > max.east() || e.north() > max.north()) 40 max = new EastNorth(Math.max(e.east(), max.east()), Math.max(e.north(), max.north())); 37 41 } 38 42 public EastNorth getCenter() 39 43 { 40 return new EastNorth(min.east()/2+max.east()/2, min.north()/2+max.north()/2); 44 return min.getCenter(max); 45 } 46 47 @Override public String toString() { 48 return "ProjectionBounds["+min.east()+","+min.north()+","+max.east()+","+max.north()+"]"; 41 49 } 42 50 } -
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r1209 r1724 30 30 return new EastNorth(this.x + proportion * (en2.x - this.x), 31 31 this.y + proportion * (en2.y - this.y)); 32 } 33 34 public EastNorth getCenter(EastNorth en2) { 35 return new EastNorth((this.x + en2.x)/2.0, (this.y + en2.y)/2.0); 32 36 } 33 37 -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r1722 r1724 143 143 } 144 144 145 public LatLon interpolate(LatLon ll2, double proportion) { 146 return new LatLon(this.x + proportion * (ll2.x - this.x), 147 this.y + proportion * (ll2.y - this.y)); 148 } 149 150 public LatLon getCenter(LatLon ll2) { 151 return new LatLon((this.x + ll2.x)/2.0, (this.y + ll2.y)/2.0); 152 } 153 145 154 @Override public String toString() { 146 155 return "LatLon[lat="+lat()+",lon="+lon()+"]"; -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r1722 r1724 84 84 for (WayPoint wpt : waypoints) { 85 85 if (bounds == null) { 86 bounds = new Bounds(wpt. latlon, wpt.latlon);86 bounds = new Bounds(wpt.getCoor()); 87 87 } else { 88 bounds.extend(wpt. latlon);88 bounds.extend(wpt.getCoor()); 89 89 } 90 90 } … … 92 92 for (WayPoint wpt : rte.routePoints) { 93 93 if (bounds == null) { 94 bounds = new Bounds(wpt. latlon, wpt.latlon);94 bounds = new Bounds(wpt.getCoor()); 95 95 } else { 96 bounds.extend(wpt. latlon);96 bounds.extend(wpt.getCoor()); 97 97 } 98 98 } … … 102 102 for (WayPoint wpt : trkseg) { 103 103 if (bounds == null) { 104 bounds = new Bounds(wpt. latlon, wpt.latlon);104 bounds = new Bounds(wpt.getCoor()); 105 105 } else { 106 bounds.extend(wpt. latlon);106 bounds.extend(wpt.getCoor()); 107 107 } 108 108 } … … 123 123 for (WayPoint tpt : trkseg) { 124 124 if(last != null){ 125 result += calcDistance(last.latlon, tpt.latlon);125 result += last.getCoor().greatCircleDistance(tpt.getCoor()); 126 126 } 127 127 last = tpt; … … 132 132 return result; 133 133 } 134 135 /**136 * returns the distance in meters between two LatLons137 */138 public static double calcDistance(LatLon p1, LatLon p2){139 double lat1, lon1, lat2, lon2;140 double dlon, dlat;141 142 lat1 = p1.lat() * Math.PI / 180.0;143 lon1 = p1.lon() * Math.PI / 180.0;144 lat2 = p2.lat() * Math.PI / 180.0;145 lon2 = p2.lon() * Math.PI / 180.0;146 147 dlon = lon2 - lon1;148 dlat = lat2 - lat1;149 150 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));151 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));152 return 6367000 * c;153 }154 155 134 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r1721 r1724 4 4 package org.openstreetmap.josm.data.gpx; 5 5 6 import java.text.ParsePosition;7 import java.text.SimpleDateFormat;8 6 import java.util.Date; 9 import java.util.regex.Pattern;10 7 import java.awt.Color; 11 8 12 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.coor.CachedLatLon; 13 11 import org.openstreetmap.josm.data.coor.EastNorth; 14 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.projection.Projection; 14 import org.openstreetmap.josm.tools.DateUtils; 15 15 16 16 public class WayPoint extends WithAttributes implements Comparable<WayPoint> 17 17 { 18 public final LatLon latlon;19 public final EastNorth eastNorth;20 18 public double time; 21 19 public Color customColoring; … … 23 21 public int dir; 24 22 23 private CachedLatLon coor; 24 25 public final LatLon getCoor() { 26 return coor; 27 } 28 29 public final EastNorth getEastNorth() { 30 return coor.getEastNorth(); 31 } 32 25 33 public WayPoint(LatLon ll) { 26 latlon = ll; 27 eastNorth = Main.proj.latlon2eastNorth(ll); 34 coor = new CachedLatLon(ll); 28 35 } 29 36 30 37 @Override 31 38 public String toString() { 32 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")";39 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + coor.toString() + ", " + attr + ")"; 33 40 } 34 41 … … 36 43 * Convert the time stamp of the waypoint into seconds from the epoch 37 44 */ 38 public final static SimpleDateFormat GPXTIMEFMT = 39 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 40 public final static SimpleDateFormat GPXTIMEFMT_nofrac = 41 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 42 public final static SimpleDateFormat GPXTIMEFMT_tz = 43 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 44 public final static SimpleDateFormat GPXTIMEFMT_tz_nofrac = 45 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 46 47 private final static Pattern colontz = Pattern.compile(".*[+-][0-9][0-9]:[0-9][0-9]\\z"); 48 private final static Pattern colontzreplacement = Pattern.compile("([+-][0-9][0-9]):([0-9][0-9])\\z"); 49 50 public void setTime() { 51 if (! attr.containsKey("time")) { 52 return; 53 } 54 String timestring = attr.get("time").toString(); 55 56 /* make the string timzeone be conanonical - unfortunately the allowed timezone in a 57 * GPX is Z or +/-hh:mm whereas in simpledateformat it is +/-hhmm only (no colon) 58 * If no timezone is given, the time will be interpreted as local time by parse. */ 59 if (timestring.substring(timestring.length() - 1).equals("Z")) { 60 timestring = timestring.substring(0, timestring.length() - 1) + "+0000"; 61 } else if (colontz.matcher(timestring).matches()) { 62 timestring = colontzreplacement.matcher(timestring).replaceFirst("$1$2"); 63 } 64 Date d = GPXTIMEFMT_tz.parse(timestring, new ParsePosition(0)); 65 if (d == null) { 66 d = GPXTIMEFMT_tz_nofrac.parse(timestring, new ParsePosition(0)); 67 if (d == null) { 68 /* try without a zimezone indication */ 69 d = GPXTIMEFMT.parse(timestring, new ParsePosition(0)); 70 if (d == null) { 71 d = GPXTIMEFMT_nofrac.parse(timestring, new ParsePosition(0)); 72 } 73 // date has parsed in local time, and been adjusted to UTC by parse 45 public void setTime() { 46 for(String key : new String[]{"time", "cmt", "desc"}) 47 { 48 if(attr.containsKey("time")) 49 { 50 double t = DateUtils.fromString(attr.get("time").toString()).getTime(); 51 if(t != 0.0) 52 { 53 time = t / 1000.0; /* ms => seconds */ 54 break; 55 } 74 56 } 75 }76 if (d != null /* parsing ok */) {77 time = d.getTime() / 1000.0; /* ms => seconds */78 }79 }80 /**81 * Convert a time stamp of the waypoint from the <cmt> or <desc> field82 * into seconds from the epoch. Handles the date format as it is used by83 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0).84 * A value of <time> fields overwrites values set with by method.85 * Does nothing if specified key does not exist or text cannot be parsed.86 *87 * @param key The key that contains the text to convert.88 */89 public void setGarminCommentTime(String key) {90 // do not overwrite time if already set91 if (time != 0.0) {92 return;93 }94 if (! attr.containsKey(key)) {95 return;96 }97 // example date format "18-AUG-08 13:33:03"98 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone99 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0));100 if (d != null /* parsing OK */) {101 time = d.getTime() / 1000.0; /* ms => seconds */102 57 } 103 58 } -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1722 r1724 6 6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.CachedLatLon; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; … … 11 12 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 13 import org.openstreetmap.josm.data.osm.Node; 13 14 14 15 15 /** … … 20 20 public final class Node extends OsmPrimitive { 21 21 22 private LatLon coor; 23 24 private EastNorth eastNorth; 25 private Projection proj; 26 22 private CachedLatLon coor; 27 23 28 24 public final void setCoor(LatLon coor) { 29 this.coor = coor; 30 proj = null; 25 if(this.coor == null) 26 this.coor = new CachedLatLon(coor); 27 else 28 this.coor.setCoor(coor); 31 29 } 32 30 … … 36 34 37 35 public final void setEastNorth(EastNorth eastNorth) { 38 proj = Main.proj; 39 eastNorth = eastNorth; 40 this.coor = proj.eastNorth2latlon(eastNorth); 36 coor.setEastNorth(eastNorth); 41 37 } 42 38 43 39 public final EastNorth getEastNorth() { 44 if(proj != Main.proj) 45 { 46 proj = Main.proj; 47 eastNorth = proj.latlon2eastNorth(coor); 48 } 49 return eastNorth; 40 return coor.getEastNorth(); 50 41 } 51 42 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r1722 r1724 6 6 import org.openstreetmap.josm.data.ProjectionBounds; 7 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.CachedLatLon; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.osm.Node; … … 42 43 if(b != null) 43 44 { 44 visit( Main.proj.latlon2eastNorth(b.min));45 visit( Main.proj.latlon2eastNorth(b.max));45 visit(b.min); 46 visit(b.max); 46 47 } 47 48 } … … 49 50 public void visit(ProjectionBounds b) { 50 51 if(b != null) 51 bounds = new ProjectionBounds(b.min, b.max); 52 { 53 visit(b.min); 54 visit(b.max); 55 } 56 } 57 58 public void visit(LatLon latlon) { 59 if(latlon != null) 60 { 61 if(latlon instanceof CachedLatLon) 62 visit(((CachedLatLon)latlon).getEastNorth()); 63 else 64 visit(Main.proj.latlon2eastNorth(latlon)); 65 } 52 66 } 53 67 … … 55 69 if (eastNorth != null) { 56 70 if (bounds == null) 57 bounds = new ProjectionBounds(eastNorth , eastNorth);71 bounds = new ProjectionBounds(eastNorth); 58 72 else 59 73 bounds.extend(eastNorth); … … 98 112 Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree))); 99 113 } 114 115 @Override public String toString() { 116 return "BoundingXYVisitor["+bounds+"]"; 117 } 100 118 } -
trunk/src/org/openstreetmap/josm/data/projection/Epsg4326.java
r1722 r1724 25 25 26 26 @Override public String toString() { 27 return tr(" EPSG:4326");27 return tr("WGS84 Geographisch"); 28 28 } 29 29 … … 34 34 public String getCacheDirectoryName() { 35 35 return "epsg4326"; 36 }37 38 @Override public boolean equals(Object o) {39 return o instanceof Epsg4326;40 36 } 41 37 -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r1722 r1724 158 158 } 159 159 160 @Override161 public boolean equals(Object o) {162 return o instanceof Lambert;163 }164 165 160 /** 166 161 * Initializes from geographic coordinates. Note that reference ellipsoid -
trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java
r1722 r1724 107 107 } 108 108 109 @Override110 public boolean equals(Object o) {111 return o instanceof LambertEST;112 }113 114 109 public ProjectionBounds getWorldBounds() 115 110 { -
trunk/src/org/openstreetmap/josm/data/projection/Mercator.java
r1722 r1724 47 47 } 48 48 49 @Override public boolean equals(Object o) {50 return o instanceof Mercator;51 }52 53 49 public ProjectionBounds getWorldBounds() 54 50 { -
trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java
r1722 r1724 101 101 } 102 102 103 @Override104 public boolean equals(Object o) {105 return o instanceof SwissGrid;106 }107 108 103 public ProjectionBounds getWorldBounds() 109 104 { -
trunk/src/org/openstreetmap/josm/data/projection/UTM.java
r1722 r1724 345 345 } 346 346 347 @Override public boolean equals(Object o) {348 return o instanceof UTM;349 }350 351 347 public ProjectionBounds getWorldBounds() 352 348 { -
trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r1722 r1724 63 63 import org.openstreetmap.josm.Main; 64 64 import org.openstreetmap.josm.actions.RenameLayerAction; 65 import org.openstreetmap.josm.data.coor. EastNorth;65 import org.openstreetmap.josm.data.coor.CachedLatLon; 66 66 import org.openstreetmap.josm.data.coor.LatLon; 67 67 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 244 244 final File image; 245 245 ImageLoader.Entry icon; 246 247 246 Date time; 248 LatLon coor; 249 EastNorth pos; 247 CachedLatLon pos; 250 248 251 249 public ImageEntry(File image) { … … 290 288 for (Collection<WayPoint> segment : trk.trackSegs) { 291 289 for (WayPoint p : segment) { 290 LatLon c = p.getCoor(); 292 291 if (!p.attr.containsKey("time")) 293 throw new IOException(tr("No time for point {0} x {1}", p.latlon.lat(),p.latlon.lon()));292 throw new IOException(tr("No time for point {0} x {1}",c.lat(),c.lon())); 294 293 Date d = null; 295 294 try { 296 295 d = DateParser.parse((String) p.attr.get("time")); 297 296 } catch (ParseException e) { 298 throw new IOException(tr("Cannot read time \"{0}\" from point {1} x {2}",p.attr.get("time"), p.latlon.lat(),p.latlon.lon()));297 throw new IOException(tr("Cannot read time \"{0}\" from point {1} x {2}",p.attr.get("time"),c.lat(),c.lon())); 299 298 } 300 gps.add(new TimedPoint(d, p.eastNorth));299 gps.add(new TimedPoint(d, c)); 301 300 } 302 301 } … … 364 363 private static final class TimedPoint implements Comparable<TimedPoint> { 365 364 Date time; 366 EastNorth pos; 367 public TimedPoint(Date time, EastNorth pos) { 365 CachedLatLon pos; 366 367 public TimedPoint(Date time, LatLon pos) { 368 368 this.time = time; 369 this.pos = pos;369 this.pos.setCoor(pos); 370 370 } 371 371 public int compareTo(TimedPoint point) { … … 404 404 if (e.pos == null) 405 405 continue; 406 Point p = Main.map.mapView.getPoint(e.pos );406 Point p = Main.map.mapView.getPoint(e.pos.getEastNorth()); 407 407 Rectangle r = new Rectangle(p.x-ICON_SIZE/2, p.y-ICON_SIZE/2, ICON_SIZE, ICON_SIZE); 408 408 if (r.contains(ev.getPoint())) { … … 536 536 537 537 if (centerToggle.getModel().isSelected()) 538 Main.map.mapView.zoomTo(currentImageEntry.pos );538 Main.map.mapView.zoomTo(currentImageEntry.pos.getEastNorth()); 539 539 540 540 dlg.setTitle(currentImageEntry.image + 541 " (" + currentImageEntry. coor.toDisplayString() + ")");541 " (" + currentImageEntry.pos.toDisplayString() + ")"); 542 542 dlg.setCursor(Cursor.getDefaultCursor()); 543 543 } … … 612 612 } 613 613 614 Point p = mv.getPoint(e.pos );614 Point p = mv.getPoint(e.pos.getEastNorth()); 615 615 Rectangle r = new Rectangle(p.x-ICON_SIZE / 2, p.y-ICON_SIZE / 2, ICON_SIZE, ICON_SIZE); 616 616 if (r.contains(mousePosition)) { … … 624 624 ImageEntry e = data.get(i); 625 625 if (e.pos != null) { 626 Point p = mv.getPoint(e.pos );626 Point p = mv.getPoint(e.pos.getEastNorth()); 627 627 Rectangle r = new Rectangle(p.x-ICON_SIZE / 2, p.y-ICON_SIZE / 2, ICON_SIZE, ICON_SIZE); 628 628 g.drawImage(e.getIcon(), r.x, r.y, null); … … 686 686 Date time = new Date(tp.time.getTime() - (delta+gpstimezone)); 687 687 if (time.after(e.time) && lastTP != null) { 688 double x = (lastTP.pos.east()+tp.pos.east())/2; 689 double y = (lastTP.pos.north()+tp.pos.north())/2; 690 e.pos = new EastNorth(x,y); 688 e.pos.setCoor(lastTP.pos.getCenter(tp.pos)); 691 689 break; 692 690 } … … 696 694 e.pos = gps.getLast().pos; 697 695 } 698 e.coor = Main.proj.eastNorth2latlon(e.pos);699 696 } 700 697 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1685 r1724 459 459 for (Collection<WayPoint> segment : trk.trackSegs) { 460 460 for (WayPoint trkPnt : segment) { 461 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) { 461 LatLon c = trkPnt.getCoor(); 462 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) { 462 463 continue; 463 464 } 464 465 trkPnt.customColoring = neutralColor; 465 466 if (oldWp != null) { 466 double dist = trkPnt.latlon.greatCircleDistance(oldWp.latlon);467 double dist = c.greatCircleDistance(oldWp.getCoor()); 467 468 468 469 switch(colored) { … … 495 496 if (maxLineLength == -1 || dist <= maxLineLength) { 496 497 trkPnt.drawLine = true; 497 trkPnt.dir = (int) (Math.atan2(-trkPnt.eastNorth.north()+oldWp.eastNorth.north(), trkPnt.eastNorth.east()-oldWp.eastNorth.east()) / Math.PI * 4 + 3.5); // crude but works498 trkPnt.dir = (int)oldWp.getCoor().heading(trkPnt.getCoor()); 498 499 } else { 499 500 trkPnt.drawLine = false; … … 517 518 for (Collection<WayPoint> segment : trk.trackSegs) { 518 519 for (WayPoint trkPnt : segment) { 519 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 520 LatLon c = trkPnt.getCoor(); 521 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 520 522 continue; 521 Point screen = mv.getPoint(trkPnt. eastNorth);523 Point screen = mv.getPoint(trkPnt.getEastNorth()); 522 524 if (trkPnt.drawLine) { 523 525 // skip points that are on the same screenposition … … 542 544 for (Collection<WayPoint> segment : trk.trackSegs) { 543 545 for (WayPoint trkPnt : segment) { 544 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 546 LatLon c = trkPnt.getCoor(); 547 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 545 548 continue; 546 549 if (trkPnt.drawLine) { 547 Point screen = mv.getPoint(trkPnt. eastNorth);550 Point screen = mv.getPoint(trkPnt.getEastNorth()); 548 551 // skip points that are on the same screenposition 549 552 if (old != null && (oldA == null || screen.x < oldA.x-delta || screen.x > oldA.x+delta || screen.y < oldA.y-delta || screen.y > oldA.y+delta)) { … … 572 575 for (Collection<WayPoint> segment : trk.trackSegs) { 573 576 for (WayPoint trkPnt : segment) { 574 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 577 LatLon c = trkPnt.getCoor(); 578 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 575 579 continue; 576 580 if (trkPnt.drawLine) { 577 Point screen = mv.getPoint(trkPnt. eastNorth);581 Point screen = mv.getPoint(trkPnt.getEastNorth()); 578 582 // skip points that are on the same screenposition 579 583 if (old != null && (oldA == null || screen.x < oldA.x-delta || screen.x > oldA.x+delta || screen.y < oldA.y-delta || screen.y > oldA.y+delta)) { … … 598 602 for (Collection<WayPoint> segment : trk.trackSegs) { 599 603 for (WayPoint trkPnt : segment) { 600 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 604 LatLon c = trkPnt.getCoor(); 605 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 601 606 continue; 602 Point screen = mv.getPoint(trkPnt. eastNorth);607 Point screen = mv.getPoint(trkPnt.getEastNorth()); 603 608 g.setColor(trkPnt.customColoring); 604 609 g.fillRect(screen.x-1, screen.y-1, 3, 3); … … 616 621 for (Collection<WayPoint> segment : trk.trackSegs) { 617 622 for (WayPoint trkPnt : segment) { 618 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 623 LatLon c = trkPnt.getCoor(); 624 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 619 625 continue; 620 626 if (!trkPnt.drawLine) { 621 Point screen = mv.getPoint(trkPnt. eastNorth);627 Point screen = mv.getPoint(trkPnt.getEastNorth()); 622 628 g.drawRect(screen.x, screen.y, 0, 0); 623 629 } … … 635 641 for (Collection<WayPoint> segment : trk.trackSegs) { 636 642 for (WayPoint trkPnt : segment) { 637 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 643 LatLon c = trkPnt.getCoor(); 644 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) 638 645 continue; 639 Point screen = mv.getPoint(trkPnt. eastNorth);646 Point screen = mv.getPoint(trkPnt.getEastNorth()); 640 647 g.setColor(trkPnt.customColoring); 641 648 g.drawRect(screen.x, screen.y, 0, 0); … … 650 657 651 658 @Override public void visitBoundingBox(BoundingXYVisitor v) { 652 for (WayPoint p : data.waypoints) 653 v.visit(p.eastNorth); 654 655 for (GpxRoute rte : data.routes) { 656 Collection<WayPoint> r = rte.routePoints; 657 for (WayPoint p : r) { 658 v.visit(p.eastNorth); 659 } 660 } 661 662 for (GpxTrack trk : data.tracks) { 663 for (Collection<WayPoint> seg : trk.trackSegs) { 664 for (WayPoint p : seg) { 665 v.visit(p.eastNorth); 666 } 667 } 668 } 659 v.visit(data.recalculateBounds()); 669 660 } 670 661 … … 684 675 Way w = new Way(); 685 676 for (WayPoint p : segment) { 686 Node n = new Node(p. latlon);677 Node n = new Node(p.getCoor()); 687 678 String timestr = p.getString("time"); 688 679 if(timestr != null) … … 748 739 for (Collection<WayPoint> segment : trk.trackSegs) { 749 740 for (WayPoint p : segment) { 750 latsum += p. latlon.lat();741 latsum += p.getCoor().lat(); 751 742 latcnt ++; 752 743 } … … 782 773 for (Collection<WayPoint> segment : trk.trackSegs) { 783 774 for (WayPoint p : segment) { 784 if (previous == null || p.latlon.greatCircleDistance(previous) > buffer_dist) { 775 LatLon c = p.getCoor(); 776 if (previous == null || c.greatCircleDistance(previous) > buffer_dist) { 785 777 // we add a buffer around the point. 786 r.setRect( p.latlon.lon()-buffer_x, p.latlon.lat()-buffer_y, 2*buffer_x, 2*buffer_y);778 r.setRect(c.lon()-buffer_x, c.lat()-buffer_y, 2*buffer_x, 2*buffer_y); 787 779 a.add(new Area(r)); 788 previous = p.latlon;780 previous = c; 789 781 } 790 782 } … … 917 909 for (WayPoint w : data.waypoints) { 918 910 if (waypoints.contains(w)) { continue; } 919 WayPoint wNear = nearestPointOnTrack(w. eastNorth, snapDistance);911 WayPoint wNear = nearestPointOnTrack(w.getEastNorth(), snapDistance); 920 912 if (wNear != null) { 921 WayPoint wc = new WayPoint(w. latlon);913 WayPoint wc = new WayPoint(w.getCoor()); 922 914 wc.time = wNear.time; 923 915 if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name")); … … 974 966 timedMarkersOmitted = true; 975 967 } else { 976 EastNorth eastNorth = w1.eastNorth.interpolate( 977 w2.eastNorth, 978 (startTime - w1.time)/(w2.time - w1.time)); 979 wayPointFromTimeStamp = new WayPoint(Main.proj.eastNorth2latlon(eastNorth)); 968 wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate( 969 w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time))); 980 970 wayPointFromTimeStamp.time = startTime; 981 971 String name = wavFile.getName(); … … 998 988 for (Collection<WayPoint> seg : track.trackSegs) { 999 989 for (WayPoint w : seg) { 1000 WayPoint wStart = new WayPoint(w. latlon);990 WayPoint wStart = new WayPoint(w.getCoor()); 1001 991 wStart.attr.put("name", "start"); 1002 992 wStart.time = w.time; … … 1030 1020 else 1031 1021 name = AudioMarker.inventName(offset); 1032 AudioMarker am = AudioMarker.create(w. latlon,1022 AudioMarker am = AudioMarker.create(w.getCoor(), 1033 1023 name, uri, ml, w.time, offset); 1034 1024 /* timeFromAudio intended for future use to shift markers of this type on synchronization */ … … 1104 1094 for (WayPoint S : seg) { 1105 1095 if (R == null) { 1096 EastNorth c = R.getEastNorth(); 1106 1097 R = S; 1107 rx = R.eastNorth.east();1108 ry = R.eastNorth.north();1098 rx = c.east(); 1099 ry = c.north(); 1109 1100 x = px - rx; 1110 1101 y = py - ry; … … 1112 1103 if (PRsq < PNminsq) { 1113 1104 PNminsq = PRsq; 1114 bestEN = R.eastNorth;1105 bestEN = c; 1115 1106 bestTime = R.time; 1116 1107 } 1117 1108 } else { 1118 sx = S.eastNorth.east(); 1119 sy = S.eastNorth.north(); 1109 EastNorth c = S.getEastNorth(); 1110 sx = c.east(); 1111 sy = c.north(); 1120 1112 double A = sy - ry; 1121 1113 double B = rx - sx; … … 1147 1139 } 1148 1140 if (R != null) { 1141 EastNorth c = R.getEastNorth(); 1149 1142 /* if there is only one point in the seg, it will do this twice, but no matter */ 1150 rx = R.eastNorth.east();1151 ry = R.eastNorth.north();1143 rx = c.east(); 1144 ry = c.north(); 1152 1145 x = px - rx; 1153 1146 y = py - ry; … … 1155 1148 if (PRsq < PNminsq) { 1156 1149 PNminsq = PRsq; 1157 bestEN = R.eastNorth;1150 bestEN = c; 1158 1151 bestTime = R.time; 1159 1152 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java
r1169 r1724 36 36 37 37 @Override public boolean containsPoint(Point p) { 38 Point screen = Main.map.mapView.getPoint( eastNorth);38 Point screen = Main.map.mapView.getPoint(getEastNorth()); 39 39 buttonRectangle.setLocation(screen.x+4, screen.y+2); 40 40 return buttonRectangle.contains(p); … … 46 46 return; 47 47 } 48 Point screen = mv.getPoint( eastNorth);48 Point screen = mv.getPoint(getEastNorth()); 49 49 buttonRectangle.setLocation(screen.x+4, screen.y+2); 50 50 symbol.paintIcon(mv, g, screen.x+4, screen.y+2); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r1601 r1724 15 15 16 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.data.coor.CachedLatLon; 17 18 import org.openstreetmap.josm.data.coor.EastNorth; 18 19 import org.openstreetmap.josm.data.coor.LatLon; … … 59 60 */ 60 61 public class Marker implements ActionListener { 61 62 public EastNorth eastNorth;63 62 public final String text; 64 63 public final Icon symbol; 65 64 public final MarkerLayer parentLayer; 66 public double time; /* a vbsolute time of marker since epocj*/65 public double time; /* absolute time of marker since epoch */ 67 66 public double offset; /* time offset in seconds from the gpx point from which it was derived, 68 67 may be adjusted later to sync with other data, so not final */ 68 69 private CachedLatLon coor; 70 71 public final void setCoor(LatLon coor) { 72 if(this.coor == null) 73 this.coor = new CachedLatLon(coor); 74 else 75 this.coor.setCoor(coor); 76 } 77 78 public final LatLon getCoor() { 79 return coor; 80 } 81 82 public final void setEastNorth(EastNorth eastNorth) { 83 coor.setEastNorth(eastNorth); 84 } 85 86 public final EastNorth getEastNorth() { 87 return coor.getEastNorth(); 88 } 69 89 70 90 /** … … 101 121 102 122 if (uri == null) 103 return new Marker(wpt. latlon, name_desc, wpt.getString("symbol"), parentLayer, time, offset);123 return new Marker(wpt.getCoor(), name_desc, wpt.getString("symbol"), parentLayer, time, offset); 104 124 else if (uri.endsWith(".wav")) 105 return AudioMarker.create(wpt. latlon, name_desc, uri, parentLayer, time, offset);125 return AudioMarker.create(wpt.getCoor(), name_desc, uri, parentLayer, time, offset); 106 126 else if (uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".jpeg") || uri.endsWith(".gif")) 107 return ImageMarker.create(wpt. latlon, uri, parentLayer, time, offset);127 return ImageMarker.create(wpt.getCoor(), uri, parentLayer, time, offset); 108 128 else 109 return WebMarker.create(wpt. latlon, uri, parentLayer, time, offset);129 return WebMarker.create(wpt.getCoor(), uri, parentLayer, time, offset); 110 130 } 111 131 … … 122 142 123 143 public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) { 124 eastNorth = Main.proj.latlon2eastNorth(ll);144 setCoor(ll); 125 145 this.text = text; 126 146 this.offset = offset; … … 162 182 */ 163 183 public void paint(Graphics g, MapView mv, boolean mousePressed, String show) { 164 Point screen = mv.getPoint( eastNorth);184 Point screen = mv.getPoint(getEastNorth()); 165 185 if (symbol != null && show.equalsIgnoreCase("show")) { 166 186 symbol.paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2); … … 205 225 206 226 public AudioMarker audioMarkerFromMarker(String uri) { 207 AudioMarker audioMarker = AudioMarker.create( Main.proj.eastNorth2latlon(this.eastNorth), this.text, uri, this.parentLayer, this.time, this.offset);227 AudioMarker audioMarker = AudioMarker.create(getCoor(), this.text, uri, this.parentLayer, this.time, this.offset); 208 228 return audioMarker; 209 229 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r1685 r1724 28 28 import org.openstreetmap.josm.Main; 29 29 import org.openstreetmap.josm.actions.RenameLayerAction; 30 import org.openstreetmap.josm.data.coor. EastNorth;30 import org.openstreetmap.josm.data.coor.LatLon; 31 31 import org.openstreetmap.josm.data.gpx.GpxData; 32 32 import org.openstreetmap.josm.data.gpx.GpxLink; … … 184 184 @Override public void visitBoundingBox(BoundingXYVisitor v) { 185 185 for (Marker mkr : data) 186 v.visit(mkr. eastNorth);186 v.visit(mkr.getEastNorth()); 187 187 } 188 188 … … 242 242 if (playHeadMarker == null) 243 243 return; 244 addAudioMarker(playHeadMarker.time, playHeadMarker. eastNorth);244 addAudioMarker(playHeadMarker.time, playHeadMarker.getCoor()); 245 245 Main.map.mapView.repaint(); 246 246 } … … 296 296 } 297 297 298 public AudioMarker addAudioMarker(double time, EastNorth en) {298 public AudioMarker addAudioMarker(double time, LatLon coor) { 299 299 // find first audio marker to get absolute start time 300 300 double offset = 0.0; … … 313 313 314 314 // make our new marker 315 AudioMarker newAudioMarker = AudioMarker.create( Main.proj.eastNorth2latlon(en),315 AudioMarker newAudioMarker = AudioMarker.create(coor, 316 316 AudioMarker.inventName(offset), AudioPlayer.url().toString(), this, time, offset); 317 317 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java
r1462 r1724 43 43 static private PlayHeadMarker playHead = null; 44 44 private MapMode oldMode = null; 45 private EastNorth oldEastNorth;45 private LatLon oldCoor; 46 46 private boolean enabled; 47 47 private boolean wasPlaying = false; … … 75 75 * getting confused with other drag operations (like select) */ 76 76 oldMode = Main.map.mapMode; 77 old EastNorth = eastNorth;77 oldCoor = getCoor(); 78 78 PlayHeadDragMode playHeadDragMode = new PlayHeadDragMode(playHead); 79 79 Main.map.selectMapMode(playHeadDragMode); … … 85 85 86 86 @Override public boolean containsPoint(Point p) { 87 Point screen = Main.map.mapView.getPoint( eastNorth);87 Point screen = Main.map.mapView.getPoint(getEastNorth()); 88 88 Rectangle r = new Rectangle(screen.x, screen.y, symbol.getIconWidth(), 89 89 symbol.getIconHeight()); … … 106 106 107 107 /** 108 * reinstate the old map mode after sw uitching temporarily to do a play head drag108 * reinstate the old map mode after switching temporarily to do a play head drag 109 109 */ 110 110 private void endDrag(boolean reset) { … … 113 113 catch (Exception ex) { AudioPlayer.audioMalfunction(ex);} 114 114 if (reset) 115 eastNorth = oldEastNorth;115 setCoor(oldCoor); 116 116 Main.map.selectMapMode(oldMode); 117 117 Main.map.mapView.repaint(); … … 124 124 */ 125 125 public void drag(EastNorth en) { 126 eastNorth = en;126 setEastNorth(en); 127 127 Main.map.mapView.repaint(); 128 128 } … … 135 135 */ 136 136 public void reposition(EastNorth en) { 137 // eastNorth = en;138 137 WayPoint cw = null; 139 138 AudioMarker recent = AudioMarker.recentlyPlayedMarker(); … … 167 166 endDrag(true); 168 167 } else { 169 eastNorth = cw.eastNorth;168 setCoor(cw.getCoor()); 170 169 ca.play(cw.time - ca.time); 171 170 endDrag(false); … … 193 192 for (Marker m : recent.parentLayer.data) { 194 193 if (m instanceof AudioMarker) { 195 double distanceSquared = m. eastNorth.distanceSq(en);194 double distanceSquared = m.getEastNorth().distanceSq(en); 196 195 if (distanceSquared < closestAudioMarkerDistanceSquared) { 197 196 ca = (AudioMarker) m; … … 216 215 return; 217 216 } 218 ca = recent.parentLayer.addAudioMarker(cw.time, cw. eastNorth);217 ca = recent.parentLayer.addAudioMarker(cw.time, cw.getCoor()); 219 218 } 220 219 … … 227 226 else if (recent.parentLayer.synchronizeAudioMarkers(ca)) { 228 227 JOptionPane.showMessageDialog(Main.parent, tr("Audio synchronized at point {0}.", ca.text)); 229 eastNorth = ca.eastNorth;228 setCoor(ca.getCoor()); 230 229 endDrag(false); 231 230 } else { … … 237 236 public void paint(Graphics g, MapView mv /*, boolean mousePressed */) { 238 237 if (time < 0.0) return; 239 Point screen = mv.getPoint( eastNorth);238 Point screen = mv.getPoint(getEastNorth()); 240 239 symbol.paintIcon(mv, g, screen.x, screen.y); 241 240 } … … 297 296 if (w1 == null) 298 297 return; 299 eastNorth =w2 == null ?300 w1. eastNorth:301 w1. eastNorth.interpolate(w2.eastNorth,302 (audioTime - w1.time)/(w2.time - w1.time)) ;298 setEastNorth(w2 == null ? 299 w1.getEastNorth() : 300 w1.getEastNorth().interpolate(w2.getEastNorth(), 301 (audioTime - w1.time)/(w2.time - w1.time))); 303 302 time = audioTime; 304 303 Main.map.mapView.repaint(); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r1597 r1724 262 262 } else if (qName.equals("cmt") || qName.equals("desc")) { 263 263 currentWayPoint.attr.put(qName, accumulator.toString()); 264 currentWayPoint.set GarminCommentTime(qName);264 currentWayPoint.setTime(); 265 265 } else if (qName.equals("rtept")) { 266 266 currentState = states.pop(); -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r1722 r1724 11 11 12 12 import org.openstreetmap.josm.data.Bounds; 13 import org.openstreetmap.josm.data.coor.LatLon; 13 14 import org.openstreetmap.josm.data.gpx.GpxData; 14 15 import org.openstreetmap.josm.data.gpx.GpxLink; … … 237 238 } 238 239 if (pnt != null) { 239 openAtt(type, "lat=\"" + pnt.latlon.lat() + "\" lon=\"" + pnt.latlon.lon() + "\""); 240 LatLon c =pnt.getCoor(); 241 openAtt(type, "lat=\"" + c.lat() + "\" lon=\"" + c.lon() + "\""); 240 242 writeAttr(pnt.attr); 241 243 closeln(type); -
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r1453 r1724 18 18 import org.openstreetmap.josm.data.gpx.GpxTrack; 19 19 import org.openstreetmap.josm.data.gpx.WayPoint; 20 import org.openstreetmap.josm.tools.DateUtils; 20 21 21 22 /** … … 285 286 // As this sentence has no complete time only use it 286 287 // if there is no time so far 287 String gpxdate = WayPoint.GPXTIMEFMT.format(d); 288 currentwp.attr.put("time", gpxdate); 288 currentwp.attr.put("time", DateUtils.fromDate(d)); 289 289 } 290 290 // elevation … … 390 390 } 391 391 // time: this sentence has complete time so always use it. 392 String gpxdate = WayPoint.GPXTIMEFMT.format(d); 393 currentwp.attr.put("time", gpxdate); 392 currentwp.attr.put("time", DateUtils.fromDate(d)); 394 393 // speed 395 394 accu = e[GPRMC.SPEED.position]; -
trunk/src/org/openstreetmap/josm/tools/DateUtils.java
r1499 r1724 19 19 package org.openstreetmap.josm.tools; 20 20 21 import java.text.ParsePosition; 22 import java.text.SimpleDateFormat; 21 23 import java.util.Calendar; 22 24 import java.util.Date; … … 61 63 // "2007-07-25T09:26:24{Z|{+|-}01:00}" 62 64 if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") || 65 checkLayout(str, "xxxx-xx-xxTxx:xx:xx") || 63 66 checkLayout(str, "xxxx-xx-xxTxx:xx:xx+xx:00") || 64 67 checkLayout(str, "xxxx-xx-xxTxx:xx:xx-xx:00")) { … … 78 81 79 82 return calendar.getTime(); 83 } 84 else if(checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") || 85 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") || 86 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx+xx:00") || 87 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx-xx:00")) { 88 calendar.set( 89 parsePart(str, 0, 4), 90 parsePart(str, 5, 2)-1, 91 parsePart(str, 8, 2), 92 parsePart(str, 11, 2), 93 parsePart(str, 14,2), 94 parsePart(str, 17, 2)); 95 long millis = parsePart(str, 20, 3); 96 if (str.length() == 29) 97 millis += parsePart(str, 24, 2) * (str.charAt(23) == '+' ? -3600000 : 3600000); 98 calendar.setTimeInMillis(calendar.getTimeInMillis()+millis); 99 100 return calendar.getTime(); 101 } 102 else 103 { 104 // example date format "18-AUG-08 13:33:03" 105 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); 106 Date d = f.parse(str, new ParsePosition(0)); 107 if(d != null) 108 return d; 80 109 } 81 110 … … 97 126 if (text.length() != pattern.length()) return false; 98 127 for (int i=0; i<pattern.length(); i++) { 99 if (pattern.charAt(i) == 'x') continue; 100 if (pattern.charAt(i) != text.charAt(i)) return false; 128 char pc = pattern.charAt(i); 129 char tc = text.charAt(i); 130 if(pc == 'x' && tc >= '0' && tc <= '9') continue; 131 else if(pc == 'x' || pc != tc) return false; 101 132 } 102 133 return true; -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r1722 r1724 74 74 static public String getURL(Bounds b) 75 75 { 76 return getURL(b. center(), getZoom(b));76 return getURL(b.getCenter(), getZoom(b)); 77 77 } 78 78
Note:
See TracChangeset
for help on using the changeset viewer.