X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMapTransform.java;h=b8f2910760baa6f22d09840ad80739d52e562cd6;hb=master;hp=ba9d1ae46121ca5ce72895562dd13ec736e88a38;hpb=76b288f8d02e0a48f04de9455a2dd0b77e48bd63;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);