[android] - limit the scale factor for double tap zoom (#7580)

* [android] - limit the scale factor to avoid accelerating the double tap zoom gesture

* clamp values
This commit is contained in:
Tobrun
2017-01-03 20:27:44 +01:00
committed by GitHub
parent 5ac72ce8bf
commit 654061c7d1
3 changed files with 17 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
## 5.0.0 - TBA
* Consistent double tap zoom acceleration [#7514](https://github.com/mapbox/mapbox-gl-native/issues/7514)
* Support for Android Nougat [#5910](5910-move-listener-logic-for-nougat) & [#6390](https://github.com/mapbox/mapbox-gl-native/pull/6390)
## 4.2.1 - December 22, 2016

View File

@@ -82,6 +82,16 @@ public class MapboxConstants {
*/
public static final double MINIMUM_DIRECTION = 0;
/**
* The currently used minimun scale factor to clamp to when a quick zoom gesture occurs
*/
public static final float MINIMUM_SCALE_FACTOR_CLAMP = 0.65f;
/**
* The currently used maximum scale factor to clamp to when a quick zoom gesture occurs
*/
public static final float MAXIMUM_SCALE_FACTOR_CLAMP = 1.35f;
/**
* Fragment Argument Key for MapboxMapOptions
*/

View File

@@ -16,6 +16,7 @@ import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector;
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
import com.mapbox.mapboxsdk.utils.MathUtils;
/**
* Manages gestures events on a MapView.
@@ -427,8 +428,12 @@ final class MapGestureDetector {
// arround user provided focal point
transform.zoomBy(detector.getScaleFactor(), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
// clamp scale factors we feed to core #7514
float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
MapboxConstants.MAXIMUM_SCALE_FACTOR_CLAMP);
// around center map
transform.zoomBy(detector.getScaleFactor(), uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
transform.zoomBy(scaleFactor, uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
} else {
// around gesture
transform.zoomBy(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());