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",
}
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();
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:
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<AltosPointInt> to_remove = new LinkedList<AltosPointInt>();
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);
}
}
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()) {
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();
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;
- }
}
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);
}
return String.format(format, distance);
}
-
- public abstract void paint(AltosMapTransform t);
}
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<PathPoint> points = new LinkedList<PathPoint>();
- PathPoint last_point = null;
+ public LinkedList<AltosMapPathPoint> points = new LinkedList<AltosMapPathPoint>();
+ 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)) {
}
public void clear () {
- points = new LinkedList<PathPoint>();
+ points = new LinkedList<AltosMapPathPoint>();
}
}
--- /dev/null
+/*
+ * Copyright © 2015 Keith Packard <keithp@keithp.com>
+ *
+ * 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;
+ }
+}
+
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;
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;
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));
}
(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));
--- /dev/null
+/*
+ * Copyright © 2015 Keith Packard <keithp@keithp.com>
+ *
+ * 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;
+ }
+}
AltosMapLine.java \
AltosMapMark.java \
AltosMapPath.java \
+ AltosMapPathPoint.java \
AltosMapRectangle.java \
AltosMapStore.java \
AltosMapStoreListener.java \
AltosMapZoomListener.java \
AltosPointDouble.java \
AltosPointInt.java \
+ AltosRectangle.java \
AltosFlightDisplay.java \
AltosFontListener.java \
AltosVersion.java