- //System.out.printf("Loading/fetching map %s\n", pngfile);
- Thread thread = new Thread() {
- public void run() {
- ImageIcon res;
- res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl);
- if (res != null) {
- tile.loadMap(res);
- } else {
- System.out.printf("# Failed to fetch file %s\n", pngfile);
- System.out.printf(" wget -O '%s' ''\n", pngfile, pngurl);
- }
- }
- };
- thread.start();
+ final ImageIcon res = AltosSiteMapCache.fetchAndLoadMap(pngfile, pngurl);
+ if (res != null) {
+ 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' '%s'\n", pngfile, pngurl);
+ }
+ }
+
+ 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, zoom);
+ pngurl = MapURL(map_latlng.lat, map_latlng.lng, zoom);
+ if (pngfile.exists()) {
+ return 1;
+ } else if (AltosSiteMapCache.fetchMap(pngfile, pngurl)) {
+ return 0;
+ } else {
+ return -1;
+ }