X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMap.java;h=59420d4b389bf7c2c4b27142419bdbd320ddd3c6;hb=3882e358b6f2970cb1afebcf2a71da34a57002df;hp=85f95eef9cfdf3af49cae55224b6d1b165dd9ae5;hpb=ba698c2cc48677735046d0881df9c180674e4082;p=fw%2Faltos diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index 85f95eef..59420d4b 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -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); @@ -276,29 +280,23 @@ 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, - px_size); + AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype, px_size); tiles.put(point, tile); } } @@ -376,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);