Merge remote-tracking branch 'origin/master'
authorKeith Packard <keithp@keithp.com>
Wed, 22 Jan 2014 04:59:06 +0000 (20:59 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 22 Jan 2014 04:59:06 +0000 (20:59 -0800)
altosui/AltosSiteMap.java
altosui/AltosSiteMapCache.java
altosui/AltosSiteMapPreload.java
altosui/AltosUI.java

index d714e13c68cbf6f479f522ccc7339f8a5c430165..105afade192ed206b3fcde8f3c688231b4da3ba8 100644 (file)
@@ -182,7 +182,9 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
                }
        }
 
-       public static void prefetchMaps(double lat, double lng, int w, int h) {
+       public static void prefetchMaps(double lat, double lng) {
+               int w = AltosSiteMapPreload.width;
+               int h = AltosSiteMapPreload.height;
                AltosSiteMap asm = new AltosSiteMap(true);
                asm.centre = asm.getBaseLocation(lat, lng);
 
index 40c8ff6bf0dc078beff6f8b5016f8910ffe2f4c4..03dc3cf5d67ebc8a3170d863d8557c75258452c1 100644 (file)
@@ -25,8 +25,13 @@ import java.net.URL;
 import java.net.URLConnection;
 
 public class AltosSiteMapCache extends JLabel {
+       static final long google_maps_ratelimit_ms = 1200;
+       // Google limits static map queries to 50 per minute per IP, so
+       // each query should take at least 1.2 seconds.
+
        public static boolean fetchMap(File file, String url) {
                URL u;
+               long startTime = System.nanoTime();
 
                try {
                        u = new URL(url);
@@ -70,6 +75,16 @@ public class AltosSiteMapCache extends JLabel {
                        }
                        return false;
                }
+
+               long duration_ms = (System.nanoTime() - startTime) / 1000000;
+               if (duration_ms < google_maps_ratelimit_ms) {
+                       try {
+                               Thread.sleep(google_maps_ratelimit_ms - duration_ms);
+                       } catch (InterruptedException e) {
+                               Thread.currentThread().interrupt();
+                       }
+               }
+
                return true;
        }
 
index fd648abccc2424d5bad08c2ee7c9f85e08796bf7..66399557e6813289da168fd511bcc711a84e442f 100644 (file)
@@ -213,7 +213,7 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener
        AltosMapPos     lat;
        AltosMapPos     lon;
 
-       final static int        radius = 4;
+       final static int        radius = 5;
        final static int        width = (radius * 2 + 1);
        final static int        height = (radius * 2 + 1);
 
@@ -326,7 +326,7 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener
 
                pane.setLayout(new GridBagLayout());
 
-               map = new AltosSiteMap(4);
+               map = new AltosSiteMap(radius);
 
                c.fill = GridBagConstraints.BOTH;
                c.anchor = GridBagConstraints.CENTER;
@@ -464,4 +464,4 @@ public class AltosSiteMapPreload extends AltosUIDialog implements ActionListener
                setLocationRelativeTo(owner);
                setVisible(true);
        }
-}
\ No newline at end of file
+}
index 50c5baabcd92146527d2b483bdf58721513b397e..5d4599476ba44bd988e0b57a1f792fe12fd5dd6f 100644 (file)
@@ -574,7 +574,7 @@ public class AltosUI extends AltosUIFrame {
                                        } else {
                                                double lat = Double.parseDouble(args[i+1]);
                                                double lon = Double.parseDouble(args[i+2]);
-                                               AltosSiteMap.prefetchMaps(lat, lon, 5, 5);
+                                               AltosSiteMap.prefetchMaps(lat, lon);
                                                i += 2;
                                        }
                                } else if (args[i].equals("--replay"))