int zoom;
double scale_x, scale_y;
+ int radius; /* half width/height of tiles to load */
+
private Point2D.Double pt(double lat, double lng) {
return pt(new LatLng(lat, lng), scale_x, scale_y);
}
// nothing
}
- private void bgLoadMap(final AltosSiteMapTile tile,
- final File pngfile, final String pngurl)
+ private void loadMap(final AltosSiteMapTile tile,
+ File pngfile, String pngurl)
{
- //System.out.printf("Loading/fetching map %s\n", pngfile);
- Thread thread = new Thread() {
- public void run() {
- 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' ''\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;
+ 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);
+ 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)) {
}
}
- private void initMap(AltosSiteMapTile tile, Point offset) {
+ public String initMap(Point offset) {
+ AltosSiteMapTile tile = mapTiles.get(offset);
Point2D.Double coord = tileCoordOffset(offset);
LatLng map_latlng = latlng(px_size/2-coord.x, px_size/2-coord.y);
- File pngfile = MapFile(map_latlng.lat, map_latlng.lng);
- String pngurl = MapURL(map_latlng.lat, map_latlng.lng);
- bgLoadMap(tile, pngfile, pngurl);
+ File pngfile = MapFile(map_latlng.lat, map_latlng.lng, zoom);
+ String pngurl = MapURL(map_latlng.lat, map_latlng.lng, zoom);
+ loadMap(tile, pngfile, pngurl);
+ return pngfile.toString();
}
- private void initMaps(double lat, double lng) {
- centre = getBaseLocation(lat, lng);
-
+ public void setBaseLocation(double lat, double lng) {
for (Point k : mapTiles.keySet()) {
- initMap(mapTiles.get(k), k);
+ AltosSiteMapTile tile = mapTiles.get(k);
+ tile.clearMap();
}
+
+ centre = getBaseLocation(lat, lng);
+ scrollRocketToVisible(pt(lat,lng));
}
- private File MapFile(double lat, double lng) {
+ private void initMaps(double lat, double lng) {
+ setBaseLocation(lat, lng);
+
+ Thread thread = new Thread() {
+ public void run() {
+ for (Point k : mapTiles.keySet())
+ initMap(k);
+ }
+ };
+ thread.start();
+ }
+
+ private static File MapFile(double lat, double lng, int zoom) {
char chlat = lat < 0 ? 'S' : 'N';
char chlng = lng < 0 ? 'W' : 'E';
if (lat < 0) lat = -lat;
chlat, lat, chlng, lng, zoom));
}
- private String MapURL(double lat, double lng) {
+ private static String MapURL(double lat, double lng, int zoom) {
return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=hybrid&format=png32", lat, lng, zoom, px_size, px_size);
}
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) {
AltosSiteMapTile tile = createTile(offset);
tile.show(state, crc_errors, lref, ref);
- initMap(tile, offset);
+ initMap(offset);
finishTileLater(tile, offset);
}
}
private void ensureTilesAround(Point base_offset) {
- for (int x = -1; x <= 1; x++) {
- for (int y = -1; y <= 1; y++) {
+ for (int x = -radius; x <= radius; x++) {
+ for (int y = -radius; y <= radius; y++) {
Point offset = new Point(base_offset.x + x, base_offset.y + y);
if (mapTiles.containsKey(offset))
continue;
AltosSiteMapTile tile = createTile(offset);
- initMap(tile, offset);
+ initMap(offset);
finishTileLater(tile, offset);
}
}
JComponent comp = new JComponent() { };
private GridBagLayout layout = new GridBagLayout();
- public AltosSiteMap() {
+ public AltosSiteMap(int in_radius) {
+ radius = in_radius;
+
GrabNDrag scroller = new GrabNDrag(comp);
comp.setLayout(layout);
- for (int x = -1; x <= 1; x++) {
- for (int y = -1; y <= 1; y++) {
+ for (int x = -radius; x <= radius; x++) {
+ for (int y = -radius; y <= radius; y++) {
Point offset = new Point(x, y);
AltosSiteMapTile t = createTile(offset);
addTileAt(t, offset);
setViewportView(comp);
setPreferredSize(new Dimension(500,500));
}
+
+ public AltosSiteMap() {
+ this(1);
+ }
}
import java.awt.geom.Line2D;
class AltosMapPos extends Box {
+ AltosUI owner;
JLabel label;
JComboBox hemi;
JTextField deg;
public double get_value() throws NumberFormatException {
int h = hemi.getSelectedIndex();
- double d = Double.parseDouble(deg.getText());
- double m = Double.parseDouble(min.getText());
- double v = d + m/60.0;
+ String d_t = deg.getText();
+ String m_t = min.getText();
+ double d, m, v;
+ try {
+ d = Double.parseDouble(d_t);
+ } catch (NumberFormatException ne) {
+ JOptionPane.showMessageDialog(owner,
+ String.format("Invalid degrees \"%s\"",
+ d_t),
+ "Invalid number",
+ JOptionPane.ERROR_MESSAGE);
+ throw ne;
+ }
+ try {
+ if (m_t.equals(""))
+ m = 0;
+ else
+ m = Double.parseDouble(m_t);
+ } catch (NumberFormatException ne) {
+ JOptionPane.showMessageDialog(owner,
+ String.format("Invalid minutes \"%s\"",
+ m_t),
+ "Invalid number",
+ JOptionPane.ERROR_MESSAGE);
+ throw ne;
+ }
+ v = d + m/60.0;
if (h == 1)
v = -v;
return v;
}
- public AltosMapPos(String label_value,
+ public AltosMapPos(AltosUI in_owner,
+ String label_value,
String[] hemi_names,
double default_value) {
super(BoxLayout.X_AXIS);
+ owner = in_owner;
label = new JLabel(label_value);
hemi = new JComboBox(hemi_names);
hemi.setEditable(false);
deg = new JTextField("000");
- deg_label = new JLabel("degrees");
+ deg_label = new JLabel("°");
min = new JTextField("00.0000");
- min_label = new JLabel("minutes");
+ min_label = new JLabel("'");
set_value(default_value);
add(label);
add(Box.createRigidArea(new Dimension(5, 0)));
JProgressBar pbar;
- final static int width = 9;
- final static int height = 9;
- final static int tiles = width * height;
+ final static int radius = 4;
+ final static int width = (radius * 2 + 1);
+ final static int height = (radius * 2 + 1);
JToggleButton load_button;
boolean loading;
int n;
String s;
- public updatePbar(int in_n, String in_s) {
- n = in_n;
+ public updatePbar(int x, int y, String in_s) {
+ n = (x + radius) + (y + radius) * width + 1;
+ System.out.printf("update pbar %d\n", n);
s = in_s;
}
public void run() {
pbar.setValue(n);
pbar.setString(s);
- if (n == width * height) {
+ if (n < width * height) {
+ pbar.setValue(n);
+ pbar.setString(s);
+ } else {
+ pbar.setValue(0);
+ pbar.setString("");
load_button.setSelected(false);
loading = false;
}
}
public void run() {
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- map.prefetchMap(y - height/2, x - width/2);
- SwingUtilities.invokeLater(new updatePbar(y * height + x + 1,
- map.pngfile.toString()));
+ for (int y = -map.radius; y <= map.radius; y++) {
+ for (int x = -map.radius; x <= map.radius; x++) {
+ String pngfile;
+ pngfile = map.initMap(new Point(x,y));
+ SwingUtilities.invokeLater(new updatePbar(x, y, pngfile));
}
}
}
if (cmd.equals("load")) {
if (!loading) {
- loading = true;
- final double latitude = lat.get_value();
- final double longitude = lon.get_value();
- map.show(latitude,longitude);
- bgLoad thread = new bgLoad(map);
- thread.start();
+ try {
+ final double latitude = lat.get_value();
+ final double longitude = lon.get_value();
+ map.setBaseLocation(latitude,longitude);
+ loading = true;
+ bgLoad thread = new bgLoad(map);
+ thread.start();
+ } catch (NumberFormatException ne) {
+ load_button.setSelected(false);
+ }
}
}
}
pane.setLayout(new GridBagLayout());
- map = new AltosSiteMap();
+ map = new AltosSiteMap(4);
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
pane.add(pbar, c);
- lat = new AltosMapPos("Latitude:",
+ lat = new AltosMapPos(owner,
+ "Latitude:",
lat_hemi_names,
37.167833333);
c.fill = GridBagConstraints.NONE;
pane.add(lat, c);
- lon = new AltosMapPos("Longitude:",
+ lon = new AltosMapPos(owner,
+ "Longitude:",
lon_hemi_names,
-97.73975);