diff options
author | Keith Packard <keithp@keithp.com> | 2016-05-11 12:48:10 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2016-05-11 23:22:15 -0700 |
commit | 2ec7e14f0104e3a227ff566fa2fc1f6286ddd9d0 (patch) | |
tree | 17f703dc3e92a6d0dc86976b02934a13d9bbaa1a /altoslib | |
parent | ab905d2f7d8929080042cfd16cc418ea5792c3cb (diff) |
altoslib: Get rid of AltosMap from AltosMapLoader
Cleans up the loader API and eliminates a AltosMapTile for every chunk
of map data.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib')
-rw-r--r-- | altoslib/AltosMap.java | 11 | ||||
-rw-r--r-- | altoslib/AltosMapInterface.java | 2 | ||||
-rw-r--r-- | altoslib/AltosMapLoader.java | 26 | ||||
-rw-r--r-- | altoslib/AltosMapTile.java | 23 |
4 files changed, 41 insertions, 21 deletions
diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index 1841277f..08ac5f3c 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -51,6 +51,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { }; AltosMapInterface map_interface; + int scale; AltosMapCache cache; @@ -328,7 +329,8 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { if (!tiles.containsKey(point)) { 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(cache, ul, center, zoom, maptype, px_size); + AltosMapTile tile = map_interface.new_tile(cache, ul, center, zoom, maptype, px_size, scale); + debug("show state %s url %s\n", AltosMapTile.status_name(tile.store.status()), tile.store.url); tile.add_listener(this); tiles.put(point, tile); } @@ -475,11 +477,16 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { drag_stop(x, y); } - public AltosMap(AltosMapInterface map_interface) { + public AltosMap(AltosMapInterface map_interface, int scale) { this.map_interface = map_interface; + this.scale = scale; cache = new AltosMapCache(map_interface); line = map_interface.new_line(); path = map_interface.new_path(); set_zoom_label(); } + + public AltosMap(AltosMapInterface map_interface) { + this(map_interface, 1); + } } diff --git a/altoslib/AltosMapInterface.java b/altoslib/AltosMapInterface.java index 756a78f2..df09224a 100644 --- a/altoslib/AltosMapInterface.java +++ b/altoslib/AltosMapInterface.java @@ -29,7 +29,7 @@ public interface AltosMapInterface { public abstract AltosMapMark new_mark(double lat, double lon, int state); - public abstract AltosMapTile new_tile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size); + public abstract AltosMapTile new_tile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size, int scale); public abstract int width(); diff --git a/altoslib/AltosMapLoader.java b/altoslib/AltosMapLoader.java index 8b856e13..015c0ad3 100644 --- a/altoslib/AltosMapLoader.java +++ b/altoslib/AltosMapLoader.java @@ -25,7 +25,7 @@ import java.lang.Math; import java.net.URL; import java.net.URLConnection; -public class AltosMapLoader extends Thread implements AltosMapTileListener { +public class AltosMapLoader extends Thread implements AltosMapStoreListener { AltosMapLoaderListener listener; double latitude, longitude; @@ -35,6 +35,7 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { int all_types; int cur_type; double radius; + int scale; int tiles_loaded_layer; int tiles_loaded_total; @@ -49,8 +50,6 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { boolean abort; - AltosMap map; - int tile_radius(int zoom) { double delta_lon = AltosMapTransform.lon_from_distance(latitude, radius); @@ -80,8 +79,6 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { AltosLatLon load_centre = new AltosLatLon(latitude, longitude); AltosMapTransform transform = new AltosMapTransform(256, 256, zoom, load_centre); - map.centre(load_centre); - AltosPointInt upper_left; AltosPointInt lower_right; @@ -103,8 +100,9 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { AltosPointInt point = new AltosPointInt(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 = new AltosMapTile(null, ul, center, zoom, maptype, AltosMap.px_size); - tile.add_listener(this); + AltosMapStore store = AltosMapStore.get(center, zoom, maptype, AltosMap.px_size, scale); + listener.debug("load state %s url %s\n", AltosMapTile.status_name(store.status()), store.url); + store.add_listener(this); if (abort) return false; } @@ -170,14 +168,14 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { listener.loader_done(tiles_total); } - public synchronized void notify_tile(AltosMapTile tile, int status) { + public synchronized void notify_store(AltosMapStore store, int status) { boolean do_next = false; if (status == AltosMapTile.fetching) return; loading.release(); - tile.remove_listener(this); + store.remove_listener(this); if (layers_loaded >= layers_total) return; @@ -185,7 +183,7 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { ++tiles_loaded_total; ++tiles_loaded_layer; - listener.debug("AltosMapLoader.notify_tile status %d total %d of %d layer %d of %d\n", + listener.debug("AltosMapLoader.notify_store status %d total %d of %d layer %d of %d\n", status, tiles_loaded_total, tiles_total, tiles_loaded_layer, tiles_this_layer); if (tiles_loaded_layer == tiles_this_layer) { @@ -198,18 +196,17 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { listener.loader_done(tiles_total); else listener.loader_notify(tiles_loaded_total, - tiles_total, tile.store.file.toString()); + tiles_total, store.file.toString()); } public void abort() { this.abort = true; } - public AltosMapLoader(AltosMap map, AltosMapLoaderListener listener, - double latitude, double longitude, int min_z, int max_z, double radius, int all_types) { + public AltosMapLoader(AltosMapLoaderListener listener, + double latitude, double longitude, int min_z, int max_z, double radius, int all_types, int scale) { listener.debug("lat %f lon %f min_z %d max_z %d radius %f all_types %d\n", latitude, longitude, min_z, max_z, radius, all_types); - this.map = map; this.listener = listener; this.latitude = latitude; this.longitude = longitude; @@ -217,6 +214,7 @@ public class AltosMapLoader extends Thread implements AltosMapTileListener { this.max_z = max_z; this.radius = radius; this.all_types = all_types; + this.scale = scale; this.abort = false; start(); } diff --git a/altoslib/AltosMapTile.java b/altoslib/AltosMapTile.java index 19332de1..b0bac963 100644 --- a/altoslib/AltosMapTile.java +++ b/altoslib/AltosMapTile.java @@ -38,6 +38,25 @@ public class AltosMapTile implements AltosFontListener, AltosMapStoreListener { static public final int bad_request = 4;/* downloading failed */ static public final int forbidden = 5; /* downloading failed */ + static public String status_name(int status) { + switch (status) { + case loaded: + return "loaded"; + case fetched: + return "fetched"; + case fetching: + return "fetching"; + case failed: + return "failed"; + case bad_request: + return "bad_request"; + case forbidden: + return "forbidden"; + default: + return "unknown"; + } + } + public void font_size_changed(int font_size) { } @@ -96,8 +115,4 @@ public class AltosMapTile implements AltosFontListener, AltosMapStoreListener { store = AltosMapStore.get(center, zoom, maptype, px_size, scale); store.add_listener(this); } - - public AltosMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { - this(cache, upper_left, center, zoom, maptype, px_size, 1); - } } |