[android] #5438 - add bearing to MyLocationView for the SDK camera object
[android] #5438 - integrate MyLocationView set bearing inside the MapView setBearing [android] #5438 - invalidate the MapView instead of calling update from core. [android] #5438 - add bearing MyLocationView to setBearing focal point on MapView [android] #5438 - Get correct bearing when camera object is rotated around the z-axis, notify MyLocationView when camera position changes, update test utilities. [android] #5438 - fixes compass tracking
This commit is contained in:
committed by
Tobrun Van Nuland
parent
081c61dcc2
commit
3dacbdd42e
@@ -641,6 +641,7 @@ public class MapView extends FrameLayout {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mMyLocationView.setBearing(0);
|
||||
mNativeMapView.cancelTransitions();
|
||||
mNativeMapView.resetNorth();
|
||||
}
|
||||
@@ -1349,20 +1350,13 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// 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 @@ public class MapView extends FrameLayout {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mMyLocationView.setBearing(bearing);
|
||||
mNativeMapView.setBearing(bearing);
|
||||
}
|
||||
|
||||
@@ -1393,6 +1388,7 @@ public class MapView extends FrameLayout {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mMyLocationView.setBearing(bearing);
|
||||
mNativeMapView.setBearing(bearing, duration);
|
||||
}
|
||||
|
||||
@@ -1400,6 +1396,7 @@ public class MapView extends FrameLayout {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mMyLocationView.setBearing(bearing);
|
||||
mNativeMapView.setBearing(bearing, focalX, focalY);
|
||||
}
|
||||
|
||||
|
||||
@@ -1629,7 +1629,7 @@ public class MapboxMap {
|
||||
* Triggers an invalidation of the map view.
|
||||
*/
|
||||
public void invalidate() {
|
||||
mMapView.update();
|
||||
mMapView.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,6 +91,9 @@ public class MyLocationView extends View {
|
||||
private Matrix matrix;
|
||||
private Camera camera;
|
||||
private PointF screenLocation;
|
||||
|
||||
// camera vars
|
||||
private float bearing;
|
||||
private float tilt;
|
||||
|
||||
@MyLocationTracking.Mode
|
||||
@@ -260,7 +263,7 @@ public class MyLocationView extends View {
|
||||
|
||||
// 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 class MyLocationView extends View {
|
||||
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 class MyLocationView extends View {
|
||||
compassListener.onPause();
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
// always face north
|
||||
gpsDirection = 0;
|
||||
gpsDirection = bearing;
|
||||
setCompass(gpsDirection);
|
||||
}
|
||||
}
|
||||
@@ -546,7 +558,7 @@ public class MyLocationView extends View {
|
||||
|
||||
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 @@ public class MyLocationView extends View {
|
||||
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 @@ public class MyLocationView extends View {
|
||||
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 @@ public class MyLocationView extends View {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user