diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-11-09 10:42:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-09 10:42:18 +0100 |
commit | 772324e8f2a316bf82774732dd60bb7af5acdb18 (patch) | |
tree | 34109021f9e7ae14a732c5f98627c892267e9d2d /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | |
parent | efc427f9bbf7fb4b8d8895613dbb29716d5d7b11 (diff) | |
download | qtlocation-mapboxgl-772324e8f2a316bf82774732dd60bb7af5acdb18.tar.gz |
Cherry pick release v4.2.0 (#6944)
* [android] - MyLocationView should facing above when location and compass bearing tracking are enabled. (#6829)
* [android] - use current animated rotation value for calculating animated marker rotation difference (#6826)
fix unit tests, input limiting is not handled by animateRotationBy instead of MarkerView.
Changed test to validate if method was called with correct value.
* [android] - only calculated offset margins for InfoWindow if View is found in current viewport, added example to the test app to test for regressions (#6877)
* upgraded okhttp dependency to latest version (#6880)
* Cancelable callback invocation (#6891)
* [android] - allow onCancel to be invoked from camera cancel callbacks
* set to null after finish
* [android] - using bearing clockwise versus counterclockwise (#6917)
* [android] - using bearing clockwise versus counterclockwise
* fixup brackets
* [android] - convert bearing values from core to Android SDK equivalent.
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index fc916024b1..278c811c03 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -89,6 +89,8 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import static com.mapbox.mapboxsdk.utils.MathUtils.convertNativeBearing; + /** * <p> * A {@code MapView} provides an embeddable map interface. @@ -151,6 +153,7 @@ public class MapView extends FrameLayout { private boolean styleWasSet = false; private List<OnMapReadyCallback> onMapReadyCallbackList; + private MapboxMap.CancelableCallback cameraCancelableCallback; private SnapshotRequest snapshotRequest; private boolean onStartCalled; @@ -708,16 +711,7 @@ public class MapView extends FrameLayout { return 0; } - double direction = -nativeMapView.getBearing(); - - while (direction > 360) { - direction -= 360; - } - while (direction < 0) { - direction += 360; - } - - return direction; + return convertNativeBearing(nativeMapView.getBearing()); } void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction) { @@ -732,7 +726,7 @@ public class MapView extends FrameLayout { return; } long duration = animated ? MapboxConstants.ANIMATION_DURATION : 0; - nativeMapView.cancelTransitions(); + cancelTransitions(); // Out of range directions are normalised in setBearing nativeMapView.setBearing(-direction, duration); } @@ -742,7 +736,7 @@ public class MapView extends FrameLayout { return; } myLocationView.setBearing(0); - nativeMapView.cancelTransitions(); + cancelTransitions(); nativeMapView.resetNorth(); } @@ -812,7 +806,7 @@ public class MapView extends FrameLayout { private void zoom(boolean zoomIn, float x, float y) { // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); if (zoomIn) { nativeMapView.scaleBy(2.0, x / screenDensity, y / screenDensity, MapboxConstants.ANIMATION_DURATION); @@ -1066,11 +1060,19 @@ public class MapView extends FrameLayout { // Mapbox Core GL Camera // + private void cancelTransitions(){ + if (cameraCancelableCallback != null) { + cameraCancelableCallback.onCancel(); + cameraCancelableCallback = null; + } + nativeMapView.cancelTransitions(); + } + void jumpTo(double bearing, LatLng center, double pitch, double zoom) { if (destroyed) { return; } - nativeMapView.cancelTransitions(); + cancelTransitions(); nativeMapView.jumpTo(bearing, center, pitch, zoom); } @@ -1078,16 +1080,17 @@ public class MapView extends FrameLayout { if (destroyed) { return; } - nativeMapView.cancelTransitions(); + cancelTransitions(); // Register callbacks early enough if (cancelableCallback != null) { + cameraCancelableCallback = cancelableCallback; addOnMapChangedListener(new OnMapChangedListener() { @Override public void onMapChanged(@MapChange int change) { - if (change == REGION_DID_CHANGE_ANIMATED) { - cancelableCallback.onFinish(); - + if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) { + cameraCancelableCallback.onFinish(); + cameraCancelableCallback = null; // Clean up after self removeOnMapChangedListener(this); } @@ -1102,16 +1105,17 @@ public class MapView extends FrameLayout { if (destroyed) { return; } - nativeMapView.cancelTransitions(); + cancelTransitions(); // Register callbacks early enough if (cancelableCallback != null) { + cameraCancelableCallback = cancelableCallback; addOnMapChangedListener(new OnMapChangedListener() { @Override public void onMapChanged(@MapChange int change) { - if (change == REGION_DID_CHANGE_ANIMATED) { + if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) { cancelableCallback.onFinish(); - + cameraCancelableCallback = null; // Clean up after self removeOnMapChangedListener(this); } @@ -1545,7 +1549,7 @@ public class MapView extends FrameLayout { return false; } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); return true; } @@ -1647,7 +1651,7 @@ public class MapView extends FrameLayout { double duration = speed / (deceleration * ease); // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); nativeMapView.moveBy(velocityX * duration / 2.0 / screenDensity, velocityY * duration / 2.0 / screenDensity, (long) (duration * 1000.0f)); @@ -1679,7 +1683,7 @@ public class MapView extends FrameLayout { // reset tracking if needed resetTrackingModesIfRequired(true, false); // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Scroll the map nativeMapView.moveBy(-distanceX / screenDensity, -distanceY / screenDensity); @@ -1750,7 +1754,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Gesture is a quickzoom if there aren't two fingers quickZoom = !twoTap; @@ -1831,7 +1835,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // rotation constitutes translation of anything except the center of // rotation, so cancel both location and bearing tracking if required @@ -1907,7 +1911,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Get tilt value (scale and clamp) double pitch = getTilt(); @@ -1974,7 +1978,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Move left nativeMapView.moveBy(scrollDist / screenDensity, 0.0 / screenDensity); @@ -1986,7 +1990,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Move right nativeMapView.moveBy(-scrollDist / screenDensity, 0.0 / screenDensity); @@ -1998,7 +2002,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Move up nativeMapView.moveBy(0.0 / screenDensity, scrollDist / screenDensity); @@ -2010,7 +2014,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Move down nativeMapView.moveBy(0.0 / screenDensity, -scrollDist / screenDensity); @@ -2090,7 +2094,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Scroll the map nativeMapView.moveBy(-10.0 * event.getX() / screenDensity, -10.0 * event.getY() / screenDensity); @@ -2186,7 +2190,7 @@ public class MapView extends FrameLayout { } // Cancel any animation - nativeMapView.cancelTransitions(); + cancelTransitions(); // Get the vertical scroll amount, one click = 1 float scrollDist = event.getAxisValue(MotionEvent.AXIS_VSCROLL); |