summaryrefslogtreecommitdiff
path: root/altosui/AltosSiteMap.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-07-16 16:37:40 -0700
committerKeith Packard <keithp@keithp.com>2011-07-16 20:47:32 -0700
commit225073fd822f9861a83d65386c29fda9b37bf273 (patch)
tree038023b19c35004f1a11579642b3f875394cf394 /altosui/AltosSiteMap.java
parentcbd14ba103ee5e3c5eec18e3a4ff13c320b98634 (diff)
altosui: Add map preloading GUI
Provide a way to manually enter latitude and longitude, preview the map area while downloading a 9x9 grid of map tiles to be used when monitoring flights without network access. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosSiteMap.java')
-rw-r--r--altosui/AltosSiteMap.java59
1 files changed, 43 insertions, 16 deletions
diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java
index 7575c10e..73068138 100644
--- a/altosui/AltosSiteMap.java
+++ b/altosui/AltosSiteMap.java
@@ -150,10 +150,13 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
//System.out.printf("Loading/fetching map %s\n", pngfile);
Thread thread = new Thread() {
public void run() {
- ImageIcon res;
- res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl);
+ final ImageIcon res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl);
if (res != null) {
- tile.loadMap(res);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ tile.loadMap(res);
+ }
+ });
} else {
System.out.printf("# Failed to fetch file %s\n", pngfile);
System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl);
@@ -163,6 +166,24 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
thread.start();
}
+ File pngfile;
+ String pngurl;
+
+ public int prefetchMap(int x, int y) {
+ LatLng map_latlng = latlng(
+ -centre.x + x*px_size + px_size/2,
+ -centre.y + y*px_size + px_size/2);
+ pngfile = MapFile(map_latlng.lat, map_latlng.lng);
+ pngurl = MapURL(map_latlng.lat, map_latlng.lng);
+ if (pngfile.exists()) {
+ return 1;
+ } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+
public static void prefetchMaps(double lat, double lng, int w, int h) {
AltosSiteMap asm = new AltosSiteMap(true);
asm.centre = asm.getBaseLocation(lat, lng);
@@ -172,18 +193,18 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
int dx = -w/2, dy = -h/2;
for (int y = dy; y < h+dy; y++) {
for (int x = dx; x < w+dx; x++) {
- LatLng map_latlng = asm.latlng(
- -asm.centre.x + x*px_size + px_size/2,
- -asm.centre.y + y*px_size + px_size/2);
- File pngfile = asm.MapFile(map_latlng.lat, map_latlng.lng);
- String pngurl = asm.MapURL(map_latlng.lat, map_latlng.lng);
- if (pngfile.exists()) {
- System.out.printf("Already have %s\n", pngfile);
- } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) {
- System.out.printf("Fetched map %s\n", pngfile);
- } else {
- System.out.printf("# Failed to fetch file %s\n", pngfile);
- System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl);
+ int r = asm.prefetchMap(x, y);
+ switch (r) {
+ case 1:
+ System.out.printf("Already have %s\n", asm.pngfile);
+ break;
+ case 0:
+ System.out.printf("Fetched map %s\n", asm.pngfile);
+ break;
+ case -1:
+ System.out.printf("# Failed to fetch file %s\n", asm.pngfile);
+ System.out.printf(" wget -O '%s' ''\n", asm.pngfile, asm.pngurl);
+ break;
}
}
}
@@ -224,6 +245,12 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
boolean initialised = false;
Point2D.Double last_pt = null;
int last_state = -1;
+
+ public void show(double lat, double lon) {
+ initMaps(lat, lon);
+ initialised = true;
+ scrollRocketToVisible(pt(lat, lon));
+ }
public void show(final AltosState state, final int crc_errors) {
// if insufficient gps data, nothing to update
if (!state.gps.locked && state.gps.nsat < 4)
@@ -382,6 +409,6 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
}
}
setViewportView(comp);
- setPreferredSize(new Dimension(500,200));
+ setPreferredSize(new Dimension(500,500));
}
}