diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 0b38269ad..e888cae3d 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -36,34 +36,29 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, jFileSource = FileSource::getNativePeer(_env, _jFileSource); auto size = mbgl::Size { static_cast(width), static_cast(height) }; - optional cameraOptions; - if (position) { - cameraOptions = CameraPosition::getCameraOptions(_env, position, pixelRatio); - } - - optional bounds; - if (region) { - bounds = LatLngBounds::getLatLngBounds(_env, region); - } - - std::pair style; - if (styleJSON) { - style = std::make_pair(true, jni::Make(_env, styleJSON)); - } else { - style = std::make_pair(false, jni::Make(_env, styleURL)); - } - showLogo = _showLogo; + // Create the core snapshotter - snapshotter = std::make_unique(style, - size, - pixelRatio, - cameraOptions, - bounds, - _localIdeographFontFamily ? - jni::Make(_env, _localIdeographFontFamily) : - optional{}, - mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource)); + snapshotter = std::make_unique( + size, + pixelRatio, + mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource), + mbgl::MapSnapshotterObserver::nullObserver(), + _localIdeographFontFamily ? jni::Make(_env, _localIdeographFontFamily) : optional{}); + + if (position) { + snapshotter->setCameraOptions(CameraPosition::getCameraOptions(_env, position, pixelRatio)); + } + + if (region) { + snapshotter->setRegion(LatLngBounds::getLatLngBounds(_env, region)); + } + + if (styleJSON) { + snapshotter->setStyleJSON(jni::Make(_env, styleJSON)); + } else { + snapshotter->setStyleJSON(jni::Make(_env, styleURL)); + } } MapSnapshotter::~MapSnapshotter() = default; @@ -71,10 +66,11 @@ MapSnapshotter::~MapSnapshotter() = default; void MapSnapshotter::start(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); activateFilesource(env); - - snapshotCallback = std::make_unique>( - *Scheduler::GetCurrent(), - [this](std::exception_ptr err, PremultipliedImage image, std::vector attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) { + snapshotter->snapshot([this](std::exception_ptr err, + PremultipliedImage image, + std::vector attributions, + mbgl::MapSnapshotter::PointForFn pointForFn, + mbgl::MapSnapshotter::LatLngForFn latLngForFn) { MBGL_VERIFY_THREAD(tid); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class::Singleton(*_env); @@ -100,13 +96,11 @@ void MapSnapshotter::start(JNIEnv& env) { deactivateFilesource(*_env); }); - - snapshotter->snapshot(snapshotCallback->self()); } void MapSnapshotter::cancel(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); - snapshotCallback.reset(); + snapshotter->cancel(); deactivateFilesource(env); } diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 608a4c855..641a0e60f 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -14,8 +14,6 @@ namespace mbgl { namespace android { -class SnapshotterRendererFrontend; - class MapSnapshotter { public: @@ -61,7 +59,6 @@ private: float pixelRatio; bool showLogo; - std::unique_ptr> snapshotCallback; std::unique_ptr snapshotter; FileSource *jFileSource;