2 * Copyright © 2015 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_7;
23 import java.lang.Math;
25 import java.net.URLConnection;
27 public class AltosMapLoader implements AltosMapTileListener {
28 AltosMapLoaderListener listener;
30 double latitude, longitude;
46 public void do_load() {
47 map.set_zoom(cur_z + AltosMap.default_zoom);
48 map.set_maptype(cur_type);
49 map.set_load_params(latitude, longitude, radius, this);
52 public int next_type(int start) {
54 for (next_type = start;
55 next_type <= AltosMap.maptype_terrain && (all_types & (1 << next_type)) == 0;
61 public void next_load() {
62 int next_type = next_type(cur_type + 1);
64 if (next_type > AltosMap.maptype_terrain) {
70 next_type = next_type(0);
76 private void start_load() {
81 for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++)
82 if ((all_types & (1 << t)) != 0)
85 all_types = (1 << AltosMap.maptype_hybrid);
89 cur_type = next_type(0);
90 tiles_per_layer = (radius * 2 + 1) * (radius * 2 + 1);
91 layers_total = (max_z - min_z + 1) * ntype;
95 listener.loader_start(layers_total * tiles_per_layer);
99 public void load(double latitude, double longitude, int min_z, int max_z, int radius, int all_types) {
100 this.latitude = latitude;
101 this.longitude = longitude;
104 this.radius = radius;
105 this.all_types = all_types;
109 public synchronized void notify_tile(AltosMapTile tile, int status) {
110 boolean do_next = false;
111 if (status == AltosMapTile.loading)
114 if (layers_loaded >= layers_total)
119 if (tiles_loaded == tiles_per_layer) {
122 if (layers_loaded == layers_total) {
123 listener.loader_done(layers_total * tiles_per_layer);
129 listener.loader_notify(layers_loaded * tiles_per_layer + tiles_loaded,
130 layers_total * tiles_per_layer, tile.store.file.toString());
135 public AltosMapCache cache() { return cache; }
137 public AltosMapLoader(AltosMap map, AltosMapCache cache,
138 AltosMapLoaderListener listener) {
141 this.listener = listener;