From 38ec9f03c1af29e7f11ff72b7c93d862c198ea73 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Thu, 6 Nov 2014 21:08:18 +1100 Subject: [PATCH] Rename angle to bearing --- android/cpp/JNI.cpp | 29 +++++++------------ .../java/com/mapbox/mapboxgl/lib/MapView.java | 26 +++++++---------- .../mapbox/mapboxgl/lib/NativeMapView.java | 22 +++++++------- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp index c12828ae0..1b9613ab7 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/JNI.cpp @@ -497,34 +497,25 @@ void JNICALL nativeRotateBy(JNIEnv* env, jobject obj, jlong native_map_view_ptr, native_map_view->getMap()->rotateBy(sx, sy, ex, ey, duration); } -void JNICALL nativeSetAngle(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble angle, jdouble duration) { - VERBOSE("nativeSetAngle"); +void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble degrees, jdouble duration) { + VERBOSE("nativeSetBearing"); ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - // TODO update java class - //native_map_view->getMap()->setAngle(angle, duration); - double degrees = -angle / M_PI * 180; native_map_view->getMap()->setBearing(degrees, duration); } -void JNICALL nativeSetAngle(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble angle, jdouble cx, jdouble cy) { - VERBOSE("nativeSetAngle"); +void JNICALL nativeSetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr, jdouble degrees, jdouble cx, jdouble cy) { + VERBOSE("nativeSetBearing"); ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - // TODO update java class - //native_map_view->getMap()->setAngle(angle, cx, cy); - double degrees = -angle / M_PI * 180; native_map_view->getMap()->setBearing(degrees, cx, cy); } -jdouble JNICALL nativeGetAngle(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { - VERBOSE("nativeGetAngle"); +jdouble JNICALL nativeGetBearing(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + VERBOSE("nativeGetBearing"); ASSERT(native_map_view_ptr != 0); NativeMapView* native_map_view = reinterpret_cast(native_map_view_ptr); - // TODO update java class - //return native_map_view->getMap()->getAngle(); - double degrees = native_map_view->getMap()->getBearing(); - return -degrees * M_PI / 180; + return native_map_view->getMap()->getBearing(); } void JNICALL nativeResetNorth(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { @@ -732,9 +723,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { { "nativeGetMinZoom", "(J)D", reinterpret_cast(&nativeGetMinZoom) }, { "nativeGetMaxZoom", "(J)D", reinterpret_cast(&nativeGetMaxZoom) }, { "nativeRotateBy", "(JDDDDD)V", reinterpret_cast(&nativeRotateBy) }, - { "nativeSetAngle", "(JDD)V", reinterpret_cast(static_cast(&nativeSetAngle)) }, - { "nativeSetAngle", "(JDDD)V", reinterpret_cast(static_cast(&nativeSetAngle)) }, - { "nativeGetAngle", "(J)D", reinterpret_cast(&nativeGetAngle) }, + { "nativeSetBearing", "(JDD)V", reinterpret_cast(static_cast(&nativeSetBearing)) }, + { "nativeSetBearing", "(JDDD)V", reinterpret_cast(static_cast(&nativeSetBearing)) }, + { "nativeGetBearing", "(J)D", reinterpret_cast(&nativeGetBearing) }, { "nativeResetNorth", "(J)V", reinterpret_cast(&nativeResetNorth) }, { "nativeStartRotating", "(J)V", reinterpret_cast(&nativeStartRotating) }, { "nativeStopRotating", "(J)V", reinterpret_cast(&nativeStopRotating) }, diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index 87ab2e885..ab15c91f4 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -213,9 +213,7 @@ public class MapView extends SurfaceView { } public double getDirection() { - double direction = mNativeMapView.getAngle(); - - direction *= 180 / Math.PI; + double direction = -mNativeMapView.getBearing(); while (direction > 360) direction -= 360; @@ -232,9 +230,7 @@ public class MapView extends SurfaceView { public void setDirection(double direction, boolean animated) { double duration = animated ? 0.3 : 0.0; - direction *= Math.PI / 180; - - mNativeMapView.setAngle(direction, duration); + mNativeMapView.setBearing(-direction, duration); } public void resetPosition() { @@ -362,7 +358,7 @@ public class MapView extends SurfaceView { if (savedInstanceState != null) { lonlat = (LonLat) savedInstanceState .getParcelable(STATE_CENTER_COORDINATE); - angle = savedInstanceState.getDouble(STATE_CENTER_DIRECTION); + bearing = savedInstanceState.getDouble(STATE_CENTER_DIRECTION); zoom = savedInstanceState.getDouble(STATE_ZOOM_LEVEL); setCenterCoordinate((LonLat) savedInstanceState .getParcelable(STATE_CENTER_COORDINATE)); @@ -418,7 +414,7 @@ public class MapView extends SurfaceView { public void onPause() { Log.v(TAG, "onPause"); lonlat = mNativeMapView.getLonLat(); - angle = mNativeMapView.getAngle(); + bearing = mNativeMapView.getBearing(); zoom = mNativeMapView.getZoom(); mNativeMapView.stop(); } @@ -429,14 +425,14 @@ public class MapView extends SurfaceView { // TODO need to fix this in Map C++ code // Seems map state gets reset when we start() private LonLat lonlat; - private double angle, zoom; + private double bearing, zoom; public void onResume() { Log.v(TAG, "onResume"); mNativeMapView.start(); if (lonlat != null) { mNativeMapView.setLonLat(lonlat); - mNativeMapView.setAngle(angle); + mNativeMapView.setBearing(bearing); mNativeMapView.setZoom(zoom); } } @@ -461,7 +457,7 @@ public class MapView extends SurfaceView { mNativeMapView.createSurface(holder.getSurface()); if (lonlat != null) { mNativeMapView.setLonLat(lonlat); - mNativeMapView.setAngle(angle); + mNativeMapView.setBearing(bearing); mNativeMapView.setZoom(zoom); } } @@ -834,10 +830,10 @@ public class MapView extends SurfaceView { mNativeMapView.cancelTransitions(); // Rotate the map - double angle = mNativeMapView.getAngle(); - angle -= detector.getRotationDegreesDelta() * Math.PI / 180.0; - Log.d("rotate", "rotate to " + angle); - mNativeMapView.setAngle(angle, detector.getFocusX(), + double bearing = mNativeMapView.getBearing(); + bearing += detector.getRotationDegreesDelta() * Math.PI / 180.0; + Log.d("rotate", "rotate to " + bearing); + mNativeMapView.setBearing(bearing, detector.getFocusX(), detector.getFocusY()); return true; diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index 1d1fa5f4d..bd72846d9 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -295,20 +295,20 @@ class NativeMapView { nativeRotateBy(mNativeMapViewPtr, sx, sy, ex, ey, duration); } - public void setAngle(double angle) { - setAngle(angle, 0.0); + public void setBearing(double degrees) { + setBearing(degrees, 0.0); } - public void setAngle(double angle, double duration) { - nativeSetAngle(mNativeMapViewPtr, angle, duration); + public void setBearing(double degrees, double duration) { + nativeSetBearing(mNativeMapViewPtr, degrees, duration); } - public void setAngle(double angle, double cx, double cy) { - nativeSetAngle(mNativeMapViewPtr, angle, cx, cy); + public void setBearing(double degrees, double cx, double cy) { + nativeSetBearing(mNativeMapViewPtr, degrees, cx, cy); } - public double getAngle() { - return nativeGetAngle(mNativeMapViewPtr); + public double getBearing() { + return nativeGetBearing(mNativeMapViewPtr); } public void resetNorth() { @@ -452,13 +452,13 @@ class NativeMapView { private native void nativeRotateBy(long nativeMapViewPtr, double sx, double sy, double ex, double ey, double duration); - private native void nativeSetAngle(long nativeMapViewPtr, double angle, + private native void nativeSetBearing(long nativeMapViewPtr, double degrees, double duration); - private native void nativeSetAngle(long nativeMapViewPtr, double angle, + private native void nativeSetBearing(long nativeMapViewPtr, double degrees, double cx, double cy); - private native double nativeGetAngle(long nativeMapViewPtr); + private native double nativeGetBearing(long nativeMapViewPtr); private native void nativeResetNorth(long nativeMapViewPtr);