+ private Semaphore loading = new Semaphore(MAX_LOADING);
+
+ boolean abort;
+
+ int tile_radius(int zoom) {
+ double delta_lon = AltosMapTransform.lon_from_distance(latitude, radius);
+
+ AltosMapTransform t = new AltosMapTransform(256, 256, zoom + AltosMap.default_zoom, new AltosLatLon(latitude, longitude));
+
+ AltosPointDouble center = t.point(new AltosLatLon(latitude, longitude));
+ AltosPointDouble edge = t.point(new AltosLatLon(latitude, longitude + delta_lon));
+
+ int tile_radius = (int) Math.ceil(Math.abs(center.x - edge.x) / AltosMap.px_size);
+
+ return tile_radius;
+ }
+
+ int tiles_per_layer(int zoom) {
+ int tile_radius = tile_radius(zoom);
+ return (tile_radius * 2 + 1) * (tile_radius * 2 + 1);
+ }
+
+ private boolean do_load() {
+ tiles_this_layer = tiles_per_layer(cur_z);
+ tiles_loaded_layer = 0;
+ listener.debug("tiles_this_layer %d (zoom %d)\n", tiles_this_layer, cur_z);
+
+ int load_radius = tile_radius(cur_z);
+ int zoom = cur_z + AltosMap.default_zoom;
+ int maptype = cur_type;
+ AltosLatLon load_centre = new AltosLatLon(latitude, longitude);
+ AltosMapTransform transform = new AltosMapTransform(256, 256, zoom, load_centre);
+
+ AltosPointInt upper_left;
+ AltosPointInt lower_right;
+
+ AltosPointInt centre = AltosMap.floor(transform.point(load_centre));
+
+ upper_left = new AltosPointInt(centre.x - load_radius * AltosMap.px_size,
+ centre.y - load_radius * AltosMap.px_size);
+ lower_right = new AltosPointInt(centre.x + load_radius * AltosMap.px_size,
+ centre.y + load_radius * AltosMap.px_size);
+
+
+ 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) {
+ try {
+ loading.acquire();
+ } catch (InterruptedException ie) {
+ return false;
+ }
+ 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));
+ 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;
+ }
+ }
+ return true;