diff options
author | Tobrun <tobrun@mapbox.com> | 2017-04-21 19:15:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-21 19:15:26 +0200 |
commit | ed51462428466628b24f3d909bcfcd7cab130607 (patch) | |
tree | 507f9bc005c7f3413b302e3d56c81652eea02d2e | |
parent | 3c23faf65ade59b62d41b68891bfac238acfc9ea (diff) | |
download | qtlocation-mapboxgl-ed51462428466628b24f3d909bcfcd7cab130607.tar.gz |
[android] - convert camera position values coming from core (#8794)
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java | 3 | ||||
-rw-r--r-- | platform/android/src/map/camera_position.cpp | 17 |
2 files changed, 17 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java index 48bfae4a6e..2b327409ae 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java @@ -108,8 +108,7 @@ public final class CompassView extends AppCompatImageView implements Runnable, F * @param bearing the direction value of the map */ public void update(final double bearing) { - // compass needs reverse bearing #8123 - rotation = (float) -bearing; + rotation = (float) bearing; if (!isEnabled()) { return; diff --git a/platform/android/src/map/camera_position.cpp b/platform/android/src/map/camera_position.cpp index 6286047257..0b46998878 100644 --- a/platform/android/src/map/camera_position.cpp +++ b/platform/android/src/map/camera_position.cpp @@ -6,9 +6,24 @@ namespace android { jni::Object<CameraPosition> CameraPosition::New(jni::JNIEnv &env, mbgl::CameraOptions options) { static auto constructor = CameraPosition::javaClass.GetConstructor<jni::Object<LatLng>, double, double, double>(env); + + // wrap LatLng values coming from core auto center = options.center.value(); center.wrap(); - return CameraPosition::javaClass.New(env, constructor, LatLng::New(env, center), options.zoom.value_or(0), options.pitch.value_or(0), options.angle.value_or(0)); + + // convert bearing, core ranges from [−π rad, π rad], android from 0 to 360 degrees + double bearing_degrees = options.angle.value_or(-M_PI) * 180.0 / M_PI; + while (bearing_degrees > 360) { + bearing_degrees -= 360; + } + while (bearing_degrees < 0) { + bearing_degrees += 360; + } + + // convert tilt, core ranges from [0 rad, 1,0472 rad], android ranges from 0 to 60 + double tilt_degrees = options.pitch.value_or(0) * 180 / M_PI; + + return CameraPosition::javaClass.New(env, constructor, LatLng::New(env, center), options.zoom.value_or(0), tilt_degrees, bearing_degrees); } void CameraPosition::registerNative(jni::JNIEnv &env) { |