AltosSiteMapTile: draw boost circle as well as landed
[fw/altos] / ao-tools / altosui / AltosSiteMapTile.java
index ca68412a98de58ddb9a4c72e31eb2aa56933d5e3..6035a7940e7cb8507751ce813fd712c2daf82ff6 100644 (file)
@@ -37,7 +37,7 @@ public class AltosSiteMapTile extends JLayeredPane {
     Point2D.Double coord_pt;
     Point2D.Double last_pt;
 
-    JLabel mapLabel;
+    AltosSiteMapLabel mapLabel;
     JLabel draw;
     Graphics2D g2d;
 
@@ -48,15 +48,7 @@ public class AltosSiteMapTile extends JLayeredPane {
 
     private void loadMap() {
         Point2D.Double map_latlng = latlng(px_size/2, px_size/2);
-        File pngfile = new File(AltosPreferences.logdir(), 
-                                FileCoord(map_latlng, zoom));
-        try {
-            mapLabel.setIcon(new ImageIcon(ImageIO.read(pngfile)));
-        } catch (Exception e) { 
-            // throw new RuntimeException(e);
-            System.out.printf("# Failed to find file %s\n", pngfile);
-            System.out.printf(" wget -O '%s' 'http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32'\n", pngfile, map_latlng.x, map_latlng.y, zoom, px_size, px_size);
-        }
+        mapLabel.loadMap(map_latlng.x, map_latlng.y, zoom, px_size);
     }
 
     private boolean setLocation(double lat, double lng) {
@@ -88,22 +80,6 @@ public class AltosSiteMapTile extends JLayeredPane {
         return v;
     }
 
-    private static String FileCoord(Point2D.Double latlng, int zoom) {
-        double lat, lng;
-        lat = latlng.x;
-        lng = latlng.y;
-        return FileCoord(lat, lng, zoom);
-    }
-    private static String FileCoord(double lat, double lng, int zoom) {
-        char chlat = lat < 0 ? 'S' : 'N';
-        char chlng = lng < 0 ? 'E' : 'W';
-        if (lat < 0) lat = -lat;
-        if (lng < 0) lng = -lng;
-        return String.format("map-%c%.6f,%c%.6f-%d.png",
-                chlat, lat, chlng, lng, zoom);
-    }
-
-
     // based on google js
     //  http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js
     // search for fromLatLngToPoint and fromPointToLatLng
@@ -161,6 +137,7 @@ public class AltosSiteMapTile extends JLayeredPane {
     };
 
     boolean drawn_landed_circle = false;
+    boolean drawn_boost_circle = false;
     public void show(AltosState state, int crc_errors) {
         if (!state.gps_ready) {
             if (state.pad_lat == 0 && state.pad_lon == 0)
@@ -172,7 +149,7 @@ public class AltosSiteMapTile extends JLayeredPane {
         if (last_pt == null) {
             setLocation(state.pad_lat, state.pad_lon);
             loadMap();
-            last_pt = pt;
+            last_pt = pt(state.pad_lat, state.pad_lon);
         }
 
         Point2D.Double pt = pt(state.gps.lat, state.gps.lon);
@@ -196,9 +173,16 @@ public class AltosSiteMapTile extends JLayeredPane {
             }
         }
 
+        if (state.state == 3 && !drawn_boost_circle) {
+            drawn_boost_circle = true;
+            g2d.setColor(Color.RED);
+            g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10);
+            g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40);
+            g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70);
+        }
         if (state.state == 8 && !drawn_landed_circle) {
             drawn_landed_circle = true;
-            g2d.setColor(Color.RED);
+            g2d.setColor(Color.BLACK);
             g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10);
             g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40);
             g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70);
@@ -221,7 +205,7 @@ public class AltosSiteMapTile extends JLayeredPane {
     public AltosSiteMapTile(int x_tile_offset, int y_tile_offset) {
         setPreferredSize(new Dimension(px_size, px_size));
 
-        mapLabel = new JLabel();
+        mapLabel = new AltosSiteMapLabel();
         fillLabel(mapLabel, Color.GRAY);
         mapLabel.setOpaque(true);
         mapLabel.setBounds(0, 0, px_size, px_size);