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

Commit

Permalink
[android] - convert camera position values coming from core (#8794)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun authored Apr 21, 2017
1 parent 3c23faf commit ed51462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ PointF getFocalPoint() {
* @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;
Expand Down
17 changes: 16 additions & 1 deletion platform/android/src/map/camera_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ed51462

Please sign in to comment.