return false;
}
- public void show(AltosGPS gps, int state) {
+ public void show(AltosGPS gps, double time, int state) {
/*
* If insufficient gps data, nothing to update
}
if (path != null) {
- AltosMapRectangle damage = path.add(gps.lat, gps.lon, state);
+ AltosMapRectangle damage = path.add(gps.lat, gps.lon, time, state);
if (damage != null)
repaint(damage, AltosMapPath.stroke_width);
}
public void show(AltosState state, AltosListenerState listener_state) {
- show(state.gps, state.state());
+ show(state.gps, state.time, state.state());
}
public void centre(AltosLatLon lat_lon) {
centre(lat_lon);
}
- public void add_mark(double lat, double lon, int state) {
+ public AltosMapMark add_mark(double lat, double lon, int state) {
+ AltosMapMark mark;
synchronized(marks) {
- AltosMapMark mark = map_interface.new_mark(lat, lon, state);
+ mark = map_interface.new_mark(lat, lon, state);
if (mark != null)
marks.add(mark);
}
repaint();
+ return mark;
+ }
+
+ public void del_mark(AltosMapMark mark) {
+ marks.remove(mark);
}
public void clear_marks() {
drag_stop(x, y);
}
+ public AltosMapPathPoint nearest(int x, int y) {
+ notice_user_input();
+ if (path == null)
+ return null;
+ AltosLatLon at = transform.screen_lat_lon(new AltosPointInt(x, y));
+ return path.nearest(at);
+ }
+
public AltosMap(AltosMapInterface map_interface, int scale) {
this.map_interface = map_interface;
this.scale = scale;
public abstract void paint(AltosMapTransform t);
- public AltosMapRectangle add(double lat, double lon, int state) {
- AltosMapPathPoint point = new AltosMapPathPoint(new AltosLatLon (lat, lon), state);
+ public AltosMapRectangle add(double lat, double lon, double time, int state) {
+ AltosMapPathPoint point = new AltosMapPathPoint(new AltosLatLon (lat, lon), time, state);
AltosMapRectangle rect = null;
if (!point.equals(last_point)) {
return rect;
}
+ private double dist(AltosLatLon lat_lon, AltosMapPathPoint point) {
+ return (new AltosGreatCircle(lat_lon.lat,
+ lat_lon.lon,
+ point.lat_lon.lat,
+ point.lat_lon.lon)).distance;
+ }
+
+ public AltosMapPathPoint nearest(AltosLatLon lat_lon) {
+ AltosMapPathPoint nearest = null;
+ double nearest_dist = 0;
+ for (AltosMapPathPoint point : points) {
+ if (nearest == null) {
+ nearest = point;
+ nearest_dist = dist(lat_lon, point);
+ } else {
+ double d = dist(lat_lon, point);
+ if (d < nearest_dist) {
+ nearest = point;
+ nearest_dist = d;
+ }
+ }
+ }
+ return nearest;
+ }
+
public void clear () {
points = new LinkedList<AltosMapPathPoint>();
}
public class AltosMapPathPoint {
public AltosLatLon lat_lon;
+ public double time;
public int state;
public int hashCode() {
return lat_lon.equals(other.lat_lon) && state == other.state;
}
- public AltosMapPathPoint(AltosLatLon lat_lon, int state) {
+ public AltosMapPathPoint(AltosLatLon lat_lon, double time, int state) {
this.lat_lon = lat_lon;
+ this.time = time;
this.state = state;
}
}
gps.nsat >= 4) {
if (map == null)
map = new AltosUIMap();
- map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+ map.show(gps, gtv. time, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
this.gps = gps;
gtv_last = gtv;
has_gps = true;
if (gtv_last != null) {
int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
if (state == AltosLib.ao_flight_landed)
- map.show(gtv_last.gps, state);
+ map.show(gtv_last.gps, gtv_last.time, state);
}
}
Graphics2D g;
Font tile_font;
Font line_font;
+ AltosMapMark nearest_mark;
static Point2D.Double point2d(AltosPointDouble pt) {
return new Point2D.Double(pt.x, pt.y);
map.touch_continue(e.getPoint().x, e.getPoint().y, is_drag_event(e));
}
+ String pos(double p, String pos, String neg) {
+ String h = pos;
+ if (p < 0) {
+ h = neg;
+ p = -p;
+ }
+ int deg = (int) Math.floor(p);
+ double min = (p - Math.floor(p)) * 60.0;
+ return String.format("%s %4d° %9.6f'", h, deg, min);
+ }
+
public void mouseMoved(MouseEvent e) {
+ AltosMapPathPoint point = map.nearest(e.getPoint().x, e.getPoint().y);
+
+ if (nearest_mark == null)
+ nearest_mark = map.add_mark(point.lat_lon.lat,
+ point.lat_lon.lon,
+ point.state);
+ else {
+ nearest_mark.lat_lon.lat = point.lat_lon.lat;
+ nearest_mark.lat_lon.lon = point.lat_lon.lon;
+ nearest_mark.state = point.state;
+ }
+ if (point != null) {
+ nearest_label.setText(String.format("Time: %9.2f Position: %s %s",
+ point.time,
+ pos(point.lat_lon.lat,
+ "N", "S"),
+ pos(point.lat_lon.lon,
+ "E", "W")));
+ } else {
+ nearest_label.setText("");
+ }
+ repaint();
}
/* MouseListener methods */
public void set_font() {
tile_font = AltosUILib.value_font;
line_font = AltosUILib.status_font;
+ if (nearest_label != null)
+ nearest_label.setFont(AltosUILib.value_font);
}
public void font_size_changed(int font_size) {
JLabel zoom_label;
+ JLabel nearest_label;
+
public void set_maptype(int type) {
/*
map.set_maptype(type);
map.show(state, listener_state);
}
- public void show(AltosGPS gps, int state) {
- map.show(gps, state);
+ public void show(AltosGPS gps, double time, int state) {
+ map.show(gps, time, state);
}
public String getName() {
c.weighty = 0;
add(zoom_out, c);
+
+ nearest_label = new JLabel("", JLabel.LEFT);
+ nearest_label.setFont(tile_font);
+
+ c = new GridBagConstraints();
+ c.anchor = GridBagConstraints.CENTER;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.gridx = 0;
+ c.gridy = 11;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.gridwidth = 1;
+ c.gridheight = 1;
+ add(nearest_label, c);
/*
maptype_combo = new JComboBox<String>(map.maptype_labels);