altosui: Display data for point nearest cursor in map view
authorKeith Packard <keithp@keithp.com>
Sun, 1 Sep 2019 04:20:31 +0000 (23:20 -0500)
committerKeith Packard <keithp@keithp.com>
Sun, 1 Sep 2019 04:20:31 +0000 (23:20 -0500)
Include time, lat and lon

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMap.java
altoslib/AltosMapPath.java
altoslib/AltosMapPathPoint.java
altosui/AltosGraphUI.java
altosuilib/AltosUIMap.java

index b033cbf..b9c4bfc 100644 (file)
@@ -222,7 +222,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                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
@@ -250,7 +250,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                }
 
                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);
@@ -262,7 +262,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
        }
 
        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) {
@@ -290,13 +290,19 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        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() {
@@ -490,6 +496,14 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        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;
index 7104b2f..54ff51f 100644 (file)
@@ -32,8 +32,8 @@ public abstract class AltosMapPath {
 
        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)) {
@@ -45,6 +45,31 @@ public abstract class AltosMapPath {
                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>();
        }
index 9a1edd4..c23d856 100644 (file)
@@ -25,6 +25,7 @@ import java.util.concurrent.*;
 
 public class AltosMapPathPoint {
        public AltosLatLon      lat_lon;
+       public double           time;
        public int              state;
 
        public int hashCode() {
@@ -43,8 +44,9 @@ public class AltosMapPathPoint {
                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;
        }
 }
index 59b06c1..c1e18ac 100644 (file)
@@ -54,7 +54,7 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt
                                    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;
@@ -64,7 +64,7 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt
                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);
                }
        }
 
index 8dfdba6..6b78c35 100644 (file)
@@ -36,6 +36,7 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
        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);
@@ -115,7 +116,40 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                        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 */
@@ -387,6 +421,8 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
        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) {
@@ -400,6 +436,8 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
 
        JLabel  zoom_label;
 
+       JLabel  nearest_label;
+
        public void set_maptype(int type) {
 /*
                map.set_maptype(type);
@@ -430,8 +468,8 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                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() {
@@ -541,6 +579,20 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                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);