summaryrefslogtreecommitdiff
path: root/altoslib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-08-31 23:20:31 -0500
committerKeith Packard <keithp@keithp.com>2019-08-31 23:20:31 -0500
commitb13893245e8c66b48e23bb2005ef6ce46e69744f (patch)
tree88813e4b389805463313de527f1c7c4176c61fe7 /altoslib
parent936a5ff21d01db6f0084ee7e4712042c914942a5 (diff)
altosui: Display data for point nearest cursor in map view
Include time, lat and lon Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib')
-rw-r--r--altoslib/AltosMap.java24
-rw-r--r--altoslib/AltosMapPath.java29
-rw-r--r--altoslib/AltosMapPathPoint.java4
3 files changed, 49 insertions, 8 deletions
diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java
index b033cbff..b9c4bfc1 100644
--- a/altoslib/AltosMap.java
+++ b/altoslib/AltosMap.java
@@ -222,7 +222,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
return false;
}
- public void show(AltosGPS gps, int state) {
+ public void show(AltosGPS gps, double time, int state) {
/*
* If insufficient gps data, nothing to update
@@ -250,7 +250,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
}
if (path != null) {
- AltosMapRectangle damage = path.add(gps.lat, gps.lon, state);
+ AltosMapRectangle damage = path.add(gps.lat, gps.lon, time, state);
if (damage != null)
repaint(damage, AltosMapPath.stroke_width);
@@ -262,7 +262,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
}
public void show(AltosState state, AltosListenerState listener_state) {
- show(state.gps, state.state());
+ show(state.gps, state.time, state.state());
}
public void centre(AltosLatLon lat_lon) {
@@ -290,13 +290,19 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
centre(lat_lon);
}
- public void add_mark(double lat, double lon, int state) {
+ public AltosMapMark add_mark(double lat, double lon, int state) {
+ AltosMapMark mark;
synchronized(marks) {
- AltosMapMark mark = map_interface.new_mark(lat, lon, state);
+ mark = map_interface.new_mark(lat, lon, state);
if (mark != null)
marks.add(mark);
}
repaint();
+ return mark;
+ }
+
+ public void del_mark(AltosMapMark mark) {
+ marks.remove(mark);
}
public void clear_marks() {
@@ -490,6 +496,14 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
drag_stop(x, y);
}
+ public AltosMapPathPoint nearest(int x, int y) {
+ notice_user_input();
+ if (path == null)
+ return null;
+ AltosLatLon at = transform.screen_lat_lon(new AltosPointInt(x, y));
+ return path.nearest(at);
+ }
+
public AltosMap(AltosMapInterface map_interface, int scale) {
this.map_interface = map_interface;
this.scale = scale;
diff --git a/altoslib/AltosMapPath.java b/altoslib/AltosMapPath.java
index 7104b2f6..54ff51fc 100644
--- a/altoslib/AltosMapPath.java
+++ b/altoslib/AltosMapPath.java
@@ -32,8 +32,8 @@ public abstract class AltosMapPath {
public abstract void paint(AltosMapTransform t);
- public AltosMapRectangle add(double lat, double lon, int state) {
- AltosMapPathPoint point = new AltosMapPathPoint(new AltosLatLon (lat, lon), state);
+ public AltosMapRectangle add(double lat, double lon, double time, int state) {
+ AltosMapPathPoint point = new AltosMapPathPoint(new AltosLatLon (lat, lon), time, state);
AltosMapRectangle rect = null;
if (!point.equals(last_point)) {
@@ -45,6 +45,31 @@ public abstract class AltosMapPath {
return rect;
}
+ private double dist(AltosLatLon lat_lon, AltosMapPathPoint point) {
+ return (new AltosGreatCircle(lat_lon.lat,
+ lat_lon.lon,
+ point.lat_lon.lat,
+ point.lat_lon.lon)).distance;
+ }
+
+ public AltosMapPathPoint nearest(AltosLatLon lat_lon) {
+ AltosMapPathPoint nearest = null;
+ double nearest_dist = 0;
+ for (AltosMapPathPoint point : points) {
+ if (nearest == null) {
+ nearest = point;
+ nearest_dist = dist(lat_lon, point);
+ } else {
+ double d = dist(lat_lon, point);
+ if (d < nearest_dist) {
+ nearest = point;
+ nearest_dist = d;
+ }
+ }
+ }
+ return nearest;
+ }
+
public void clear () {
points = new LinkedList<AltosMapPathPoint>();
}
diff --git a/altoslib/AltosMapPathPoint.java b/altoslib/AltosMapPathPoint.java
index 9a1edd42..c23d8567 100644
--- a/altoslib/AltosMapPathPoint.java
+++ b/altoslib/AltosMapPathPoint.java
@@ -25,6 +25,7 @@ import java.util.concurrent.*;
public class AltosMapPathPoint {
public AltosLatLon lat_lon;
+ public double time;
public int state;
public int hashCode() {
@@ -43,8 +44,9 @@ public class AltosMapPathPoint {
return lat_lon.equals(other.lat_lon) && state == other.state;
}
- public AltosMapPathPoint(AltosLatLon lat_lon, int state) {
+ public AltosMapPathPoint(AltosLatLon lat_lon, double time, int state) {
this.lat_lon = lat_lon;
+ this.time = time;
this.state = state;
}
}