1 | //License: GPLv2 or later
|
---|
2 | //Copyright 2007 by Raphael Mack and others
|
---|
3 |
|
---|
4 | package org.openstreetmap.josm.data.gpx;
|
---|
5 |
|
---|
6 | import java.text.ParsePosition;
|
---|
7 | import java.text.SimpleDateFormat;
|
---|
8 | import java.util.Date;
|
---|
9 | import java.awt.Color;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 |
|
---|
15 | public class WayPoint extends WithAttributes implements Comparable<WayPoint>
|
---|
16 | {
|
---|
17 | public final LatLon latlon;
|
---|
18 | public final EastNorth eastNorth;
|
---|
19 | public double time;
|
---|
20 | public Color speedLineColor;
|
---|
21 | public boolean drawLine;
|
---|
22 | public int dir;
|
---|
23 |
|
---|
24 | public WayPoint(LatLon ll) {
|
---|
25 | latlon = ll;
|
---|
26 | eastNorth = Main.proj.latlon2eastNorth(ll);
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public String toString() {
|
---|
31 | return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")";
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Convert the time stamp of the waypoint into seconds from the epoch
|
---|
36 | */
|
---|
37 | public void setTime() {
|
---|
38 | if (! attr.containsKey("time")) {
|
---|
39 | return;
|
---|
40 | }
|
---|
41 | SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone
|
---|
42 | Date d = f.parse(attr.get("time").toString(), new ParsePosition(0));
|
---|
43 | if (d != null /* parsing ok */) {
|
---|
44 | time = d.getTime() / 1000.0; /* ms => seconds */
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Convert a time stamp of the waypoint from the <cmt> or <desc> field
|
---|
50 | * into seconds from the epoch. Handles the date format as it is used by
|
---|
51 | * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0).
|
---|
52 | * A value of <time> fields overwrites values set with by method.
|
---|
53 | * Does nothing if specified key does not exist or text cannot be parsed.
|
---|
54 | *
|
---|
55 | * @param key The key that contains the text to convert.
|
---|
56 | */
|
---|
57 | public void setGarminCommentTime(String key) {
|
---|
58 | // do not overwrite time if already set
|
---|
59 | if (time != 0.0) {
|
---|
60 | return;
|
---|
61 | }
|
---|
62 | if (! attr.containsKey(key)) {
|
---|
63 | return;
|
---|
64 | }
|
---|
65 | // example date format "18-AUG-08 13:33:03"
|
---|
66 | SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone
|
---|
67 | Date d = f.parse(attr.get(key).toString(), new ParsePosition(0));
|
---|
68 | if (d != null /* parsing OK */) {
|
---|
69 | time = d.getTime() / 1000.0; /* ms => seconds */
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public int compareTo(WayPoint w)
|
---|
74 | {
|
---|
75 | return Double.compare(time, w.time);
|
---|
76 | }
|
---|
77 | }
|
---|