diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-10-09 16:54:32 +0300 |
---|---|---|
committer | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2017-11-01 09:23:53 -0400 |
commit | 9c3e78a9b95782e8fbf15cf7a4052f46f27922fd (patch) | |
tree | 79a96703acd32ffa44eb178754b65211a821a446 /platform/android/src/snapshotter/map_snapshot.cpp | |
parent | b3834447ff6006e865cec754de31be280cbae3f6 (diff) | |
download | qtlocation-mapboxgl-9c3e78a9b95782e8fbf15cf7a4052f46f27922fd.tar.gz |
[android] map snapshotter - wrap snapshot in native peer for access to the pointFor functionality
Diffstat (limited to 'platform/android/src/snapshotter/map_snapshot.cpp')
-rw-r--r-- | platform/android/src/snapshotter/map_snapshot.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp new file mode 100644 index 0000000000..09e83bbb8a --- /dev/null +++ b/platform/android/src/snapshotter/map_snapshot.cpp @@ -0,0 +1,57 @@ +#include "map_snapshot.hpp" + +#include "../bitmap.hpp" + +#include <memory> + +namespace mbgl { +namespace android { + +MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_) + : pixelRatio(pixelRatio_) + , pointForFn(std::move(pointForFn_)) { +} + +MapSnapshot::~MapSnapshot() = default; + +jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng> jLatLng) { + ScreenCoordinate point = pointForFn(LatLng::getLatLng(env, jLatLng)); + return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio); +} + + +// Static methods // + +jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env, + PremultipliedImage&& image, + float pixelRatio, + mbgl::MapSnapshotter::PointForFn pointForFn) { + // Create the bitmap + auto bitmap = Bitmap::CreateBitmap(env, std::move(image)); + + // Create the Mapsnapshot peers + static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>>(env); + auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn); + return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap); +} + +jni::Class<MapSnapshot> MapSnapshot::javaClass; + +void MapSnapshot::registerNative(jni::JNIEnv& env) { + // Lookup the class + MapSnapshot::javaClass = *jni::Class<MapSnapshot>::Find(env).NewGlobalRef(env).release(); + +#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) + + // Register the peer + jni::RegisterNativePeer<MapSnapshot>(env, MapSnapshot::javaClass, + "nativePtr", + std::make_unique<MapSnapshot, JNIEnv&>, + "initialize", + "finalize", + METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng") + ); +} + +} // namespace android +} // namespace mbgl |