#include "map_snapshot.hpp" #include "../bitmap.hpp" #include "../jni/collection.hpp" #include namespace mbgl { namespace android { MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_) : pixelRatio(pixelRatio_) , pointForFn(std::move(pointForFn_)) { } MapSnapshot::~MapSnapshot() = default; jni::Object MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object jLatLng) { ScreenCoordinate point = pointForFn(LatLng::getLatLng(env, jLatLng)); return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio); } // Static methods // jni::Object MapSnapshot::New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, std::vector attributions, 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::Array>(env); auto nativePeer = std::make_unique(pixelRatio, pointForFn); return javaClass.New(env, constructor, reinterpret_cast(nativePeer.release()), bitmap, jni::Make>(env, attributions)); } jni::Class MapSnapshot::javaClass; void MapSnapshot::registerNative(jni::JNIEnv& env) { // Lookup the class MapSnapshot::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer jni::RegisterNativePeer(env, MapSnapshot::javaClass, "nativePtr", std::make_unique, "initialize", "finalize", METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng") ); } } // namespace android } // namespace mbgl