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.awt.Color;
|
---|
7 | import java.util.Date;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.coor.CachedLatLon;
|
---|
10 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.tools.PrimaryDateParser;
|
---|
13 |
|
---|
14 | public class WayPoint extends WithAttributes implements Comparable<WayPoint> {
|
---|
15 |
|
---|
16 | private static ThreadLocal<PrimaryDateParser> dateParser = new ThreadLocal<PrimaryDateParser>() {
|
---|
17 | @Override protected PrimaryDateParser initialValue() {
|
---|
18 | return new PrimaryDateParser();
|
---|
19 | }
|
---|
20 | };
|
---|
21 |
|
---|
22 | public double time;
|
---|
23 | public Color customColoring;
|
---|
24 | public boolean drawLine;
|
---|
25 | public int dir;
|
---|
26 |
|
---|
27 | public WayPoint(LatLon ll) {
|
---|
28 | coor = new CachedLatLon(ll);
|
---|
29 | }
|
---|
30 |
|
---|
31 | private final CachedLatLon coor;
|
---|
32 |
|
---|
33 | public final LatLon getCoor() {
|
---|
34 | return coor;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public final EastNorth getEastNorth() {
|
---|
38 | return coor.getEastNorth();
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public String toString() {
|
---|
43 | return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + coor.toString() + ", " + attr + ")";
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Convert the time stamp of the waypoint into seconds from the epoch
|
---|
48 | */
|
---|
49 | public void setTime() {
|
---|
50 | if(attr.containsKey("time")) {
|
---|
51 | try {
|
---|
52 | time = dateParser.get().parse(attr.get("time").toString()).getTime() / 1000.; /* ms => seconds */
|
---|
53 | } catch(Exception e) {
|
---|
54 | time = 0;
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public int compareTo(WayPoint w)
|
---|
60 | {
|
---|
61 | return Double.compare(time, w.time);
|
---|
62 | }
|
---|
63 |
|
---|
64 | public Date getTime() {
|
---|
65 | return new Date((long) (time * 1000));
|
---|
66 | }
|
---|
67 | }
|
---|