From cc87c16b347acc53575d71b31aa1ed58217336c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Mon, 20 Jul 2015 00:44:38 +0200 Subject: [PATCH] Support zooming via mouse wheel. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Behaviour should possibly be fine-tuned to use a smooth instead of animated zooming and to keep the cursor position as a fixed point instead of moving it to the center. Still, this should be a small improvement for usage with mouse. Signed-off-by: Reimar Döffinger --- .../osmand/plus/views/OsmAndMapLayersView.java | 8 ++++++++ .../osmand/plus/views/OsmAndMapSurfaceView.java | 8 ++++++++ .../osmand/plus/views/OsmandMapTileView.java | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmAndMapLayersView.java b/OsmAnd/src/net/osmand/plus/views/OsmAndMapLayersView.java index d21ced8e20..5141e58129 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmAndMapLayersView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmAndMapLayersView.java @@ -50,6 +50,14 @@ public class OsmAndMapLayersView extends View { return r; } + @Override + public boolean onGenericMotionEvent(MotionEvent event) { + if(mapView == null) { + return super.onGenericMotionEvent(event); + } + return mapView.onGenericMotionEvent(event); + } + @Override public boolean onTouchEvent(MotionEvent event) { if(mapView == null) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmAndMapSurfaceView.java b/OsmAnd/src/net/osmand/plus/views/OsmAndMapSurfaceView.java index 844628b4b7..4a9b47e008 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmAndMapSurfaceView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmAndMapSurfaceView.java @@ -87,6 +87,14 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback { return r; } + @Override + public boolean onGenericMotionEvent(MotionEvent event) { + if(mapView == null) { + return super.onGenericMotionEvent(event); + } + return mapView.onGenericMotionEvent(event); + } + @Override public boolean onTouchEvent(MotionEvent event) { if(mapView == null) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index f9c20d5781..7be62ca800 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -49,6 +49,7 @@ import android.util.DisplayMetrics; import android.view.GestureDetector; import android.view.GestureDetector.OnDoubleTapListener; import android.view.GestureDetector.OnGestureListener; +import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceHolder; @@ -729,6 +730,20 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } + public boolean onGenericMotionEvent(MotionEvent event) { + if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 && + event.getAction() == MotionEvent.ACTION_SCROLL && + event.getAxisValue(MotionEvent.AXIS_VSCROLL) != 0) { + final RotatedTileBox tb = getCurrentRotatedTileBox(); + final double lat = tb.getLatFromPixel(event.getX(), event.getY()); + final double lon = tb.getLonFromPixel(event.getX(), event.getY()); + int zoomDir = event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0 ? -1 : 1; + getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + zoomDir, true); + return true; + } + return false; + } + public boolean onTouchEvent(MotionEvent event) { if (mapRenderer != null) { if (event.getAction() == MotionEvent.ACTION_DOWN) { @@ -996,4 +1011,4 @@ public class OsmandMapTileView implements IMapDownloaderCallback { return activity; } -} \ No newline at end of file +}