From: Keith Packard Date: Wed, 22 Jan 2014 04:59:06 +0000 (-0800) Subject: Merge remote-tracking branch 'origin/master' X-Git-Tag: 1.3.1~8 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=13cf4000bd53ac4af66231d56e24c9eb11178a5f;hp=99fedbf0ed42a5d4fa80f094576ca0260040ef5e Merge remote-tracking branch 'origin/master' --- diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index d714e13c..105afade 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -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); diff --git a/altosui/AltosSiteMapCache.java b/altosui/AltosSiteMapCache.java index 40c8ff6b..03dc3cf5 100644 --- a/altosui/AltosSiteMapCache.java +++ b/altosui/AltosSiteMapCache.java @@ -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; } diff --git a/altosui/AltosSiteMapPreload.java b/altosui/AltosSiteMapPreload.java index fd648abc..66399557 100644 --- a/altosui/AltosSiteMapPreload.java +++ b/altosui/AltosSiteMapPreload.java @@ -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 +} diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 50c5baab..5d459947 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -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"))