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 1562847e77d..8a0beadd405 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 @@ -641,6 +641,7 @@ void resetNorth() { if (mDestroyed) { return; } + mMyLocationView.setBearing(0); mNativeMapView.cancelTransitions(); mNativeMapView.resetNorth(); } @@ -1349,20 +1350,13 @@ public void surfaceDestroyed(SurfaceHolder holder) { } } - // Used by UserLocationView - void update() { - if (mDestroyed) { - return; - } - - mNativeMapView.update(); - } - CameraPosition invalidateCameraPosition() { if (mDestroyed) { return new CameraPosition.Builder().build(); } - return new CameraPosition.Builder(mNativeMapView.getCameraValues()).build(); + CameraPosition position = new CameraPosition.Builder(mNativeMapView.getCameraValues()).build(); + mMyLocationView.setCameraPosition(position); + return position; } double getBearing() { @@ -1386,6 +1380,7 @@ void setBearing(float bearing) { if (mDestroyed) { return; } + mMyLocationView.setBearing(bearing); mNativeMapView.setBearing(bearing); } @@ -1393,6 +1388,7 @@ void setBearing(float bearing, long duration) { if (mDestroyed) { return; } + mMyLocationView.setBearing(bearing); mNativeMapView.setBearing(bearing, duration); } @@ -1400,6 +1396,7 @@ void setBearing(double bearing, float focalX, float focalY) { if (mDestroyed) { return; } + mMyLocationView.setBearing(bearing); mNativeMapView.setBearing(bearing, focalX, focalY); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 84d121a372a..c86a6fc4ecf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1629,7 +1629,7 @@ void setProjection(Projection projection) { * Triggers an invalidation of the map view. */ public void invalidate() { - mMapView.update(); + mMapView.invalidate(); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 16ff084a488..04064d1f24d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -91,6 +91,9 @@ public void onAnimationUpdate(ValueAnimator animation) { private Matrix matrix; private Camera camera; private PointF screenLocation; + + // camera vars + private float bearing; private float tilt; @MyLocationTracking.Mode @@ -260,7 +263,7 @@ protected void onDraw(Canvas canvas) { // apply tilt to camera camera.save(); - camera.rotate(tilt, 0, 0); + camera.rotate(tilt, 0, bearing); // map camera matrix on our matrix camera.getMatrix(matrix); @@ -301,6 +304,15 @@ public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) { this.tilt = (float) tilt; } + public void setBearing(double bearing) { + this.bearing = (float) bearing; + } + + public void setCameraPosition(CameraPosition position) { + setTilt(position.tilt); + setBearing(position.bearing); + } + public void onPause() { compassListener.onPause(); toggleGps(false); @@ -404,7 +416,7 @@ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTracki compassListener.onPause(); if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) { // always face north - gpsDirection = 0; + gpsDirection = bearing; setCompass(gpsDirection); } } @@ -546,7 +558,7 @@ public void onSensorChanged(SensorEvent event) { SensorManager.getRotationMatrix(mR, mI, mGData, mMData); SensorManager.getOrientation(mR, mOrientation); - setCompass((int) (mOrientation[0] * 180.0f / Math.PI)); + setCompass(mCurrentDegree = (int) (mOrientation[0] * 180.0f / Math.PI)); mCompassUpdateNextTimestamp = currentTime + UPDATE_RATE_MS; } @@ -662,7 +674,7 @@ void updateLatLng(@NonNull Location location) { if (location.hasBearing()) { builder.bearing(location.getBearing()); } - gpsDirection = 0; + gpsDirection = location.getBearing(); setCompass(gpsDirection); } else if (myBearingTrackingMode == MyBearingTracking.COMPASS) { if (!compassListener.isPaused()) { @@ -703,8 +715,8 @@ void updateLatLng(@NonNull final Location location) { latLng = new LatLng(location); // update LatLng direction - if (location.hasBearing()) { - gpsDirection = clamp(location.getBearing() - (float) mapboxMap.getCameraPosition().bearing); + if (myBearingTrackingMode == MyBearingTracking.GPS && location.hasBearing()) { + gpsDirection = location.getBearing(); setCompass(gpsDirection); } @@ -736,17 +748,6 @@ void updateLatLng(@NonNull final Location location) { latLng = interpolatedLocation; } - private float clamp(float direction) { - float diff = previousDirection - direction; - if (diff > 180.0f) { - direction += 360.0f; - } else if (diff < -180.0f) { - direction -= 360.f; - } - previousDirection = direction; - return direction; - } - @Override void invalidate() { screenLocation = projection.toScreenLocation(latLng); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapUtils.java index d41c6925094..8b8cd720960 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapUtils.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapUtils.java @@ -21,8 +21,8 @@ public static MapboxMap getMapboxMap(MapView mapView) { * @param mapView * @param direction */ - public static void setDirection(MapView mapView, double direction) { - mapView.setDirection(direction); + public static void setDirection(MapView mapView, float direction) { + mapView.setBearing(direction); } }