summaryrefslogtreecommitdiff
path: root/platform/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src')
-rwxr-xr-xplatform/android/src/jni.cpp2
-rw-r--r--platform/android/src/snapshotter/map_snapshot.cpp57
-rw-r--r--platform/android/src/snapshotter/map_snapshot.hpp41
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp12
4 files changed, 106 insertions, 6 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index f6ddb8b6ee..f4e5734861 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -50,6 +50,7 @@
#include "style/sources/sources.hpp"
#include "style/light.hpp"
#include "snapshotter/map_snapshotter.hpp"
+#include "snapshotter/map_snapshot.hpp"
namespace mbgl {
namespace android {
@@ -186,6 +187,7 @@ void registerNatives(JavaVM *vm) {
// Snapshotter
MapSnapshotter::registerNative(env);
+ MapSnapshot::registerNative(env);
}
} // namespace android
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
diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp
new file mode 100644
index 0000000000..6d60d49728
--- /dev/null
+++ b/platform/android/src/snapshotter/map_snapshot.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <mbgl/map/map_snapshotter.hpp>
+
+#include <jni/jni.hpp>
+
+#include "../geometry/lat_lng.hpp"
+#include "../graphics/pointf.hpp"
+
+namespace mbgl {
+namespace android {
+
+class MapSnapshot {
+public:
+
+ using PointForFn = mbgl::MapSnapshotter::PointForFn;
+
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshot"; };
+
+ static void registerNative(jni::JNIEnv&);
+
+ static jni::Object<MapSnapshot> New(JNIEnv& env,
+ PremultipliedImage&& image,
+ float pixelRatio,
+ PointForFn pointForFn);
+
+ MapSnapshot(jni::JNIEnv&) {};
+ MapSnapshot(float pixelRatio, PointForFn);
+ ~MapSnapshot();
+
+ jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>);
+
+private:
+ static jni::Class<MapSnapshot> javaClass;
+
+ float pixelRatio;
+ mbgl::MapSnapshotter::PointForFn pointForFn;
+};
+
+} // namespace android
+} // namespace mbgl \ No newline at end of file
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index 74e43c70a1..a13e91ccd3 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -8,7 +8,7 @@
#include <mbgl/actor/scheduler.hpp>
#include "../attach_env.hpp"
-#include "../bitmap.hpp"
+#include "map_snapshot.hpp"
namespace mbgl {
namespace android {
@@ -58,7 +58,7 @@ MapSnapshotter::~MapSnapshotter() = default;
void MapSnapshotter::start(JNIEnv&) {
MBGL_VERIFY_THREAD(tid);
- snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(*Scheduler::GetCurrent(), [this](std::exception_ptr err, PremultipliedImage image) {
+ snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(*Scheduler::GetCurrent(), [this](std::exception_ptr err, PremultipliedImage image, mbgl::MapSnapshotter::PointForFn pointForFn) {
MBGL_VERIFY_THREAD(tid);
android::UniqueEnv _env = android::AttachEnv();
@@ -67,12 +67,12 @@ void MapSnapshotter::start(JNIEnv&) {
static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed");
javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
} else {
- // Create the bitmap
- auto bitmap = Bitmap::CreateBitmap(*_env, std::move(image));
+ // Create the wrapper
+ auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, pointForFn);
// invoke callback
- static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<Bitmap>)>(*_env, "onSnapshotReady");
- javaPeer->Call(*_env, onSnapshotReady, bitmap);
+ static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
+ javaPeer->Call(*_env, onSnapshotReady, mapSnapshot);
}
});