f4143fe2433d84fbdcfeb072daee35f19772381e
[fw/altos] / altosuilib / AltosSiteMap.java
1 /*
2  * Copyright © 2010 Anthony Towns <aj@erisian.com.au>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altosuilib_2;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import java.io.*;
24 import java.lang.Math;
25 import java.awt.geom.Point2D;
26 import java.util.*;
27 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_4.*;
29
30 class MapPoint {
31         double  lat, lon;
32         int     state;
33
34         public MapPoint(double lat, double lon, int state) {
35                 this.lat = lat;
36                 this.lon = lon;
37                 this.state = state;
38         }
39
40         public boolean equals(MapPoint other) {
41                 if (other == null)
42                         return false;
43                 if (other.lat != lat)
44                         return false;
45                 if (other.lon != lon)
46                         return false;
47                 if (other.state != state)
48                         return false;
49                 return true;
50         }
51 }
52
53 public class AltosSiteMap extends JComponent implements AltosFlightDisplay {
54         // preferred vertical step in a tile in naut. miles
55         // will actually choose a step size between x and 2x, where this
56         // is 1.5x
57         static final double tile_size_nmi = 0.75;
58
59         static final int px_size = 512;
60
61         static final int MAX_TILE_DELTA = 100;
62
63         static final int maptype_hybrid = 0;
64         static final int maptype_roadmap = 1;
65         static final int maptype_satellite = 2;
66         static final int maptype_terrain = 3;
67
68         int maptype = maptype_hybrid;
69
70         static final String[] maptype_names = {
71                 "hybrid",
72                 "roadmap",
73                 "satellite",
74                 "terrain"
75         };
76
77         static final String[] maptype_labels = {
78                 "Hybrid",
79                 "Roadmap",
80                 "Satellite",
81                 "Terrain"
82         };
83
84         LinkedList<MapPoint> points = new LinkedList<MapPoint>();
85
86         private static Point2D.Double translatePoint(Point2D.Double p,
87                         Point2D.Double d)
88         {
89                 return new Point2D.Double(p.x + d.x, p.y + d.y);
90         }
91
92         static class LatLng {
93                 public double lat, lng;
94                 public LatLng(double lat, double lng) {
95                         this.lat = lat;
96                         this.lng = lng;
97                 }
98         }
99
100         // based on google js
101         //  http://maps.gstatic.com/intl/en_us/mapfiles/api-3/2/10/main.js
102         // search for fromLatLngToPoint and fromPointToLatLng
103         /*
104         private static Point2D.Double pt(LatLng latlng, int zoom) {
105                 double scale_x = 256/360.0 * Math.pow(2, zoom);
106                 double scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom);
107                 return pt(latlng, scale_x, scale_y);
108         }
109         */
110
111         private static Point2D.Double pt(LatLng latlng,
112                                          double scale_x, double scale_y)
113         {
114                 Point2D.Double res = new Point2D.Double();
115                 double e;
116
117                 res.x = latlng.lng * scale_x;
118
119                 e = Math.sin(Math.toRadians(latlng.lat));
120                 e = Math.max(e,-(1-1.0E-15));
121                 e = Math.min(e,  1-1.0E-15 );
122
123                 res.y = 0.5*Math.log((1+e)/(1-e))*-scale_y;
124                 return res;
125         }
126
127         static private LatLng latlng(Point2D.Double pt,
128                                      double scale_x, double scale_y)
129         {
130                 double lat, lng;
131                 double rads;
132
133                 lng = pt.x/scale_x;
134                 rads = 2 * Math.atan(Math.exp(-pt.y/scale_y));
135                 lat = Math.toDegrees(rads - Math.PI/2);
136
137                 return new LatLng(lat,lng);
138         }
139
140         static final int default_zoom = 15;
141         static final int min_zoom = 3;
142         static final int max_zoom = 21;
143
144         int zoom = default_zoom;
145
146         double scale_x, scale_y;
147
148         int radius;     /* half width/height of tiles to load */
149
150         private Point2D.Double pt(double lat, double lng) {
151                 return pt(new LatLng(lat, lng), scale_x, scale_y);
152         }
153
154         private LatLng latlng(double x, double y) {
155                 return latlng(new Point2D.Double(x,y), scale_x, scale_y);
156         }
157         /*
158         private LatLng latlng(Point2D.Double pt) {
159                 return latlng(pt, scale_x, scale_y);
160         }
161         */
162
163         ConcurrentHashMap<Point,AltosSiteMapTile> mapTiles = new ConcurrentHashMap<Point,AltosSiteMapTile>();
164         Point2D.Double centre;
165
166         private Point2D.Double tileCoordOffset(Point p) {
167                 return new Point2D.Double(centre.x - p.x*px_size,
168                                           centre.y - p.y*px_size);
169         }
170
171         private Point tileOffset(Point2D.Double p) {
172                 return new Point((int)Math.floor((centre.x+p.x)/px_size),
173                                  (int)Math.floor((centre.y+p.y)/px_size));
174         }
175
176         private Point2D.Double getBaseLocation(double lat, double lng) {
177                 Point2D.Double locn = pt(0,0), north_step;
178
179                 scale_x = 256/360.0 * Math.pow(2, zoom);
180                 scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom);
181                 locn = pt(lat, lng);
182                 locn.x = -px_size * Math.floor(locn.x/px_size);
183                 locn.y = -px_size * Math.floor(locn.y/px_size);
184                 return locn;
185         }
186
187         public void reset() {
188                 // nothing
189         }
190
191         public void set_font() {
192                 for (AltosSiteMapTile tile : mapTiles.values())
193                         tile.set_font(AltosUILib.value_font);
194         }
195
196         static final int load_mode_cached = 1;
197         static final int load_mode_uncached = 2;
198
199         private boolean load_map(final AltosSiteMapTile tile,
200                                  final File pngfile, String pngurl,
201                                  int load_mode)
202         {
203                 boolean has_map = AltosSiteMapCache.has_map(pngfile, pngurl);
204                 if ((load_mode & load_mode_uncached) == 0 && !has_map)
205                         return false;
206                 if ((load_mode & load_mode_cached) == 0 && has_map)
207                         return false;
208
209                 tile.set_status(AltosSiteMapCache.loading);
210                 int status = AltosSiteMapCache.fetch_map(pngfile, pngurl);
211                 if (status == AltosSiteMapCache.success) {
212                         SwingUtilities.invokeLater(new Runnable() {
213                                         public void run() {
214                                                 tile.load_map(pngfile);
215                                         }
216                                 });
217                 } else {
218                         tile.set_status(status);
219                         System.out.printf("# Failed to fetch file %s (status %d)\n", pngfile, status);
220                         System.out.printf(" wget -O '%s' '%s'\n", pngfile, pngurl);
221                         System.out.printf(" sleep 1\n");
222                 }
223                 return true;
224         }
225
226
227         class AltosSiteMapPrefetch {
228                 int     x;
229                 int     y;
230                 int     result;
231                 File    pngfile;
232                 String  pngurl;
233         }
234
235         public AltosSiteMapPrefetch prefetchMap(int x, int y) {
236                 AltosSiteMapPrefetch    prefetch = new AltosSiteMapPrefetch();
237                 LatLng map_latlng = latlng(
238                         -centre.x + x*px_size + px_size/2,
239                         -centre.y + y*px_size + px_size/2);
240                 prefetch.pngfile = MapFile(map_latlng.lat, map_latlng.lng, zoom, maptype_hybrid);
241                 prefetch.pngurl = MapURL(map_latlng.lat, map_latlng.lng, zoom, maptype_hybrid);
242                 if (AltosSiteMapCache.has_map(prefetch.pngfile, prefetch.pngurl)) {
243                         prefetch.result = 1;
244                 } else if (AltosSiteMapCache.fetch_map(prefetch.pngfile, prefetch.pngurl) == AltosSiteMapCache.success) {
245                         prefetch.result = 0;
246                 } else {
247                         prefetch.result = -1;
248                 }
249                 return prefetch;
250         }
251
252         public static void prefetchMaps(double lat, double lng) {
253                 int w = AltosSiteMapPreload.width;
254                 int h = AltosSiteMapPreload.height;
255                 AltosSiteMap asm = new AltosSiteMap(true);
256                 asm.centre = asm.getBaseLocation(lat, lng);
257
258                 //Point2D.Double p = new Point2D.Double();
259                 //Point2D.Double p2;
260                 int dx = -w/2, dy = -h/2;
261                 for (int y = dy; y < h+dy; y++) {
262                         for (int x = dx; x < w+dx; x++) {
263                                 AltosSiteMapPrefetch prefetch = asm.prefetchMap(x, y);
264                                 switch (prefetch.result) {
265                                 case 1:
266                                         System.out.printf("Already have %s\n", prefetch.pngfile);
267                                         break;
268                                 case 0:
269                                         System.out.printf("Fetched map %s\n", prefetch.pngfile);
270                                         break;
271                                 case -1:
272                                         System.out.printf("# Failed to fetch file %s\n", prefetch.pngfile);
273                                         System.out.printf(" wget -O '%s' ''\n",
274                                                           prefetch.pngfile, prefetch.pngurl);
275                                         break;
276                                 }
277                         }
278                 }
279         }
280
281         public File init_map(Point offset, int load_mode) {
282                 AltosSiteMapTile tile = mapTiles.get(offset);
283                 Point2D.Double coord = tileCoordOffset(offset);
284
285                 LatLng map_latlng = latlng(px_size/2-coord.x, px_size/2-coord.y);
286
287                 File pngfile = MapFile(map_latlng.lat, map_latlng.lng, zoom, maptype);
288                 String pngurl = MapURL(map_latlng.lat, map_latlng.lng, zoom, maptype);
289                 load_map(tile, pngfile, pngurl, load_mode);
290                 return pngfile;
291         }
292
293         public void initAndFinishMapAsync (final AltosSiteMapTile tile, final Point offset) {
294                 Thread thread = new Thread() {
295                                 public void run() {
296                                         init_map(offset, load_mode_cached|load_mode_uncached);
297                                         finishTileLater(tile, offset);
298                                 }
299                         };
300                 thread.start();
301         }
302
303         double  lat, lon;
304         boolean base_location_set = false;
305
306         public void clear_base_location() {
307                 base_location_set = false;
308                 circle_set = false;
309                 points = new LinkedList<MapPoint>();
310                 for (AltosSiteMapTile tile : mapTiles.values())
311                         tile.clearMap();
312         }
313
314         public void setBaseLocation(double lat, double lng) {
315                 this.lat = lat;
316                 this.lon = lng;
317                 base_location_set = true;
318                 for (AltosSiteMapTile tile : mapTiles.values())
319                         tile.clearMap();
320
321                 centre = getBaseLocation(lat, lng);
322                 scrollRocketToVisible(pt(lat,lng));
323         }
324
325         private void initMaps(double lat, double lng) {
326                 setBaseLocation(lat, lng);
327
328                 Thread thread = new Thread() {
329                                 public void run() {
330                                         for (Point k : mapTiles.keySet())
331                                                 init_map(k, load_mode_cached);
332                                         for (Point k : mapTiles.keySet())
333                                                 init_map(k, load_mode_uncached);
334                                 }
335                         };
336                 thread.start();
337         }
338
339         private static File MapFile(double lat, double lng, int zoom, int maptype) {
340                 char chlat = lat < 0 ? 'S' : 'N';
341                 char chlng = lng < 0 ? 'W' : 'E';
342                 if (lat < 0) lat = -lat;
343                 if (lng < 0) lng = -lng;
344                 String maptype_string = String.format("%s-", maptype_names[maptype]);
345                 String format_string;
346                 if (maptype == maptype_hybrid || maptype == maptype_satellite || maptype == maptype_terrain)
347                         format_string = "jpg";
348                 else
349                         format_string = "png";
350                 return new File(AltosUIPreferences.mapdir(),
351                                 String.format("map-%c%.6f,%c%.6f-%s%d.%s",
352                                               chlat, lat, chlng, lng, maptype_string, zoom, format_string));
353         }
354
355         private static String MapURL(double lat, double lng, int zoom, int maptype) {
356                 String format_string;
357                 if (maptype == maptype_hybrid || maptype == maptype_satellite || maptype == maptype_terrain)
358                         format_string = "jpg";
359                 else
360                         format_string = "png32";
361                 return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=%s",
362                                      lat, lng, zoom, px_size, px_size, maptype_names[maptype], format_string);
363         }
364
365         boolean initialised = false;
366         MapPoint last_point = null;
367         int last_state = -1;
368
369         public void show(double lat, double lon) {
370                 System.out.printf ("show %g %g\n", lat, lon);
371                 return;
372 //              initMaps(lat, lon);
373 //              scrollRocketToVisible(pt(lat, lon));
374         }
375
376         JLabel  zoom_label;
377
378         public void set_zoom_label() {
379                 zoom_label.setText(String.format("- %d -", zoom - default_zoom));
380         }
381
382         public void set_zoom(int zoom) {
383                 if (min_zoom <= zoom && zoom <= max_zoom) {
384                         this.zoom = zoom;
385                         if (base_location_set)
386                                 initMaps(lat, lon);
387                         redraw();
388                         set_zoom_label();
389                 }
390         }
391
392         public int get_zoom() {
393                 return zoom;
394         }
395
396         public void draw(MapPoint last_point, MapPoint point) {
397                 boolean force_ensure = false;
398                 if (last_point == null) {
399                         force_ensure = true;
400                         last_point = point;
401                 }
402
403                 Point2D.Double pt = pt(point.lat, point.lon);
404                 Point2D.Double last_pt = pt(last_point.lat, last_point.lon);
405
406                 boolean in_any = false;
407                 for (Point offset : mapTiles.keySet()) {
408                         AltosSiteMapTile tile = mapTiles.get(offset);
409                         Point2D.Double ref, lref;
410                         ref = translatePoint(pt, tileCoordOffset(offset));
411                         lref = translatePoint(last_pt, tileCoordOffset(offset));
412                         tile.show(point.state, lref, ref);
413                         if (0 <= ref.x && ref.x < px_size)
414                                 if (0 <= ref.y && ref.y < px_size)
415                                         in_any = true;
416                 }
417
418                 Point offset = tileOffset(pt);
419                 if (!in_any) {
420                         Point2D.Double ref, lref;
421                         ref = translatePoint(pt, tileCoordOffset(offset));
422                         lref = translatePoint(last_pt, tileCoordOffset(offset));
423
424                         AltosSiteMapTile tile = createTile(offset);
425                         tile.show(point.state, lref, ref);
426                         initAndFinishMapAsync(tile, offset);
427                 }
428
429                 scrollRocketToVisible(pt);
430
431                 if (force_ensure || offset != tileOffset(last_pt)) {
432                         ensureTilesAround(offset);
433                 }
434         }
435
436         public void redraw() {
437                 MapPoint        last_point = null;
438
439                 for (MapPoint point : points) {
440                         draw(last_point, point);
441                         last_point = point;
442                 }
443                 if (circle_set)
444                         draw_circle(circle_lat, circle_lon);
445         }
446
447         public void show(final AltosState state, final AltosListenerState listener_state) {
448                 // if insufficient gps data, nothing to update
449                 AltosGPS        gps = state.gps;
450
451                 if (gps == null)
452                         return;
453
454                 if (!gps.locked && gps.nsat < 4)
455                         return;
456
457                 if (!initialised) {
458                         if (state.pad_lat != AltosLib.MISSING && state.pad_lon != AltosLib.MISSING) {
459                                 initMaps(state.pad_lat, state.pad_lon);
460                                 initialised = true;
461                         } else if (gps.lat != AltosLib.MISSING && gps.lon != AltosLib.MISSING) {
462                                 initMaps(gps.lat, gps.lon);
463                                 initialised = true;
464                         } else {
465                                 return;
466                         }
467                 }
468
469                 MapPoint        point = new MapPoint(gps.lat, gps.lon, state.state);
470
471                 if (point.equals(last_point))
472                         return;
473
474                 points.add(point);
475
476                 draw(last_point, point);
477
478                 last_point = point;
479         }
480
481         public void centre(Point2D.Double pt) {
482                 Rectangle r = comp.getVisibleRect();
483                 Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft));
484                 int dx = (int)copt.x - r.width/2 - r.x;
485                 int dy = (int)copt.y - r.height/2 - r.y;
486                 r.x += dx;
487                 r.y += dy;
488                 r.width = 1;
489                 r.height = 1;
490                 comp.scrollRectToVisible(r);
491         }
492
493         public void centre(AltosState state) {
494                 if (!state.gps.locked && state.gps.nsat < 4)
495                         return;
496                 centre(pt(state.gps.lat, state.gps.lon));
497         }
498
499         private double circle_lat, circle_lon;
500         private boolean circle_set = false;
501
502         public void draw_circle(double lat, double lon) {
503                 circle_lat = lat;
504                 circle_lon = lon;
505                 circle_set = true;
506
507                 Point2D.Double pt = pt(lat, lon);
508
509                 for (Point offset : mapTiles.keySet()) {
510                         AltosSiteMapTile tile = mapTiles.get(offset);
511                         Point2D.Double ref = translatePoint(pt, tileCoordOffset(offset));
512                         tile.set_boost(ref);
513                 }
514         }
515
516         private AltosSiteMapTile createTile(Point offset) {
517                 AltosSiteMapTile tile = new AltosSiteMapTile(px_size);
518                 tile.set_font(AltosUILib.value_font);
519                 mapTiles.put(offset, tile);
520                 return tile;
521         }
522         private void finishTileLater(final AltosSiteMapTile tile,
523                                      final Point offset)
524         {
525                 SwingUtilities.invokeLater( new Runnable() {
526                         public void run() {
527                                 addTileAt(tile, offset);
528                         }
529                 } );
530         }
531
532         private void ensureTilesAround(Point base_offset) {
533                 for (int x = -radius; x <= radius; x++) {
534                         for (int y = -radius; y <= radius; y++) {
535                                 Point offset = new Point(base_offset.x + x, base_offset.y + y);
536                                 if (mapTiles.containsKey(offset))
537                                         continue;
538                                 AltosSiteMapTile tile = createTile(offset);
539                                 initAndFinishMapAsync(tile, offset);
540                         }
541                 }
542         }
543
544         private Point topleft = new Point(0,0);
545         private void scrollRocketToVisible(Point2D.Double pt) {
546                 Rectangle r = comp.getVisibleRect();
547                 Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft));
548
549                 int dx = (int)copt.x - r.width/2 - r.x;
550                 int dy = (int)copt.y - r.height/2 - r.y;
551                 if (Math.abs(dx) > r.width/4 || Math.abs(dy) > r.height/4) {
552                         r.x += dx;
553                         r.y += dy;
554                         comp.scrollRectToVisible(r);
555                 }
556         }
557
558         private void addTileAt(AltosSiteMapTile tile, Point offset) {
559                 if (Math.abs(offset.x) >= MAX_TILE_DELTA ||
560                                 Math.abs(offset.y) >= MAX_TILE_DELTA)
561                 {
562                         System.out.printf("Rocket too far away from pad (tile %d,%d)\n",
563                                           offset.x, offset.y);
564                         return;
565                 }
566
567                 boolean review = false;
568                 Rectangle r = comp.getVisibleRect();
569                 if (offset.x < topleft.x) {
570                         r.x += (topleft.x - offset.x) * px_size;
571                         topleft.x = offset.x;
572                         review = true;
573                 }
574                 if (offset.y < topleft.y) {
575                         r.y += (topleft.y - offset.y) * px_size;
576                         topleft.y = offset.y;
577                         review = true;
578                 }
579                 GridBagConstraints c = new GridBagConstraints();
580                 c.anchor = GridBagConstraints.CENTER;
581                 c.fill = GridBagConstraints.BOTH;
582                 // put some space between the map tiles, debugging only
583                 // c.insets = new Insets(5, 5, 5, 5);
584
585                 c.gridx = offset.x + MAX_TILE_DELTA;
586                 c.gridy = offset.y + MAX_TILE_DELTA;
587                 layout.setConstraints(tile, c);
588
589                 comp.add(tile);
590 //              if (review) {
591 //                      comp.scrollRectToVisible(r);
592 //              }
593         }
594
595         private AltosSiteMap(boolean knowWhatYouAreDoing) {
596                 if (!knowWhatYouAreDoing) {
597                         throw new RuntimeException("Arggh.");
598                 }
599         }
600
601         JComponent comp = new JComponent() { };
602         private GridBagLayout layout = new GridBagLayout();
603
604         JScrollPane     pane = new JScrollPane();
605
606         public AltosSiteMap(int in_radius) {
607                 radius = in_radius;
608
609                 GrabNDrag scroller = new GrabNDrag(comp);
610
611                 comp.setLayout(layout);
612
613                 for (int x = -radius; x <= radius; x++) {
614                         for (int y = -radius; y <= radius; y++) {
615                                 Point offset = new Point(x, y);
616                                 AltosSiteMapTile t = createTile(offset);
617                                 addTileAt(t, offset);
618                         }
619                 }
620                 pane.setViewportView(comp);
621                 pane.setPreferredSize(new Dimension(500,500));
622                 pane.setVisible(true);
623                 pane.setEnabled(true);
624
625                 GridBagLayout   my_layout = new GridBagLayout();
626
627                 setLayout(my_layout);
628
629                 GridBagConstraints c = new GridBagConstraints();
630                 c.anchor = GridBagConstraints.CENTER;
631                 c.fill = GridBagConstraints.BOTH;
632                 c.gridx = 0;
633                 c.gridy = 0;
634                 c.gridwidth = 1;
635                 c.gridheight = 10;
636                 c.weightx = 1;
637                 c.weighty = 1;
638                 add(pane, c);
639
640                 int     y = 0;
641
642                 zoom_label = new JLabel("", JLabel.CENTER);
643                 set_zoom_label();
644
645                 c = new GridBagConstraints();
646                 c.anchor = GridBagConstraints.CENTER;
647                 c.fill = GridBagConstraints.HORIZONTAL;
648                 c.gridx = 1;
649                 c.gridy = y++;
650                 c.weightx = 0;
651                 c.weighty = 0;
652                 add(zoom_label, c);
653
654                 JButton zoom_reset = new JButton("0");
655                 zoom_reset.addActionListener(new ActionListener() {
656                                 public void actionPerformed(ActionEvent e) {
657                                         set_zoom(default_zoom);
658                                 }
659                         });
660
661                 c = new GridBagConstraints();
662                 c.anchor = GridBagConstraints.CENTER;
663                 c.fill = GridBagConstraints.HORIZONTAL;
664                 c.gridx = 1;
665                 c.gridy = y++;
666                 c.weightx = 0;
667                 c.weighty = 0;
668                 add(zoom_reset, c);
669
670                 JButton zoom_in = new JButton("+");
671                 zoom_in.addActionListener(new ActionListener() {
672                                 public void actionPerformed(ActionEvent e) {
673                                         set_zoom(get_zoom() + 1);
674                                 }
675                         });
676
677                 c = new GridBagConstraints();
678                 c.anchor = GridBagConstraints.CENTER;
679                 c.fill = GridBagConstraints.HORIZONTAL;
680                 c.gridx = 1;
681                 c.gridy = y++;
682                 c.weightx = 0;
683                 c.weighty = 0;
684                 add(zoom_in, c);
685
686                 JButton zoom_out = new JButton("-");
687                 zoom_out.addActionListener(new ActionListener() {
688                                 public void actionPerformed(ActionEvent e) {
689                                         set_zoom(get_zoom() - 1);
690                                 }
691                         });
692                 c = new GridBagConstraints();
693                 c.anchor = GridBagConstraints.CENTER;
694                 c.fill = GridBagConstraints.HORIZONTAL;
695                 c.gridx = 1;
696                 c.gridy = y++;
697                 c.weightx = 0;
698                 c.weighty = 0;
699                 add(zoom_out, c);
700
701                 final JComboBox<String> maptype_combo = new JComboBox<String>(maptype_labels);
702
703                 maptype_combo.setEditable(false);
704                 maptype_combo.setMaximumRowCount(maptype_combo.getItemCount());
705                 maptype_combo.addItemListener(new ItemListener() {
706                                 public void itemStateChanged(ItemEvent e) {
707                                         maptype = maptype_combo.getSelectedIndex();
708                                         if (base_location_set)
709                                                 initMaps(lat, lon);
710                                         redraw();
711                                 }
712                         });
713
714                 c = new GridBagConstraints();
715                 c.anchor = GridBagConstraints.CENTER;
716                 c.fill = GridBagConstraints.HORIZONTAL;
717                 c.gridx = 1;
718                 c.gridy = y++;
719                 c.weightx = 0;
720                 c.weighty = 0;
721                 add(maptype_combo, c);
722         }
723
724         public AltosSiteMap() {
725                 this(1);
726         }
727 }