Changeset 4126 in josm for trunk/src/org/openstreetmap/josm/data/gpx
- Timestamp:
- 2011-06-07T19:05:14+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r3321 r4126 7 7 import java.util.Date; 8 8 9 import org.openstreetmap.josm. data.coor.CachedLatLon;9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.data.coor.EastNorth; 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.data.projection.Projections; 12 13 import org.openstreetmap.josm.tools.PrimaryDateParser; 13 14 … … 26 27 27 28 public WayPoint(LatLon ll) { 28 coor = new CachedLatLon(ll); 29 lat = ll.lat(); 30 lon = ll.lon(); 29 31 } 30 32 31 private final CachedLatLon coor; 33 /* 34 * We "inline" lat/lon, rather than usinga LatLon internally => reduces memory overhead. Relevant 35 * because a lot of GPX waypoints are created when GPS tracks are downloaded from the OSM server. 36 */ 37 private double lat = 0; 38 private double lon = 0; 39 40 /* 41 * internal cache of projected coordinates 42 */ 43 private double east = Double.NaN; 44 private double north = Double.NaN; 45 46 /** 47 * Invalidate the internal cache of east/north coordinates. 48 */ 49 public void invalidateEastNorthCache() { 50 this.east = Double.NaN; 51 this.north = Double.NaN; 52 } 32 53 33 54 public final LatLon getCoor() { 34 return coor;55 return new LatLon(lat,lon); 35 56 } 36 57 58 /** 59 * <p>Replies the projected east/north coordinates.</p> 60 * 61 * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. 62 * Internally caches the projected coordinates.</p> 63 * 64 * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must 65 * {@link #reproject() trigger a reprojection} or {@link #invalidateEastNorthCache() invalidate the internal cache}.</p> 66 * 67 * @return the east north coordinates or {@code null} 68 * @see #invalidateEastNorthCache() 69 * 70 */ 37 71 public final EastNorth getEastNorth() { 38 return coor.getEastNorth(); 72 if (Double.isNaN(east) || Double.isNaN(north)) { 73 // projected coordinates haven't been calculated yet, 74 // so fill the cache of the projected waypoint coordinates 75 EastNorth en = Projections.project(new LatLon(lat, lon)); 76 this.east = en.east(); 77 this.north = en.north(); 78 } 79 return new EastNorth(east, north); 39 80 } 40 81 41 82 @Override 42 83 public String toString() { 43 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + coor.toString() + ", " + attr + ")";84 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + getCoor().toString() + ", " + attr + ")"; 44 85 } 45 86 … … 57 98 } 58 99 59 public int compareTo(WayPoint w) 60 { 100 public int compareTo(WayPoint w) { 61 101 return Double.compare(time, w.time); 62 102 }
Note:
See TracChangeset
for help on using the changeset viewer.