From 3b4e6da65158a434905dc652e46c69d2c38cea7f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 27 May 2015 23:12:34 -0700 Subject: altoslib: Add map loading helper class This adds the AltosMapLoader class, which iterates over a sequence of zoom levels and formats to get local copies of a desired launch site. Signed-off-by: Keith Packard --- altoslib/AltosMapLoader.java | 143 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 altoslib/AltosMapLoader.java (limited to 'altoslib/AltosMapLoader.java') diff --git a/altoslib/AltosMapLoader.java b/altoslib/AltosMapLoader.java new file mode 100644 index 00000000..5db20cf8 --- /dev/null +++ b/altoslib/AltosMapLoader.java @@ -0,0 +1,143 @@ +/* + * Copyright © 2015 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altoslib_7; + +import java.io.*; +import java.util.*; +import java.text.*; +import java.lang.Math; +import java.net.URL; +import java.net.URLConnection; + +public class AltosMapLoader implements AltosMapTileListener { + AltosMapLoaderListener listener; + + double latitude, longitude; + int min_z; + int max_z; + int cur_z; + int all_types; + int cur_type; + int radius; + + int tiles_per_layer; + int tiles_loaded; + int layers_total; + int layers_loaded; + + AltosMap map; + AltosMapCache cache; + + public void do_load() { + map.set_zoom(cur_z + AltosMap.default_zoom); + map.set_maptype(cur_type); + map.set_load_params(latitude, longitude, radius, this); + } + + public int next_type(int start) { + int next_type; + for (next_type = start; + next_type <= AltosMap.maptype_terrain && (all_types & (1 << next_type)) == 0; + next_type++) + ; + return next_type; + } + + public void next_load() { + int next_type = next_type(cur_type + 1); + + if (next_type > AltosMap.maptype_terrain) { + if (cur_z == max_z) { + return; + } else { + cur_z++; + } + next_type = next_type(0); + } + cur_type = next_type; + do_load(); + } + + private void start_load() { + + cur_z = min_z; + int ntype = 0; + + for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) + if ((all_types & (1 << t)) != 0) + ntype++; + if (ntype == 0) { + all_types = (1 << AltosMap.maptype_hybrid); + ntype = 1; + } + + cur_type = next_type(0); + tiles_per_layer = (radius * 2 + 1) * (radius * 2 + 1); + layers_total = (max_z - min_z + 1) * ntype; + layers_loaded = 0; + tiles_loaded = 0; + + listener.loader_start(layers_total * tiles_per_layer); + do_load(); + } + + public void load(double latitude, double longitude, int min_z, int max_z, int radius, int all_types) { + this.latitude = latitude; + this.longitude = longitude; + this.min_z = min_z; + this.max_z = max_z; + this.radius = radius; + this.all_types = all_types; + start_load(); + } + + public synchronized void notify_tile(AltosMapTile tile, int status) { + boolean do_next = false; + if (status == AltosMapTile.loading) + return; + + if (layers_loaded >= layers_total) + return; + + ++tiles_loaded; + + if (tiles_loaded == tiles_per_layer) { + tiles_loaded = 0; + ++layers_loaded; + if (layers_loaded == layers_total) { + listener.loader_done(layers_total * tiles_per_layer); + return; + } else { + do_next = true; + } + } + listener.loader_notify(layers_loaded * tiles_per_layer + tiles_loaded, + layers_total * tiles_per_layer, tile.store.file.toString()); + if (do_next) + next_load(); + } + + public AltosMapCache cache() { return cache; } + + public AltosMapLoader(AltosMap map, AltosMapCache cache, + AltosMapLoaderListener listener) { + this.map = map; + this.cache = cache; + this.listener = listener; + } +} -- cgit v1.2.3 From ba698c2cc48677735046d0881df9c180674e4082 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 28 May 2015 01:01:23 -0700 Subject: altoslib: Pass all map loader params to set_load_params Add zoom and map type to the param list so we don't call set_zoom and set_maptype separately, which only causes lots of extra image loads to get started unnecessarily. Signed-off-by: Keith Packard --- altoslib/AltosMap.java | 10 ++++++++-- altoslib/AltosMapLoader.java | 11 +++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'altoslib/AltosMapLoader.java') diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index d39c3302..85f95eef 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -248,7 +248,9 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { public void add_mark(double lat, double lon, int state) { synchronized(marks) { - marks.add(map_interface.new_mark(lat, lon, state)); + AltosMapMark mark = map_interface.new_mark(lat, lon, state); + if (mark != null) + marks.add(mark); } repaint(); } @@ -303,11 +305,15 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { } } - public void set_load_params(double lat, double lon, int radius, AltosMapTileListener listener) { + public void set_load_params(int new_zoom, int new_type, double lat, double lon, int radius, AltosMapTileListener listener) { + if (AltosMap.min_zoom <= new_zoom && new_zoom <= AltosMap.max_zoom) + zoom = new_zoom; + maptype = new_type; load_centre = new AltosLatLon(lat, lon); load_radius = radius; load_listener = listener; centre(lat, lon); + tiles.clear(); make_tiles(); for (AltosMapTile tile : tiles.values()) { tile.add_store_listener(this); diff --git a/altoslib/AltosMapLoader.java b/altoslib/AltosMapLoader.java index 5db20cf8..cf7169ba 100644 --- a/altoslib/AltosMapLoader.java +++ b/altoslib/AltosMapLoader.java @@ -41,12 +41,9 @@ public class AltosMapLoader implements AltosMapTileListener { int layers_loaded; AltosMap map; - AltosMapCache cache; public void do_load() { - map.set_zoom(cur_z + AltosMap.default_zoom); - map.set_maptype(cur_type); - map.set_load_params(latitude, longitude, radius, this); + map.set_load_params(cur_z + AltosMap.default_zoom, cur_type, latitude, longitude, radius, this); } public int next_type(int start) { @@ -132,12 +129,10 @@ public class AltosMapLoader implements AltosMapTileListener { next_load(); } - public AltosMapCache cache() { return cache; } + public AltosMapCache cache() { return map.cache(); } - public AltosMapLoader(AltosMap map, AltosMapCache cache, - AltosMapLoaderListener listener) { + public AltosMapLoader(AltosMap map, AltosMapLoaderListener listener) { this.map = map; - this.cache = cache; this.listener = listener; } } -- cgit v1.2.3 From d015cfc1499a263549f52d46e9e5b934fcb94f53 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 11 Jul 2015 19:15:08 -0700 Subject: altoslib: Preload maps based on distance rather than number of tiles This lets you get the specific area requested at all zoom levels, rather than having further detail only at lower resolution zooms. Signed-off-by: Keith Packard --- altosdroid/res/layout/map_preload.xml | 8 +- altosdroid/res/values/strings.xml | 2 +- .../altusmetrum/AltosDroid/PreloadMapActivity.java | 66 +++++++++++++-- altoslib/AltosMapLoader.java | 99 ++++++++++++++++++---- altoslib/AltosMapLoaderListener.java | 2 + altosuilib/AltosUIMapPreloadNew.java | 35 ++++++-- 6 files changed, 179 insertions(+), 33 deletions(-) (limited to 'altoslib/AltosMapLoader.java') diff --git a/altosdroid/res/layout/map_preload.xml b/altosdroid/res/layout/map_preload.xml index 1d1fca32..dc613bf2 100644 --- a/altosdroid/res/layout/map_preload.xml +++ b/altosdroid/res/layout/map_preload.xml @@ -103,15 +103,15 @@ android:prompt="@string/preload_max_zoom" android:spinnerMode="dropdown" /> - -