X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=inline;f=altoslib%2FAltosMap.java;h=59420d4b389bf7c2c4b27142419bdbd320ddd3c6;hb=3882e358b6f2970cb1afebcf2a71da34a57002df;hp=b54c66cf7a9d44e8f496f90b89b71ed3ef114f1b;hpb=501fa41111b93cc213a1114a33612858e1e93ab5;p=fw%2Faltos diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index b54c66cf..59420d4b 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -58,8 +58,9 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { LinkedList marks = new LinkedList(); - AltosMapPath path; - AltosMapLine line; + AltosMapPath path; + AltosMapLine line; + public AltosLatLon last_position; boolean have_boost = false; boolean have_landed = false; @@ -108,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); @@ -149,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() { @@ -195,8 +202,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 +217,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 +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(); } @@ -266,39 +280,38 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { upper_left = floor(transform.screen_point(new AltosPointInt(0, 0))); lower_right = floor(transform.screen_point(new AltosPointInt(width(), height()))); } - LinkedList to_remove = new LinkedList(); - for (AltosPointInt point : tiles.keySet()) { if (point.x < upper_left.x || lower_right.x < point.x || point.y < upper_left.y || lower_right.y < point.y) { - to_remove.add(point); + tiles.remove(point); } } - for (AltosPointInt point : to_remove) - 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); + AltosPointInt point = new AltosPointInt(x, y); if (!tiles.containsKey(point)) { - AltosLatLon ul = transform.lat_lon(new AltosPointDouble(x, y)); + AltosLatLon ul = transform.lat_lon(point); AltosLatLon center = transform.lat_lon(new AltosPointDouble(x + AltosMap.px_size/2, y + AltosMap.px_size/2)); - AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype, - AltosMap.px_size); + AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype, px_size); tiles.put(point, tile); } } } } - 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 +326,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 +337,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 */ @@ -358,6 +374,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); @@ -368,13 +389,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 +424,5 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { line = map_interface.new_line(); path = map_interface.new_path(); set_zoom_label(); - centre(0, 0); } }