#include "map_snapshot.hpp" #include "../bitmap.hpp" #include "../conversion/collection.hpp" #include namespace mbgl { namespace android { MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_, MapSnapshot::LatLngForFn latLngForFn_) : pixelRatio(pixelRatio_) , pointForFn(std::move(pointForFn_)) , latLngForFn(std::move(latLngForFn_)) { } 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); } jni::Object MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::ObjectjPoint) { return LatLng::New(env, latLngForFn(PointF::getScreenCoordinate(env, jPoint))); } // Static methods // jni::Object MapSnapshot::New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, std::vector attributions, bool showLogo, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) { // Create the bitmap auto bitmap = Bitmap::CreateBitmap(env, std::move(image)); // Create the Mapsnapshot peers static auto constructor = javaClass.GetConstructor, jni::Array, jni::jboolean>(env); auto nativePeer = std::make_unique(pixelRatio, pointForFn, latLngForFn); return javaClass.New(env, constructor, reinterpret_cast(nativePeer.release()), bitmap, conversion::toArray(env, attributions), (jni::jboolean) showLogo); } 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::latLngForPixel, "latLngForPixel"), METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng") ); } } // namespace android } // namespace mbgl