Cherry pick latlngbounds to release branch (#8788)
* [android] - move calculation of LatLngBounds to core * [core] Ignore shortest path in Map::pixelForLatLng * [android] - convert camera position values coming from core (#8794)
This commit is contained in:
@@ -127,6 +127,9 @@ void registerNatives(JavaVM *vm) {
|
||||
IdentityStops::registerNative(env);
|
||||
IntervalStops::registerNative(env);
|
||||
|
||||
// Map
|
||||
CameraPosition::registerNative(env);
|
||||
|
||||
// Connectivity
|
||||
ConnectivityListener::registerNative(env);
|
||||
|
||||
|
||||
38
platform/android/src/map/camera_position.cpp
Normal file
38
platform/android/src/map/camera_position.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "camera_position.hpp"
|
||||
#include "../geometry/lat_lng.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
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();
|
||||
|
||||
// convert bearing, core ranges from [−π rad, π rad], android from 0 to 360 degrees
|
||||
double bearing_degrees = options.angle.value_or(0) * 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.latitude, center.longitude), options.zoom.value_or(0), tilt_degrees, bearing_degrees);
|
||||
}
|
||||
|
||||
void CameraPosition::registerNative(jni::JNIEnv &env) {
|
||||
// Lookup the class
|
||||
CameraPosition::javaClass = *jni::Class<CameraPosition>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
jni::Class<CameraPosition> CameraPosition::javaClass;
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mb
|
||||
26
platform/android/src/map/camera_position.hpp
Normal file
26
platform/android/src/map/camera_position.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/map/camera.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class CameraPosition : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/camera/CameraPosition"; };
|
||||
|
||||
static jni::Object<CameraPosition> New(jni::JNIEnv&, mbgl::CameraOptions);
|
||||
|
||||
static jni::Class<CameraPosition> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -44,6 +44,8 @@
|
||||
#include "bitmap.hpp"
|
||||
#include "run_loop_impl.hpp"
|
||||
#include "java/util.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -369,6 +371,10 @@ void NativeMapView::setLatLng(jni::JNIEnv&, jni::jdouble latitude, jni::jdouble
|
||||
map->setLatLng(mbgl::LatLng(latitude, longitude), insets, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
|
||||
}
|
||||
|
||||
jni::Object<CameraPosition> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> jBounds) {
|
||||
return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), insets));
|
||||
}
|
||||
|
||||
void NativeMapView::setReachability(jni::JNIEnv&, jni::jboolean reachable) {
|
||||
if (reachable) {
|
||||
mbgl::NetworkStatus::Reachable();
|
||||
@@ -494,21 +500,8 @@ void NativeMapView::enableFps(jni::JNIEnv&, jni::jboolean enable) {
|
||||
fpsEnabled = enable;
|
||||
}
|
||||
|
||||
jni::Array<jni::jdouble> NativeMapView::getCameraValues(jni::JNIEnv& env) {
|
||||
//Create buffer with values
|
||||
jdouble buf[5];
|
||||
mbgl::LatLng latLng = map->getLatLng(insets);
|
||||
buf[0] = latLng.latitude;
|
||||
buf[1] = latLng.longitude;
|
||||
buf[2] = -map->getBearing();
|
||||
buf[3] = map->getPitch();
|
||||
buf[4] = map->getZoom();
|
||||
|
||||
//Convert to Java array
|
||||
auto output = jni::Array<jni::jdouble>::New(env, 5);
|
||||
jni::SetArrayRegion(env, *output, 0, 5, buf);
|
||||
|
||||
return output;
|
||||
jni::Object<CameraPosition> NativeMapView::getCameraPosition(jni::JNIEnv& env) {
|
||||
return CameraPosition::New(env, map->getCameraOptions(insets));
|
||||
}
|
||||
|
||||
void NativeMapView::updateMarker(jni::JNIEnv& env, jni::jlong markerId, jni::jdouble lat, jni::jdouble lon, jni::String jid) {
|
||||
@@ -1429,6 +1422,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::flyTo, "nativeFlyTo"),
|
||||
METHOD(&NativeMapView::getLatLng, "nativeGetLatLng"),
|
||||
METHOD(&NativeMapView::setLatLng, "nativeSetLatLng"),
|
||||
METHOD(&NativeMapView::getCameraForLatLngBounds, "nativeGetCameraForLatLngBounds"),
|
||||
METHOD(&NativeMapView::setReachability, "nativeSetReachability"),
|
||||
METHOD(&NativeMapView::resetPosition, "nativeResetPosition"),
|
||||
METHOD(&NativeMapView::getPitch, "nativeGetPitch"),
|
||||
@@ -1452,7 +1446,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::setContentPadding, "nativeSetContentPadding"),
|
||||
METHOD(&NativeMapView::scheduleSnapshot, "nativeTakeSnapshot"),
|
||||
METHOD(&NativeMapView::enableFps, "nativeSetEnableFps"),
|
||||
METHOD(&NativeMapView::getCameraValues, "nativeGetCameraValues"),
|
||||
METHOD(&NativeMapView::getCameraPosition, "nativeGetCameraPosition"),
|
||||
METHOD(&NativeMapView::updateMarker, "nativeUpdateMarker"),
|
||||
METHOD(&NativeMapView::addMarkers, "nativeAddMarkers"),
|
||||
METHOD(&NativeMapView::setDebug, "nativeSetDebug"),
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "geometry/projected_meters.hpp"
|
||||
#include "style/layers/layers.hpp"
|
||||
#include "style/sources/sources.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <jni.h>
|
||||
@@ -107,6 +109,8 @@ public:
|
||||
|
||||
void setLatLng(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jlong);
|
||||
|
||||
jni::Object<CameraPosition> getCameraForLatLngBounds(jni::JNIEnv&, jni::Object<mbgl::android::LatLngBounds>);
|
||||
|
||||
void setReachability(jni::JNIEnv&, jni::jboolean);
|
||||
|
||||
void resetPosition(jni::JNIEnv&);
|
||||
@@ -153,7 +157,7 @@ public:
|
||||
|
||||
void enableFps(jni::JNIEnv&, jni::jboolean enable);
|
||||
|
||||
jni::Array<jni::jdouble> getCameraValues(jni::JNIEnv&);
|
||||
jni::Object<CameraPosition> getCameraPosition(jni::JNIEnv&);
|
||||
|
||||
void updateMarker(jni::JNIEnv&, jni::jlong, jni::jdouble, jni::jdouble, jni::String);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user