X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMapTransform.java;h=3f8f290c9f87faa419358de317a3210ea879d583;hb=3ed101d634968666cd3ee2d8c49737970caf406b;hp=ba9d1ae46121ca5ce72895562dd13ec736e88a38;hpb=52149fd81df45f37f5097850795f290f463c43ef;p=fw%2Faltos diff --git a/altoslib/AltosMapTransform.java b/altoslib/AltosMapTransform.java index ba9d1ae4..3f8f290c 100644 --- a/altoslib/AltosMapTransform.java +++ b/altoslib/AltosMapTransform.java @@ -29,6 +29,8 @@ public class AltosMapTransform { double offset_x, offset_y; + int width, height; + public AltosLatLon lat_lon (AltosPointDouble point) { double lat, lon; double rads; @@ -110,6 +112,39 @@ public class AltosMapTransform { return screen(point(lat, lon)); } + /* Return first longitude value which ends up on-screen */ + public double first_lon(double lon) { + /* Find a longitude left of the screen */ + for (;;) { + double x = lon * scale_x - offset_x; + if (x < 0) + break; + lon -= 360.0; + } + /* Find the first longitude on the screen */ + for (;;) { + double x = lon * scale_x - offset_x; + if (x >= 0) + break; + lon += 360.0; + } + return lon; + } + + /* Return last longitude value which ends up on-screen */ + public double last_lon(double lon) { + lon = first_lon(lon); + + for(;;) { + double next_lon = lon + 360.0; + double next_x = next_lon * scale_x - offset_x; + if (next_x >= width) + break; + lon = next_lon; + } + return lon; + } + private boolean has_location; public boolean has_location() { @@ -120,6 +155,9 @@ public class AltosMapTransform { scale_x = 256/360.0 * Math.pow(2, zoom); scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); + this.width = width; + this.height = height; + AltosPointDouble centre_pt = point(centre_lat_lon); has_location = (centre_lat_lon.lat != 0 || centre_lat_lon.lon != 0);