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;
45 public void do_load() {
46 map.set_load_params(cur_z + AltosMap.default_zoom, cur_type, latitude, longitude, radius, this);
49 public int next_type(int start) {
51 for (next_type = start;
52 next_type <= AltosMap.maptype_terrain && (all_types & (1 << next_type)) == 0;
58 public void next_load() {
59 int next_type = next_type(cur_type + 1);
61 if (next_type > AltosMap.maptype_terrain) {
67 next_type = next_type(0);
73 private void start_load() {
78 for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++)
79 if ((all_types & (1 << t)) != 0)
82 all_types = (1 << AltosMap.maptype_hybrid);
86 cur_type = next_type(0);
87 tiles_per_layer = (radius * 2 + 1) * (radius * 2 + 1);
88 layers_total = (max_z - min_z + 1) * ntype;
92 listener.loader_start(layers_total * tiles_per_layer);
96 public void load(double latitude, double longitude, int min_z, int max_z, int radius, int all_types) {
97 this.latitude = latitude;
98 this.longitude = longitude;
101 this.radius = radius;
102 this.all_types = all_types;
106 public synchronized void notify_tile(AltosMapTile tile, int status) {
107 boolean do_next = false;
108 if (status == AltosMapTile.loading)
111 if (layers_loaded >= layers_total)
116 if (tiles_loaded == tiles_per_layer) {
119 if (layers_loaded == layers_total) {
120 listener.loader_done(layers_total * tiles_per_layer);
126 listener.loader_notify(layers_loaded * tiles_per_layer + tiles_loaded,
127 layers_total * tiles_per_layer, tile.store.file.toString());
132 public AltosMapCache cache() { return map.cache(); }
134 public AltosMapLoader(AltosMap map, AltosMapLoaderListener listener) {
136 this.listener = listener;