Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

5438 MyLocationView transformation #5654

Merged
merged 1 commit into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ void resetNorth() {
if (mDestroyed) {
return;
}
mMyLocationView.setBearing(0);
mNativeMapView.cancelTransitions();
mNativeMapView.resetNorth();
}
Expand Down Expand Up @@ -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() {
Expand All @@ -1386,20 +1380,23 @@ void setBearing(float bearing) {
if (mDestroyed) {
return;
}
mMyLocationView.setBearing(bearing);
mNativeMapView.setBearing(bearing);
}

void setBearing(float bearing, long duration) {
if (mDestroyed) {
return;
}
mMyLocationView.setBearing(bearing);
mNativeMapView.setBearing(bearing, duration);
}

void setBearing(double bearing, float focalX, float focalY) {
if (mDestroyed) {
return;
}
mMyLocationView.setBearing(bearing);
mNativeMapView.setBearing(bearing, focalX, focalY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ void setProjection(Projection projection) {
* Triggers an invalidation of the map view.
*/
public void invalidate() {
mMapView.update();
mMapView.invalidate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}