diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-27 16:55:44 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-03-05 17:43:37 +0200 |
commit | 039bc80411e3b1ca09e2dd60c9f18105fc68d4fc (patch) | |
tree | 73da958206a3755a5b6dd4f4c33328babd147ba5 | |
parent | d86eb878ce9721a9e40a63893c24fc035b54cd56 (diff) | |
download | qtlocation-mapboxgl-039bc80411e3b1ca09e2dd60c9f18105fc68d4fc.tar.gz |
[android] Update android snapshotter
-rw-r--r-- | platform/android/src/snapshotter/map_snapshotter.cpp | 46 | ||||
-rw-r--r-- | platform/android/src/snapshotter/map_snapshotter.hpp | 3 |
2 files changed, 20 insertions, 29 deletions
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 0b38269ada..e888cae3df 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<uint32_t>(width), static_cast<uint32_t>(height) }; - optional<mbgl::CameraOptions> cameraOptions; + showLogo = _showLogo; + + // Create the core snapshotter + snapshotter = std::make_unique<mbgl::MapSnapshotter>( + size, + pixelRatio, + mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource), + mbgl::MapSnapshotterObserver::nullObserver(), + _localIdeographFontFamily ? jni::Make<std::string>(_env, _localIdeographFontFamily) : optional<std::string>{}); + if (position) { - cameraOptions = CameraPosition::getCameraOptions(_env, position, pixelRatio); + snapshotter->setCameraOptions(CameraPosition::getCameraOptions(_env, position, pixelRatio)); } - optional<mbgl::LatLngBounds> bounds; if (region) { - bounds = LatLngBounds::getLatLngBounds(_env, region); + snapshotter->setRegion(LatLngBounds::getLatLngBounds(_env, region)); } - std::pair<bool, std::string> style; if (styleJSON) { - style = std::make_pair(true, jni::Make<std::string>(_env, styleJSON)); + snapshotter->setStyleJSON(jni::Make<std::string>(_env, styleJSON)); } else { - style = std::make_pair(false, jni::Make<std::string>(_env, styleURL)); + snapshotter->setStyleJSON(jni::Make<std::string>(_env, styleURL)); } - - showLogo = _showLogo; - // Create the core snapshotter - snapshotter = std::make_unique<mbgl::MapSnapshotter>(style, - size, - pixelRatio, - cameraOptions, - bounds, - _localIdeographFontFamily ? - jni::Make<std::string>(_env, _localIdeographFontFamily) : - optional<std::string>{}, - mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource)); } 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<Actor<mbgl::MapSnapshotter::Callback>>( - *Scheduler::GetCurrent(), - [this](std::exception_ptr err, PremultipliedImage image, std::vector<std::string> attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) { + snapshotter->snapshot([this](std::exception_ptr err, + PremultipliedImage image, + std::vector<std::string> attributions, + mbgl::MapSnapshotter::PointForFn pointForFn, + mbgl::MapSnapshotter::LatLngForFn latLngForFn) { MBGL_VERIFY_THREAD(tid); android::UniqueEnv _env = android::AttachEnv(); static auto& javaClass = jni::Class<MapSnapshotter>::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 608a4c855f..641a0e60f8 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<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback; std::unique_ptr<mbgl::MapSnapshotter> snapshotter; FileSource *jFileSource; |