[android] - fine tune gesture zoom & rotation

This commit is contained in:
Tobrun Van Nuland
2017-10-05 15:04:50 +02:00
committed by Tobrun
parent a1aed6f095
commit 9048d6cfd0
3 changed files with 19 additions and 11 deletions

View File

@@ -54,7 +54,9 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
ViewConfiguration config = ViewConfiguration.get(context);
edgeSlop = config.getScaledEdgeSlop();
// lowering the edgeSlop allows to execute gesture faster
// https://github.com/mapbox/mapbox-gl-native/issues/10102
edgeSlop = config.getScaledEdgeSlop() / 3.0f;
}
@Override

View File

@@ -526,10 +526,10 @@ final class MapGestureDetector {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
private static final long ROTATE_INVOKE_WAIT_TIME = 1500;
private static final long ROTATE_INVOKE_WAIT_TIME = 750;
private static final float ROTATE_INVOKE_ANGLE = 17.5f;
private long beginTime = 0;
private float totalAngle = 0.0f;
private boolean started = false;
// Called when two fingers first touch the screen
@@ -551,7 +551,6 @@ final class MapGestureDetector {
public void onRotateEnd(RotateGestureDetector detector) {
// notify camera change listener
beginTime = 0;
totalAngle = 0.0f;
started = false;
}
@@ -573,8 +572,8 @@ final class MapGestureDetector {
// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
totalAngle += detector.getRotationDegreesDelta();
if (totalAngle > 35.0f || totalAngle < -35.0f) {
float angle = detector.getRotationDegreesDelta();
if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_ROTATION_START, transform));
@@ -589,9 +588,8 @@ final class MapGestureDetector {
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
// Get rotate value
double bearing = transform.getRawBearing();
bearing += detector.getRotationDegreesDelta();
// Calculate map bearing value
double bearing = transform.getRawBearing() + angle;
// Rotate the map
if (focalPoint != null) {

View File

@@ -382,6 +382,10 @@ public class MapView extends FrameLayout {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isMapInitialized()) {
return super.onTouchEvent(event);
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mapZoomButtonController.setVisible(true);
}
@@ -471,7 +475,7 @@ public class MapView extends FrameLayout {
if (destroyed) {
return;
}
if (nativeMapView == null) {
if (!isMapInitialized()) {
mapboxMapOptions.styleUrl(url);
return;
}
@@ -488,7 +492,7 @@ public class MapView extends FrameLayout {
return;
}
if (!isInEditMode() && nativeMapView != null) {
if (!isInEditMode() && isMapInitialized()) {
nativeMapView.resizeView(width, height);
}
}
@@ -574,6 +578,10 @@ public class MapView extends FrameLayout {
}
}
private boolean isMapInitialized() {
return nativeMapView != null;
}
MapboxMap getMapboxMap() {
return mapboxMap;
}