1 | /**
|
---|
2 | *
|
---|
3 | */
|
---|
4 | package livegps;
|
---|
5 |
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
7 |
|
---|
8 | import java.awt.Point;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.data.osm.Way;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * @author cdaller
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class LiveGpsData {
|
---|
19 | private LatLon latLon;
|
---|
20 | private float course;
|
---|
21 | private float speed;
|
---|
22 | private boolean fix;
|
---|
23 | private String wayString;
|
---|
24 | private Way way;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * @param latitude
|
---|
28 | * @param longitude
|
---|
29 | * @param course
|
---|
30 | * @param speed
|
---|
31 | * @param haveFix
|
---|
32 | */
|
---|
33 | public LiveGpsData(double latitude, double longitude, float course, float speed, boolean haveFix) {
|
---|
34 | super();
|
---|
35 | this.latLon = new LatLon(latitude, longitude);
|
---|
36 | this.course = course;
|
---|
37 | this.speed = speed;
|
---|
38 | this.fix = haveFix;
|
---|
39 | }
|
---|
40 | /**
|
---|
41 | *
|
---|
42 | */
|
---|
43 | public LiveGpsData() {
|
---|
44 | // TODO Auto-generated constructor stub
|
---|
45 | }
|
---|
46 | /**
|
---|
47 | * @return the course
|
---|
48 | */
|
---|
49 | public float getCourse() {
|
---|
50 | return this.course;
|
---|
51 | }
|
---|
52 | /**
|
---|
53 | * @param course the course to set
|
---|
54 | */
|
---|
55 | public void setCourse(float course) {
|
---|
56 | this.course = course;
|
---|
57 | }
|
---|
58 | /**
|
---|
59 | * @return the haveFix
|
---|
60 | */
|
---|
61 | public boolean isFix() {
|
---|
62 | return this.fix;
|
---|
63 | }
|
---|
64 | /**
|
---|
65 | * @param haveFix the haveFix to set
|
---|
66 | */
|
---|
67 | public void setFix(boolean haveFix) {
|
---|
68 | this.fix = haveFix;
|
---|
69 | }
|
---|
70 | /**
|
---|
71 | * @return the latitude
|
---|
72 | */
|
---|
73 | public double getLatitude() {
|
---|
74 | return this.latLon.lat();
|
---|
75 | }
|
---|
76 | /**
|
---|
77 | * @return the longitude
|
---|
78 | */
|
---|
79 | public double getLongitude() {
|
---|
80 | return this.latLon.lon();
|
---|
81 | }
|
---|
82 | /**
|
---|
83 | * @return the speed in metres per second!
|
---|
84 | */
|
---|
85 | public float getSpeed() {
|
---|
86 | return this.speed;
|
---|
87 | }
|
---|
88 | /**
|
---|
89 | * @param speed the speed to set
|
---|
90 | */
|
---|
91 | public void setSpeed(float speed) {
|
---|
92 | this.speed = speed;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * @return the latlon
|
---|
97 | */
|
---|
98 | public LatLon getLatLon() {
|
---|
99 | return this.latLon;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * @param latLon
|
---|
104 | */
|
---|
105 | public void setLatLon(LatLon latLon) {
|
---|
106 | this.latLon = latLon;
|
---|
107 | }
|
---|
108 |
|
---|
109 | public String toString() {
|
---|
110 | return getClass().getSimpleName() + "[fix=" + fix + ", lat=" + latLon.lat()
|
---|
111 | + ", long=" + latLon.lon() + ", speed=" + speed + ", course=" + course + "]";
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Returns the name of the way that is closest to the current coordinates or an
|
---|
116 | * empty string if no way is around.
|
---|
117 | *
|
---|
118 | * @return the name of the way that is closest to the current coordinates.
|
---|
119 | */
|
---|
120 | public String getWayInfo() {
|
---|
121 | if(wayString == null) {
|
---|
122 | Way way = getWay();
|
---|
123 | if(way != null) {
|
---|
124 | StringBuilder builder = new StringBuilder();
|
---|
125 | String tmp = way.get("name");
|
---|
126 | if(tmp != null) {
|
---|
127 | builder.append(tmp);
|
---|
128 | } else {
|
---|
129 | builder.append(tr("no name"));
|
---|
130 | }
|
---|
131 | tmp = way.get("ref");
|
---|
132 | if(tmp != null) {
|
---|
133 | builder.append(" (").append(tmp).append(")");
|
---|
134 | }
|
---|
135 | tmp = way.get("highway");
|
---|
136 | if(tmp != null) {
|
---|
137 | builder.append(" {").append(tmp).append("}");
|
---|
138 | }
|
---|
139 | String type = "";
|
---|
140 | tmp = way.get("tunnel");
|
---|
141 | if(tmp != null) {
|
---|
142 | type = type + "T";
|
---|
143 | }
|
---|
144 | tmp = way.get("bridge");
|
---|
145 | if(tmp != null) {
|
---|
146 | type = type + "B";
|
---|
147 | }
|
---|
148 | if(type.length() > 0) {
|
---|
149 | builder.append(" [").append(type).append("]");
|
---|
150 | }
|
---|
151 | wayString = builder.toString();
|
---|
152 | } else {
|
---|
153 | wayString = "";
|
---|
154 | }
|
---|
155 | }
|
---|
156 | return wayString;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Returns the closest way to this position.
|
---|
161 | * @return the closest way to this position.
|
---|
162 | */
|
---|
163 | public Way getWay() {
|
---|
164 | if(way == null && Main.map != null && Main.map.mapView != null) {
|
---|
165 | Point xy = Main.map.mapView.getPoint(getLatLon());
|
---|
166 | way = Main.map.mapView.getNearestWay(xy);
|
---|
167 | }
|
---|
168 | return way;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /* (non-Javadoc)
|
---|
172 | * @see java.lang.Object#hashCode()
|
---|
173 | */
|
---|
174 | @Override
|
---|
175 | public int hashCode() {
|
---|
176 | final int prime = 31;
|
---|
177 | int result = 1;
|
---|
178 | result = prime * result + Float.floatToIntBits(this.course);
|
---|
179 | result = prime * result + ((this.latLon == null) ? 0 : this.latLon.hashCode());
|
---|
180 | result = prime * result + Float.floatToIntBits(this.speed);
|
---|
181 | return result;
|
---|
182 | }
|
---|
183 | /* (non-Javadoc)
|
---|
184 | * @see java.lang.Object#equals(java.lang.Object)
|
---|
185 | */
|
---|
186 | @Override
|
---|
187 | public boolean equals(Object obj) {
|
---|
188 | if (this == obj)
|
---|
189 | return true;
|
---|
190 | if (obj == null)
|
---|
191 | return false;
|
---|
192 | if (getClass() != obj.getClass())
|
---|
193 | return false;
|
---|
194 | final LiveGpsData other = (LiveGpsData) obj;
|
---|
195 | if (Float.floatToIntBits(this.course) != Float.floatToIntBits(other.course))
|
---|
196 | return false;
|
---|
197 | if (this.latLon == null) {
|
---|
198 | if (other.latLon != null)
|
---|
199 | return false;
|
---|
200 | } else if (!this.latLon.equals(other.latLon))
|
---|
201 | return false;
|
---|
202 | if (Float.floatToIntBits(this.speed) != Float.floatToIntBits(other.speed))
|
---|
203 | return false;
|
---|
204 | return true;
|
---|
205 | }
|
---|
206 | }
|
---|