altoslib: Remove debug output from AltosMap
[fw/altos] / altoslib / AltosMap.java
index 762054a33f158fcefb0698a00091359b97c6e5bd..1504120cfd29cd5a6196ff81414e5411e98c1ad6 100644 (file)
@@ -109,6 +109,10 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                return map_interface.height();
        }
 
+       public void debug(String format, Object ... arguments) {
+               map_interface.debug(format, arguments);
+       }
+
        public AltosPointInt floor(AltosPointDouble point) {
                return new AltosPointInt ((int) Math.floor(point.x / AltosMap.px_size) * AltosMap.px_size,
                                              (int) Math.floor(point.y / AltosMap.px_size) * AltosMap.px_size);
@@ -150,8 +154,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() {
@@ -246,7 +252,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();
        }
@@ -285,6 +293,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);
@@ -300,11 +309,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);
@@ -319,7 +332,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);
@@ -366,6 +380,11 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                int dx = x - drag_start.x;
                int dy = y - drag_start.y;
 
+               if (transform == null) {
+                       debug("Transform not set in drag\n");
+                       return;
+               }
+
                AltosLatLon new_centre = transform.screen_lat_lon(new AltosPointInt(width() / 2 - dx, height() / 2 - dy));
                centre(new_centre);
                drag_start = new AltosPointInt(x, y);
@@ -411,6 +430,5 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                line = map_interface.new_line();
                path = map_interface.new_path();
                set_zoom_label();
-               centre(0, 0);
        }
 }