source: osm/applications/editors/josm/plugins/livegps/src/LiveGpsData.java@ 14003

Last change on this file since 14003 was 13497, checked in by skela, 17 years ago

applications/editors/josm: Set svn:eol-style native on all *.java files
in plugins. Normalize the eol-style in
plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java.

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1/**
2 *
3 */
4package livegps;
5
6import java.awt.Point;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.coor.EastNorth;
10import org.openstreetmap.josm.data.coor.LatLon;
11import org.openstreetmap.josm.data.osm.Way;
12
13/**
14 * @author cdaller
15 *
16 */
17public class LiveGpsData {
18 private LatLon latLon;
19 private float course;
20 private float speed;
21 private boolean fix;
22 private String wayString;
23 private Way way;
24
25 /**
26 * @param latitude
27 * @param longitude
28 * @param course
29 * @param speed
30 * @param haveFix
31 */
32 public LiveGpsData(double latitude, double longitude, float course, float speed, boolean haveFix) {
33 super();
34 this.latLon = new LatLon(latitude, longitude);
35 this.course = course;
36 this.speed = speed;
37 this.fix = haveFix;
38 }
39 /**
40 *
41 */
42 public LiveGpsData() {
43 // TODO Auto-generated constructor stub
44 }
45 /**
46 * @return the course
47 */
48 public float getCourse() {
49 return this.course;
50 }
51 /**
52 * @param course the course to set
53 */
54 public void setCourse(float course) {
55 this.course = course;
56 }
57 /**
58 * @return the haveFix
59 */
60 public boolean isFix() {
61 return this.fix;
62 }
63 /**
64 * @param haveFix the haveFix to set
65 */
66 public void setFix(boolean haveFix) {
67 this.fix = haveFix;
68 }
69 /**
70 * @return the latitude
71 */
72 public double getLatitude() {
73 return this.latLon.lat();
74 }
75 /**
76 * @return the longitude
77 */
78 public double getLongitude() {
79 return this.latLon.lon();
80 }
81 /**
82 * @return the speed in metres per second!
83 */
84 public float getSpeed() {
85 return this.speed;
86 }
87 /**
88 * @param speed the speed to set
89 */
90 public void setSpeed(float speed) {
91 this.speed = speed;
92 }
93
94 /**
95 * @return the latlon
96 */
97 public LatLon getLatLon() {
98 return this.latLon;
99 }
100
101 /**
102 * @param latLon
103 */
104 public void setLatLon(LatLon latLon) {
105 this.latLon = latLon;
106 }
107
108 public String toString() {
109 return getClass().getSimpleName() + "[fix=" + fix + ", lat=" + latLon.lat()
110 + ", long=" + latLon.lon() + ", speed=" + speed + ", course=" + course + "]";
111
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("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) {
165 EastNorth eastnorth = Main.proj.latlon2eastNorth(getLatLon());
166 Point xy = Main.map.mapView.getPoint(eastnorth);
167 way = Main.map.mapView.getNearestWay(xy);
168 }
169 return way;
170
171 }
172
173 /* (non-Javadoc)
174 * @see java.lang.Object#hashCode()
175 */
176 @Override
177 public int hashCode() {
178 final int prime = 31;
179 int result = 1;
180 result = prime * result + Float.floatToIntBits(this.course);
181 result = prime * result + ((this.latLon == null) ? 0 : this.latLon.hashCode());
182 result = prime * result + Float.floatToIntBits(this.speed);
183 return result;
184 }
185 /* (non-Javadoc)
186 * @see java.lang.Object#equals(java.lang.Object)
187 */
188 @Override
189 public boolean equals(Object obj) {
190 if (this == obj)
191 return true;
192 if (obj == null)
193 return false;
194 if (getClass() != obj.getClass())
195 return false;
196 final LiveGpsData other = (LiveGpsData) obj;
197 if (Float.floatToIntBits(this.course) != Float.floatToIntBits(other.course))
198 return false;
199 if (this.latLon == null) {
200 if (other.latLon != null)
201 return false;
202 } else if (!this.latLon.equals(other.latLon))
203 return false;
204 if (Float.floatToIntBits(this.speed) != Float.floatToIntBits(other.speed))
205 return false;
206 return true;
207 }
208
209
210
211}
Note: See TracBrowser for help on using the repository browser.