altoslib: Add set_zoom_centre to AltosMap
authorKeith Packard <keithp@keithp.com>
Sun, 21 Jun 2015 16:34:29 +0000 (09:34 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 23 Jun 2015 04:04:43 +0000 (21:04 -0700)
This zooms around a specific point, keeping it at the same place on
the screen.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMap.java

index 59420d4b389bf7c2c4b27142419bdbd320ddd3c6..adf52ab9469d0be1405a4295a201b92fe7dca718 100644 (file)
@@ -166,6 +166,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
 
        public boolean set_zoom(int zoom) {
+               notice_user_input();
                if (AltosMap.min_zoom <= zoom && zoom <= AltosMap.max_zoom && zoom != this.zoom) {
                        this.zoom = zoom;
                        tiles.clear();
@@ -176,6 +177,29 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                return false;
        }
 
+       public boolean set_zoom_centre(int zoom, AltosPointInt centre) {
+               AltosLatLon     mouse_lat_lon = null;
+               boolean         ret;
+
+               if (transform != null)
+                       mouse_lat_lon = transform.screen_lat_lon(centre);
+
+               ret = set_zoom(zoom);
+
+               if (ret && mouse_lat_lon != null) {
+                       AltosPointDouble        new_mouse = transform.screen(mouse_lat_lon);
+
+                       double  dx = width()/2.0 - centre.x;
+                       double  dy = height()/2.0 - centre.y;
+
+                       AltosLatLon     new_centre = transform.screen_lat_lon(new AltosPointDouble(new_mouse.x + dx, new_mouse.y + dy));
+
+                       centre(new_centre);
+               }
+
+               return ret;
+       }
+
        public int get_zoom() {
                return zoom;
        }