diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2015-11-08 06:09:17 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2015-11-30 11:30:28 +0100 |
commit | 77df026adcabb04ddbaa90c3782fc7f11bc46ec7 (patch) | |
tree | 4bf1d44fdd36de1a8fc67c19d53f869dee3ddd0f /android | |
parent | 43aad4eb1d63854545c9093add7620529c7d5ac0 (diff) | |
download | qtlocation-mapboxgl-77df026adcabb04ddbaa90c3782fc7f11bc46ec7.tar.gz |
Correct behaviour when switching between tracking modes, added javadoc
Diffstat (limited to 'android')
4 files changed, 82 insertions, 25 deletions
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java index ce01e7b4c5..a70d37dedc 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java @@ -2,14 +2,16 @@ package com.mapbox.mapboxsdk.constants; import android.support.annotation.IntDef; +import com.mapbox.mapboxsdk.views.MapView; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * MyBearingTracking exposes different types bearing tracking modes. * - * @see - * @see + * @see MapView#setMyBearingTrackingMode(int) + * @see com.mapbox.mapboxsdk.views.UserLocationView#setMyBearingTrackingMode(int) */ public class MyBearingTracking { @@ -21,9 +23,21 @@ public class MyBearingTracking { public @interface Mode { } + /** + * Bearing tracking is disabled + */ public static final int NONE = 0x00000000; + + /** + * Tracking the bearing of the user based on sensor data + */ public static final int COMPASS = 0x00000004; + + /** + * Tracking the bearing of the user based on GPS data + */ public static final int GPS = 0x00000008; -// public static final int COMBINED = 0x00000012; + + //public static final int COMBINED = 0x00000012; } diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java index f477c4ab45..130ca36f76 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java @@ -29,7 +29,7 @@ public class MyLocationTracking { public static final int TRACKING_NONE = 0x00000000; /** - * Tracking user, {@link MapView} will reposition to center of {@link com.mapbox.mapboxsdk.views.UserLocationView} + * Tracking the location of the user, {@link MapView} will reposition to center of {@link com.mapbox.mapboxsdk.views.UserLocationView} */ public static final int TRACKING_FOLLOW = 0x00000004; diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index f08c87d0fa..3755a86dd5 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -3294,6 +3294,12 @@ public final class MapView extends FrameLayout { @UiThread public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) { mUserLocationView.setMyLocationTrackingMode(myLocationTrackingMode); + validateGesturesForTrackingModes(); + } + + private void validateGesturesForTrackingModes() { + int myLocationTrackingMode = mUserLocationView.getMyLocationTrackingMode(); + int myBearingTrackingMode = mUserLocationView.getMyBearingTrackingMode(); // Enable/disable gestures based on tracking mode if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) { @@ -3301,10 +3307,11 @@ public final class MapView extends FrameLayout { mRotateEnabled = true; } else { mScrollEnabled = false; - mRotateEnabled = (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW); + mRotateEnabled = (myBearingTrackingMode == MyBearingTracking.NONE); } } + /** * Returns the current user location tracking mode. * @@ -3320,7 +3327,12 @@ public final class MapView extends FrameLayout { /** * Set the current my bearing tracking mode. - * Tracking my bearing disables gestures and shows the direction the user is heading. + * <p/> + * Tracking the users bearing will disable gestures and shows the direction the user is heading. + * <p/> + * When location tracking is disabled the direction of {@link UserLocationView} is rotated + * When location tracking is enabled the {@link MapView} is rotated based on bearing value. + * <p/> * See {@link MyBearingTracking} for different values. * * @param myBearingTrackingMode The bearing tracking mode to be used. @@ -3329,6 +3341,7 @@ public final class MapView extends FrameLayout { @UiThread public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) { mUserLocationView.setMyBearingTrackingMode(myBearingTrackingMode); + validateGesturesForTrackingModes(); } /** diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java index b36ac1ab6d..256330ac2e 100644 --- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java +++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java @@ -73,7 +73,8 @@ final class UserLocationView extends View { private LatLng mMarkerCoordinate; private ValueAnimator mMarkerCoordinateAnimator; - private float mMarkerDirection; + private float mGpsMarkerDirection; + private float mCompassMarkerDirection; private ObjectAnimator mMarkerDirectionAnimator; private float mMarkerAccuracy; private ObjectAnimator mMarkerAccuracyAnimator; @@ -271,16 +272,27 @@ final class UserLocationView extends View { // compute new marker position // TODO add JNI method that takes existing pointf - mMarkerScreenPoint = mMapView.toScreenLocation(mMarkerCoordinate); - mMarkerScreenMatrix.reset(); - mMarkerScreenMatrix.setTranslate( - mMarkerScreenPoint.x, - mMarkerScreenPoint.y); + if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) { + mMarkerScreenPoint = mMapView.toScreenLocation(mMarkerCoordinate); + mMarkerScreenMatrix.reset(); + mMarkerScreenMatrix.setTranslate( + mMarkerScreenPoint.x, + mMarkerScreenPoint.y); + } else if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) { + mMapView.setCenterCoordinate(mMarkerCoordinate, true); + } // rotate so arrow in points to bearing if (mShowDirection) { - mMarkerScreenMatrix.preRotate(mMarkerDirection + - (float) mMapView.getDirection()); + if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) { + mMarkerScreenMatrix.preRotate(mCompassMarkerDirection + (float) mMapView.getDirection()); + } else if (mMyBearingTrackingMode == MyBearingTracking.GPS) { + if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) { + mMarkerScreenMatrix.preRotate(mGpsMarkerDirection + (float) mMapView.getDirection()); + } else { + mMarkerScreenMatrix.preRotate(mGpsMarkerDirection); + } + } } // adjust accuracy circle @@ -355,9 +367,17 @@ final class UserLocationView extends View { mMyBearingTrackingMode = myBearingTrackingMode; if (myBearingTrackingMode == MyBearingTracking.COMPASS) { + mShowDirection = false; mBearingChangeListener.onStart(getContext()); - } else { + } else if (myBearingTrackingMode == MyBearingTracking.GPS) { mBearingChangeListener.onStop(); + if (mUserLocation != null && mUserLocation.hasBearing()) { + mShowDirection = true; + } else { + mShowDirection = false; + } + } else { + mShowDirection = false; } } @@ -535,9 +555,9 @@ final class UserLocationView extends View { mShowDirection = location.hasBearing(); if (mShowDirection) { if (mUserLocation != null && mUserLocation.hasBearing()) { - mMarkerDirection = mUserLocation.getBearing(); + mGpsMarkerDirection = mUserLocation.getBearing(); } - float oldDir = mMarkerDirection; + float oldDir = mGpsMarkerDirection; float newDir = location.getBearing(); float diff = oldDir - newDir; if (diff > 180.0f) { @@ -550,7 +570,9 @@ final class UserLocationView extends View { mMarkerDirectionAnimator.start(); } } else if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW && mMyBearingTrackingMode == MyBearingTracking.GPS) { - // set bearing on map + // always show north & rotate map below + mShowDirection = true; + mGpsMarkerDirection = 0; if (location.hasBearing()) { mMapView.setBearing(mUserLocation.getBearing()); } @@ -579,7 +601,7 @@ final class UserLocationView extends View { if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) { // animate marker mShowDirection = true; - float oldDir = mMarkerDirection; + float oldDir = mCompassMarkerDirection; float newDir = bearing; float diff = oldDir - newDir; if (diff > 180.0f) { @@ -590,12 +612,13 @@ final class UserLocationView extends View { mMarkerDirectionAnimator = ObjectAnimator.ofFloat(this, "direction", oldDir, newDir); mMarkerDirectionAnimator.setDuration(1000); mMarkerDirectionAnimator.start(); - mMarkerDirection = bearing; + mCompassMarkerDirection = bearing; } else if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) { - // change map direction if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) { - mMarkerDirection = bearing; - mMapView.setBearing(mMarkerDirection); + // always show north & change map direction + mShowDirection = true; + mCompassMarkerDirection = 0; + mMapView.setBearing(bearing); } } } @@ -622,12 +645,19 @@ final class UserLocationView extends View { // public for animator only public float getDirection() { - return mMarkerDirection; + if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) { + return mCompassMarkerDirection; + } + return mGpsMarkerDirection; } // public for animator only public void setDirection(float direction) { - mMarkerDirection = direction % 360.0f; + if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) { + mCompassMarkerDirection = direction % 360.0f; + } else { + mGpsMarkerDirection = direction % 360.0f; + } updateOnNextFrame(); } |