altosdroid: Add map types and map preloading UIs
[fw/altos] / altoslib / AltosMap.java
index bdb60f0cb72f239ed5969a50f4fe30cb3756eeac..85f95eef9cfdf3af49cae55224b6d1b165dd9ae5 100644 (file)
@@ -58,8 +58,9 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
        LinkedList<AltosMapMark> marks = new LinkedList<AltosMapMark>();
 
-       AltosMapPath    path;
-       AltosMapLine    line;
+       AltosMapPath            path;
+       AltosMapLine            line;
+       public AltosLatLon      last_position;
 
        boolean         have_boost = false;
        boolean         have_landed = false;
@@ -149,8 +150,10 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
        }
 
        public void set_transform() {
-               transform = new AltosMapTransform(width(), height(), zoom, centre);
-               repaint();
+               if (centre != null) {
+                       transform = new AltosMapTransform(width(), height(), zoom, centre);
+                       repaint();
+               }
        }
 
        private void set_zoom_label() {
@@ -195,8 +198,6 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                if (!gps.locked && gps.nsat < 4)
                        return;
 
-               AltosMapRectangle       damage = path.add(gps.lat, gps.lon, state.state);
-
                switch (state.state) {
                case AltosLib.ao_flight_boost:
                        if (!have_boost) {
@@ -212,8 +213,15 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        break;
                }
 
-               if (damage != null)
-                       repaint(damage, AltosMapPath.stroke_width);
+               if (path != null) {
+                       AltosMapRectangle       damage = path.add(gps.lat, gps.lon, state.state);
+
+                       if (damage != null)
+                               repaint(damage, AltosMapPath.stroke_width);
+               }
+
+               last_position = new AltosLatLon(gps.lat, gps.lon);
+
                maybe_centre(gps.lat, gps.lon);
        }
 
@@ -240,7 +248,9 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
        public void add_mark(double lat, double lon, int state) {
                synchronized(marks) {
-                       marks.add(map_interface.new_mark(lat, lon, state));
+                       AltosMapMark mark = map_interface.new_mark(lat, lon, state);
+                       if (mark != null)
+                               marks.add(mark);
                }
                repaint();
        }
@@ -279,6 +289,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        tiles.remove(point);
 
                cache.set_cache_size((width() / AltosMap.px_size + 2) * (height() / AltosMap.px_size + 2));
+
                for (int y = (int) upper_left.y; y <= lower_right.y; y += AltosMap.px_size) {
                        for (int x = (int) upper_left.x; x <= lower_right.x; x += AltosMap.px_size) {
                                AltosPointInt point = new AltosPointInt(x, y);
@@ -294,11 +305,15 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                }
        }
 
-       public void set_load_params(double lat, double lon, int radius, AltosMapTileListener listener) {
+       public void set_load_params(int new_zoom, int new_type, double lat, double lon, int radius, AltosMapTileListener listener) {
+               if (AltosMap.min_zoom <= new_zoom && new_zoom <= AltosMap.max_zoom)
+                       zoom = new_zoom;
+               maptype = new_type;
                load_centre = new AltosLatLon(lat, lon);
                load_radius = radius;
                load_listener = listener;
                centre(lat, lon);
+               tiles.clear();
                make_tiles();
                for (AltosMapTile tile : tiles.values()) {
                        tile.add_store_listener(this);
@@ -313,7 +328,8 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
        }
 
        public void paint() {
-               make_tiles();
+               if (centre != null)
+                       make_tiles();
 
                for (AltosMapTile tile : tiles.values())
                        tile.paint(transform);
@@ -323,9 +339,11 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                                mark.paint(transform);
                }
 
-               path.paint(transform);
+               if (path != null)
+                       path.paint(transform);
 
-               line.paint(transform);
+               if (line != null)
+                       line.paint(transform);
        }
 
        /* AltosMapTileListener methods */
@@ -368,13 +386,17 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
        }
 
        private void line_start(int x, int y) {
-               line.pressed(new AltosPointInt(x, y), transform);
-               repaint();
+               if (line != null) {
+                       line.pressed(new AltosPointInt(x, y), transform);
+                       repaint();
+               }
        }
 
        private void line(int x, int y) {
-               line.dragged(new AltosPointInt(x, y), transform);
-               repaint();
+               if (line != null) {
+                       line.dragged(new AltosPointInt(x, y), transform);
+                       repaint();
+               }
        }
 
        public void touch_start(int x, int y, boolean is_drag) {
@@ -399,6 +421,5 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                line = map_interface.new_line();
                path = map_interface.new_path();
                set_zoom_label();
-               centre(0, 0);
        }
 }