[android] - move calculation of LatLngBounds to core (#8765)
This commit is contained in:
@@ -159,6 +159,9 @@ void registerNatives(JavaVM *vm) {
|
||||
IdentityStops::registerNative(env);
|
||||
IntervalStops::registerNative(env);
|
||||
|
||||
// Map
|
||||
CameraPosition::registerNative(env);
|
||||
|
||||
// Connectivity
|
||||
ConnectivityListener::registerNative(env);
|
||||
|
||||
|
||||
24
platform/android/src/map/camera_position.cpp
Normal file
24
platform/android/src/map/camera_position.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#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);
|
||||
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));
|
||||
}
|
||||
|
||||
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
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "run_loop_impl.hpp"
|
||||
#include "java/util.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -449,6 +450,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();
|
||||
@@ -562,21 +567,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) {
|
||||
@@ -1493,6 +1485,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"),
|
||||
@@ -1513,7 +1506,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"),
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "style/layers/layers.hpp"
|
||||
#include "style/sources/sources.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
#include "map/camera_position.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
@@ -129,6 +130,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&);
|
||||
@@ -169,7 +172,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