From 29edc37a8de56cb6eb028e3bf3f56aa70f109eba Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 May 2015 13:49:28 -0700 Subject: altoslib: Create display-independent map support code This takes the swing-specific map code and creates a generic version. Signed-off-by: Keith Packard --- altoslib/Makefile.am | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'altoslib/Makefile.am') diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index c640c69c..0ee7b935 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -128,7 +128,28 @@ altoslib_JAVA = \ AltosPyro.java \ AltosWriter.java \ AltosQuaternion.java \ - AltosRotation.java + AltosRotation.java \ + AltosImage.java \ + AltosLatLon.java \ + AltosMap.java \ + AltosMapCache.java \ + AltosMapCacheListener.java \ + AltosMapInterface.java \ + AltosMapLine.java \ + AltosMapMark.java \ + AltosMapPath.java \ + AltosMapRectangle.java \ + AltosMapStore.java \ + AltosMapStoreListener.java \ + AltosMapTile.java \ + AltosMapTileListener.java \ + AltosMapTransform.java \ + AltosMapZoomListener.java \ + AltosPointDouble.java \ + AltosPointInt.java \ + AltosFlightDisplay.java \ + AltosFontListener.java \ + AltosVersion.java JAR=altoslib_$(ALTOSLIB_VERSION).jar -- cgit v1.2.3 From 00aca369c4070901e0400f291d5f269b5fb8015c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 25 May 2015 20:10:37 -0700 Subject: altoslib: Get new abstract mapping code compiling Not useful yet, but at least it compiles now? Signed-off-by: Keith Packard --- altoslib/AltosMap.java | 48 +++++++++++++++++++++++++++-------------- altoslib/AltosMapInterface.java | 15 ++++++------- altoslib/AltosMapLine.java | 14 ++++++------ altoslib/AltosMapPath.java | 25 ++++----------------- altoslib/AltosMapPathPoint.java | 41 +++++++++++++++++++++++++++++++++++ altoslib/AltosMapTile.java | 4 +++- altoslib/AltosMapTransform.java | 20 +++++++++++------ altoslib/AltosRectangle.java | 29 +++++++++++++++++++++++++ altoslib/Makefile.am | 2 ++ 9 files changed, 138 insertions(+), 60 deletions(-) create mode 100644 altoslib/AltosMapPathPoint.java create mode 100644 altoslib/AltosRectangle.java (limited to 'altoslib/Makefile.am') diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index b42f9f85..f8c3a36b 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -24,19 +24,19 @@ import java.util.concurrent.*; public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, AltosMapStoreListener { - static final int px_size = 512; + public static final int px_size = 512; - static final int maptype_hybrid = 0; - static final int maptype_roadmap = 1; - static final int maptype_satellite = 2; - static final int maptype_terrain = 3; - static final int maptype_default = maptype_hybrid; + public static final int maptype_hybrid = 0; + public static final int maptype_roadmap = 1; + public static final int maptype_satellite = 2; + public static final int maptype_terrain = 3; + public static final int maptype_default = maptype_hybrid; - static final int default_zoom = 15; - static final int min_zoom = 3; - static final int max_zoom = 21; + public static final int default_zoom = 15; + public static final int min_zoom = 3; + public static final int max_zoom = 21; - static final String[] maptype_names = { + public static final String[] maptype_names = { "hybrid", "roadmap", "satellite", @@ -157,7 +157,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos } public void font_size_changed(int font_size) { - map_interface.line.font_size_changed(font_size); + map_interface.line().font_size_changed(font_size); for (AltosMapTile tile : tiles.values()) tile.font_size_changed(font_size); repaint(); @@ -211,7 +211,7 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos if (!gps.locked && gps.nsat < 4) return; - AltosMapRectangle damage = map_interface.path.add(gps.lat, gps.lon, state.state); + AltosMapRectangle damage = map_interface.path().add(gps.lat, gps.lon, state.state); switch (state.state) { case AltosLib.ao_flight_boost: @@ -279,8 +279,8 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos lower_right = new AltosPointInt(centre.x + load_radius * AltosMap.px_size, centre.y + load_radius * AltosMap.px_size); } else { - upper_left = floor(transform.screen_point(new AltosPointDouble(0.0, 0.0))); - lower_right = floor(transform.screen_point(new AltosPointDouble(width(), height()))); + upper_left = floor(transform.screen_point(new AltosPointInt(0, 0))); + lower_right = floor(transform.screen_point(new AltosPointInt(width(), height()))); } LinkedList to_remove = new LinkedList(); @@ -302,8 +302,8 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos if (!tiles.containsKey(point)) { AltosLatLon ul = transform.lat_lon(new AltosPointDouble(x, y)); AltosLatLon center = transform.lat_lon(new AltosPointDouble(x + AltosMap.px_size/2, y + AltosMap.px_size/2)); - AltosMapTile tile = new AltosMapTile(this, ul, center, zoom, maptype, - AltosMap.px_size); + AltosMapTile tile = map_interface.new_tile(this, ul, center, zoom, maptype, + AltosMap.px_size); tiles.put(point, tile); } } @@ -328,6 +328,22 @@ public class AltosMap implements AltosFlightDisplay, AltosMapTileListener, Altos return "Map"; } + public void paint() { + make_tiles(); + + for (AltosMapTile tile : tiles.values()) + tile.paint(transform); + + synchronized(marks) { + for (AltosMapMark mark : marks) + mark.paint(transform); + } + + map_interface.path().paint(transform); + + map_interface.line().paint(transform); + } + /* AltosMapTileListener methods */ public synchronized void notify_tile(AltosMapTile tile, int status) { for (AltosPointInt point : tiles.keySet()) { diff --git a/altoslib/AltosMapInterface.java b/altoslib/AltosMapInterface.java index ea5454de..c548744b 100644 --- a/altoslib/AltosMapInterface.java +++ b/altoslib/AltosMapInterface.java @@ -20,16 +20,18 @@ package org.altusmetrum.altoslib_6; import java.io.*; import java.net.*; -public abstract class AltosMapInterface { - - public AltosMapPath path; - public AltosMapLine line; +public interface AltosMapInterface { + public abstract AltosMapPath path(); + public abstract AltosMapLine line(); public abstract AltosImage load_image(File file) throws Exception; public abstract AltosMapMark new_mark(double lat, double lon, int state); + public abstract AltosMapTile new_tile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size); + public abstract int width(); + public abstract int height(); public abstract void repaint(); @@ -39,9 +41,4 @@ public abstract class AltosMapInterface { public abstract void repaint(double x, double y, double w, double h); public abstract void set_units(); - - public AltosMapInterface (AltosMapPath path, AltosMapLine line) { - this.path = path; - this.line = line; - } } diff --git a/altoslib/AltosMapLine.java b/altoslib/AltosMapLine.java index 83de47f9..77807b94 100644 --- a/altoslib/AltosMapLine.java +++ b/altoslib/AltosMapLine.java @@ -23,26 +23,28 @@ import java.util.*; import java.util.concurrent.*; public abstract class AltosMapLine implements AltosFontListener { - AltosLatLon start, end; + public AltosLatLon start, end; static public int stroke_width = 6; public abstract void font_size_changed(int font_size); - private AltosLatLon lat_lon(AltosPointDouble pt, AltosMapTransform t) { + public abstract void paint(AltosMapTransform t); + + private AltosLatLon lat_lon(AltosPointInt pt, AltosMapTransform t) { return t.screen_lat_lon(pt); } - public void dragged(AltosPointDouble pt, AltosMapTransform t) { + public void dragged(AltosPointInt pt, AltosMapTransform t) { end = lat_lon(pt, t); } - public void pressed(AltosPointDouble pt, AltosMapTransform t) { + public void pressed(AltosPointInt pt, AltosMapTransform t) { start = lat_lon(pt, t); end = null; } - private String line_dist() { + public String line_dist() { String format; AltosGreatCircle g = new AltosGreatCircle(start.lat, start.lon, end.lat, end.lon); @@ -78,6 +80,4 @@ public abstract class AltosMapLine implements AltosFontListener { } return String.format(format, distance); } - - public abstract void paint(AltosMapTransform t); } diff --git a/altoslib/AltosMapPath.java b/altoslib/AltosMapPath.java index 272a4316..e7224b57 100644 --- a/altoslib/AltosMapPath.java +++ b/altoslib/AltosMapPath.java @@ -22,34 +22,17 @@ import java.lang.Math; import java.util.*; import java.util.concurrent.*; -class PathPoint { - AltosLatLon lat_lon; - int state; - - public PathPoint(AltosLatLon lat_lon, int state) { - this.lat_lon = lat_lon; - this.state = state; - } - - public boolean equals(PathPoint other) { - if (other == null) - return false; - - return lat_lon.equals(other.lat_lon) && state == other.state; - } -} - public abstract class AltosMapPath { - LinkedList points = new LinkedList(); - PathPoint last_point = null; + public LinkedList points = new LinkedList(); + public AltosMapPathPoint last_point = null; static public int stroke_width = 6; public abstract void paint(AltosMapTransform t); public AltosMapRectangle add(double lat, double lon, int state) { - PathPoint point = new PathPoint(new AltosLatLon (lat, lon), state); + AltosMapPathPoint point = new AltosMapPathPoint(new AltosLatLon (lat, lon), state); AltosMapRectangle rect = null; if (!point.equals(last_point)) { @@ -62,6 +45,6 @@ public abstract class AltosMapPath { } public void clear () { - points = new LinkedList(); + points = new LinkedList(); } } diff --git a/altoslib/AltosMapPathPoint.java b/altoslib/AltosMapPathPoint.java new file mode 100644 index 00000000..757211af --- /dev/null +++ b/altoslib/AltosMapPathPoint.java @@ -0,0 +1,41 @@ +/* + * 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_6; + +import java.io.*; +import java.lang.Math; +import java.util.*; +import java.util.concurrent.*; + +public class AltosMapPathPoint { + public AltosLatLon lat_lon; + public int state; + + public boolean equals(AltosMapPathPoint other) { + if (other == null) + return false; + + return lat_lon.equals(other.lat_lon) && state == other.state; + } + + public AltosMapPathPoint(AltosLatLon lat_lon, int state) { + this.lat_lon = lat_lon; + this.state = state; + } +} + diff --git a/altoslib/AltosMapTile.java b/altoslib/AltosMapTile.java index b5dee7a4..923b7c6b 100644 --- a/altoslib/AltosMapTile.java +++ b/altoslib/AltosMapTile.java @@ -20,7 +20,7 @@ package org.altusmetrum.altoslib_6; import java.io.*; import java.util.*; -public class AltosMapTile implements AltosFontListener { +public abstract class AltosMapTile implements AltosFontListener { AltosMapTileListener listener; AltosLatLon upper_left, center; int px_size; @@ -94,6 +94,8 @@ public class AltosMapTile implements AltosFontListener { store.remove_listener(listener); } + public abstract void paint(AltosMapTransform t); + public AltosMapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { this.listener = listener; this.upper_left = upper_left; diff --git a/altoslib/AltosMapTransform.java b/altoslib/AltosMapTransform.java index f5fc5ebe..384c1744 100644 --- a/altoslib/AltosMapTransform.java +++ b/altoslib/AltosMapTransform.java @@ -39,10 +39,18 @@ public class AltosMapTransform { return new AltosLatLon(lat,lon); } + public AltosPointDouble screen_point(AltosPointInt screen) { + return new AltosPointDouble(screen.x + offset_x, screen.y + offset_y); + } + public AltosPointDouble screen_point(AltosPointDouble screen) { return new AltosPointDouble(screen.x + offset_x, screen.y + offset_y); } + public AltosLatLon screen_lat_lon(AltosPointInt screen) { + return lat_lon(screen_point(screen)); + } + public AltosLatLon screen_lat_lon(AltosPointDouble screen) { return lat_lon(screen_point(screen)); } @@ -71,12 +79,12 @@ public class AltosMapTransform { (int) (point.y - offset_y + 0.5)); } -// public Rectangle screen(AltosMapRectangle map_rect) { -// AltosPoint2D ul = screen(map_rect.ul); -// AltosPoint2D lr = screen(map_rect.lr); -// -// return new Rectangle((int) ul.x, (int) ul.y, (int) (lr.x - ul.x), (int) (lr.y - ul.y)); -// } + public AltosRectangle screen(AltosMapRectangle map_rect) { + AltosPointDouble ul = screen(map_rect.ul); + AltosPointDouble lr = screen(map_rect.lr); + + return new AltosRectangle((int) ul.x, (int) ul.y, (int) (lr.x - ul.x), (int) (lr.y - ul.y)); + } public AltosPointDouble screen(AltosLatLon lat_lon) { return screen(point(lat_lon)); diff --git a/altoslib/AltosRectangle.java b/altoslib/AltosRectangle.java new file mode 100644 index 00000000..c55fd613 --- /dev/null +++ b/altoslib/AltosRectangle.java @@ -0,0 +1,29 @@ +/* + * 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_6; + +public class AltosRectangle { + public int x, y, width, height; + + public AltosRectangle(int x, int y, int w, int h) { + this.x = x; + this.y = y; + this.width = w; + this.height = h; + } +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 0ee7b935..481c974f 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -138,6 +138,7 @@ altoslib_JAVA = \ AltosMapLine.java \ AltosMapMark.java \ AltosMapPath.java \ + AltosMapPathPoint.java \ AltosMapRectangle.java \ AltosMapStore.java \ AltosMapStoreListener.java \ @@ -147,6 +148,7 @@ altoslib_JAVA = \ AltosMapZoomListener.java \ AltosPointDouble.java \ AltosPointInt.java \ + AltosRectangle.java \ AltosFlightDisplay.java \ AltosFontListener.java \ AltosVersion.java -- cgit v1.2.3 From 519d477cb752d9cdba78a4daa32b1f547bf889b4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 27 May 2015 15:30:29 -0700 Subject: altoslib: Add AltosLaunchSite bits This asynchronously fetches the list of available launch sites from the standard location and notifies the caller when finished. Signed-off-by: Keith Packard --- altoslib/AltosLaunchSite.java | 57 +++++++++++++++++++++++++++ altoslib/AltosLaunchSiteListener.java | 26 +++++++++++++ altoslib/AltosLaunchSites.java | 73 +++++++++++++++++++++++++++++++++++ altoslib/Makefile.am | 3 ++ 4 files changed, 159 insertions(+) create mode 100644 altoslib/AltosLaunchSite.java create mode 100644 altoslib/AltosLaunchSiteListener.java create mode 100644 altoslib/AltosLaunchSites.java (limited to 'altoslib/Makefile.am') diff --git a/altoslib/AltosLaunchSite.java b/altoslib/AltosLaunchSite.java new file mode 100644 index 00000000..70a4bb58 --- /dev/null +++ b/altoslib/AltosLaunchSite.java @@ -0,0 +1,57 @@ +/* + * 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.lang.*; +import java.util.*; +import java.text.*; +import java.util.concurrent.*; + +public class AltosLaunchSite { + public String name; + public double latitude; + public double longitude; + + public String toString() { + return name; + } + + public AltosLaunchSite(String in_name, double in_latitude, double in_longitude) { + name = in_name; + latitude = in_latitude; + longitude = in_longitude; + } + + public AltosLaunchSite(String line) throws ParseException { + String[] elements = line.split(":"); + + if (elements.length < 3) + throw new ParseException(String.format("Invalid site line %s", line), 0); + + name = elements[0]; + + try { + latitude = AltosParse.parse_double_net(elements[1]); + longitude = AltosParse.parse_double_net(elements[2]); + } catch (ParseException pe) { + throw new ParseException(String.format("Invalid site line %s", line), 0); + } + } +} + diff --git a/altoslib/AltosLaunchSiteListener.java b/altoslib/AltosLaunchSiteListener.java new file mode 100644 index 00000000..21015909 --- /dev/null +++ b/altoslib/AltosLaunchSiteListener.java @@ -0,0 +1,26 @@ +/* + * 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.lang.*; +import java.util.*; +import java.util.concurrent.*; + +public interface AltosLaunchSiteListener { + public abstract void notify_launch_sites(List sites); +} diff --git a/altoslib/AltosLaunchSites.java b/altoslib/AltosLaunchSites.java new file mode 100644 index 00000000..0922bcea --- /dev/null +++ b/altoslib/AltosLaunchSites.java @@ -0,0 +1,73 @@ +/* + * 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.lang.*; +import java.util.*; +import java.util.concurrent.*; +import java.net.*; +import java.text.*; + +public class AltosLaunchSites extends Thread { + URL url; + LinkedList sites; + AltosLaunchSiteListener listener; + + void notify_complete() { + listener.notify_launch_sites(sites); + } + + void add(AltosLaunchSite site) { + sites.add(site); + } + + void add(String line) { + try { + add(new AltosLaunchSite(line)); + } catch (ParseException pe) { + System.out.printf("parse exception %s\n", pe.toString()); + } + } + + public void run() { + try { + url = new URL(AltosLib.launch_sites_url); + URLConnection uc = url.openConnection(); + + InputStreamReader in_stream = new InputStreamReader(uc.getInputStream(), AltosLib.unicode_set); + BufferedReader in = new BufferedReader(in_stream); + + for (;;) { + String line = in.readLine(); + if (line == null) + break; + add(line); + } + } catch (Exception e) { + } finally { + notify_complete(); + } + } + + public AltosLaunchSites(AltosLaunchSiteListener listener) { + sites = new LinkedList(); + this.listener = listener; + start(); + } +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index 481c974f..de13c1ec 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -151,6 +151,9 @@ altoslib_JAVA = \ AltosRectangle.java \ AltosFlightDisplay.java \ AltosFontListener.java \ + AltosLaunchSite.java \ + AltosLaunchSiteListener.java \ + AltosLaunchSites.java \ AltosVersion.java JAR=altoslib_$(ALTOSLIB_VERSION).jar -- cgit v1.2.3 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 +++++++++++++++++++++++++++++++++++ altoslib/AltosMapLoaderListener.java | 26 +++++++ altoslib/Makefile.am | 2 + 3 files changed, 171 insertions(+) create mode 100644 altoslib/AltosMapLoader.java create mode 100644 altoslib/AltosMapLoaderListener.java (limited to 'altoslib/Makefile.am') 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; + } +} diff --git a/altoslib/AltosMapLoaderListener.java b/altoslib/AltosMapLoaderListener.java new file mode 100644 index 00000000..79f8b9df --- /dev/null +++ b/altoslib/AltosMapLoaderListener.java @@ -0,0 +1,26 @@ +/* + * 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; + +public interface AltosMapLoaderListener { + public abstract void loader_start(int max); + + public abstract void loader_notify(int cur, int max, String name); + + public abstract void loader_done(int max); +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index de13c1ec..a6b178fa 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -154,6 +154,8 @@ altoslib_JAVA = \ AltosLaunchSite.java \ AltosLaunchSiteListener.java \ AltosLaunchSites.java \ + AltosMapLoaderListener.java \ + AltosMapLoader.java \ AltosVersion.java JAR=altoslib_$(ALTOSLIB_VERSION).jar -- cgit v1.2.3