From e0c318cdd32b3c3fed5099c754aea3ebc6186a0f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 21 Jun 2015 09:34:29 -0700 Subject: [PATCH] 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 --- altoslib/AltosMap.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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; } -- 2.30.2