altosui: Add speed and gps height to map display data
[fw/altos] / altosuilib / AltosUIMap.java
index 3fb33d4a221a88ebd11f5aa89dd15ec4cd6dac75..5b981d14e6113f2fa9d24c5a3616168295329c9d 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);
@@ -106,7 +107,7 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                }
 
                private boolean is_drag_event(MouseEvent e) {
-                       return e.getModifiers() == InputEvent.BUTTON1_MASK;
+                       return e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK;
                }
 
                /* MouseMotionListener methods */
@@ -115,7 +116,61 @@ 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) {
+                       if (p == AltosLib.MISSING)
+                               return "";
+                       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);
+               }
+
+               String height(double h, String label) {
+                       if (h == AltosLib.MISSING)
+                               return "";
+                       return String.format(" %s%s",
+                                            AltosConvert.height.show(6, h),
+                                            label);
+               }
+
+               String speed(double s, String label) {
+                       if (s == AltosLib.MISSING)
+                               return "";
+                       return String.format(" %s%s",
+                                            AltosConvert.speed.show(6, s),
+                                            label);
+               }
+
                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.gps.lat,
+                                                           point.gps.lon,
+                                                           point.state);
+                       else {
+                               nearest_mark.lat_lon.lat = point.gps.lat;
+                               nearest_mark.lat_lon.lon = point.gps.lon;
+                               nearest_mark.state = point.state;
+                       }
+                       if (point != null) {
+                               nearest_label.setText(String.format("%9.2f sec %s%s%s%s",
+                                                                   point.time,
+                                                                   pos(point.gps.lat,
+                                                                       "N", "S"),
+                                                                   pos(point.gps.lon,
+                                                                       "E", "W"),
+                                                                   height(point.gps_height, ""),
+                                                                   speed(point.gps.ground_speed, "(h)"),
+                                                                   speed(point.gps.climb_rate, "(v)")));
+                       } else {
+                               nearest_label.setText("");
+                       }
+                       repaint();
                }
 
                /* MouseListener methods */
@@ -222,7 +277,7 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                        g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
 
                        for (AltosMapPathPoint point : points) {
-                               Point2D.Double  cur = point2d(t.screen(point.lat_lon));
+                               Point2D.Double  cur = point2d(t.screen(point.gps.lat, point.gps.lon));
                                if (prev != null) {
                                        Line2D.Double   line = new Line2D.Double (prev, cur);
                                        Rectangle       bounds = line.getBounds();
@@ -264,6 +319,21 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
 
                        if (image != null) {
                                g.drawImage(image, point.x, point.y, null);
+/*
+ * Useful when debugging map fetching problems
+ *
+                               String message = String.format("%.6f %.6f", center.lat, center.lon);
+                               g.setFont(tile_font);
+                               g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+                               Rectangle2D bounds = tile_font.getStringBounds(message, g.getFontRenderContext());
+
+                               float x = px_size / 2.0f;
+                               float y = px_size / 2.0f;
+                               x = x - (float) bounds.getWidth() / 2.0f;
+                               y = y + (float) bounds.getHeight() / 2.0f;
+                               g.setColor(Color.RED);
+                               g.drawString(message, (float) point_double.x + x, (float) point_double.y + y);
+*/
                        } else {
                                g.setColor(Color.GRAY);
                                g.fillRect(point.x, point.y, px_size, px_size);
@@ -281,7 +351,7 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                                                message = "Network error";
                                                break;
                                        case AltosMapTile.forbidden:
-                                               message = "Outside of launch area";
+                                               message = "Outside of known launch areas";
                                                break;
                                        }
                                        if (message != null && tile_font != null) {
@@ -372,6 +442,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) {
@@ -385,9 +457,13 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
 
        JLabel  zoom_label;
 
+       JLabel  nearest_label;
+
        public void set_maptype(int type) {
+/*
                map.set_maptype(type);
                maptype_combo.setSelectedIndex(type);
+*/
        }
 
        /* AltosUIMapPreload functions */
@@ -413,8 +489,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, double gps_height) {
+               map.show(gps, time, state, gps_height);
        }
 
        public String getName() {
@@ -433,7 +509,9 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
        /* internal layout bits */
        private GridBagLayout layout = new GridBagLayout();
 
+/*
        JComboBox<String>       maptype_combo;
+*/
 
        MapView view;
 
@@ -522,6 +600,21 @@ 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);
 
                maptype_combo.setEditable(false);
@@ -540,7 +633,7 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                c.weightx = 0;
                c.weighty = 0;
                add(maptype_combo, c);
-
+*/
                map = new AltosMap(this);
        }
 }