From: Keith Packard Date: Sun, 21 Jun 2015 16:34:29 +0000 (-0700) Subject: altoslib: Add set_zoom_centre to AltosMap X-Git-Tag: 1.6.0.3~21 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=e0c318cdd32b3c3fed5099c754aea3ebc6186a0f altoslib: Add set_zoom_centre to AltosMap This zooms around a specific point, keeping it at the same place on the screen. Signed-off-by: Keith Packard --- diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index 59420d4b..adf52ab9 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -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; }