summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkevin <kevin.li@mapbox.com>2020-03-09 18:26:23 +0800
committerkevin <kevin.li@mapbox.com>2020-03-09 18:26:23 +0800
commitd9d0cbcc6b1ec0c3eb0841e84561498ac1a067d4 (patch)
tree0ce4184c0edc532f4b9401dc5e11aca1aff7b5b9
parente6024a2e020ce28f87a785522b99212f91ed3ce4 (diff)
downloadqtlocation-mapboxgl-d9d0cbcc6b1ec0c3eb0841e84561498ac1a067d4.tar.gz
[android] Add jni binding for styleable snapshotter
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp15
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.hpp15
2 files changed, 26 insertions, 4 deletions
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index e888cae3df..c3172c1cbd 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -37,13 +37,12 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
auto size = mbgl::Size { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
showLogo = _showLogo;
-
// Create the core snapshotter
snapshotter = std::make_unique<mbgl::MapSnapshotter>(
size,
pixelRatio,
mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource),
- mbgl::MapSnapshotterObserver::nullObserver(),
+ observer,
_localIdeographFontFamily ? jni::Make<std::string>(_env, _localIdeographFontFamily) : optional<std::string>{});
if (position) {
@@ -57,7 +56,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
if (styleJSON) {
snapshotter->setStyleJSON(jni::Make<std::string>(_env, styleJSON));
} else {
- snapshotter->setStyleJSON(jni::Make<std::string>(_env, styleURL));
+ snapshotter->setStyleURL(jni::Make<std::string>(_env, styleURL));
}
}
@@ -126,6 +125,15 @@ void MapSnapshotter::setRegion(JNIEnv& env, const jni::Object<LatLngBounds>& reg
snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region));
}
+void MapSnapshotter::addLayer(JNIEnv &, jlong nativeLayerPtr) {
+ assert(nativeLayerPtr != 0);
+ Layer *layer = reinterpret_cast<Layer *>(nativeLayerPtr);
+ style::Layer &t = layer->get();
+ std::unique_ptr<style::Layer> u (&t);
+ observer.didFinishLoadingStyleCallback= [&] {
+ snapshotter->getStyle().addLayer(std::move(u));
+ };
+}
// Private methods //
@@ -157,6 +165,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
"nativeInitialize",
"finalize",
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
+ METHOD(&MapSnapshotter::addLayer, "nativeAddLayer"),
METHOD(&MapSnapshotter::setStyleJson, "setStyleJson"),
METHOD(&MapSnapshotter::setSize, "setSize"),
METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"),
diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp
index 641a0e60f8..96214df090 100644
--- a/platform/android/src/snapshotter/map_snapshotter.hpp
+++ b/platform/android/src/snapshotter/map_snapshotter.hpp
@@ -6,6 +6,7 @@
#include "../file_source.hpp"
#include "../geometry/lat_lng_bounds.hpp"
#include "../map/camera_position.hpp"
+#include "../style/layers/layer.hpp"
#include <jni/jni.hpp>
@@ -13,6 +14,16 @@
namespace mbgl {
namespace android {
+ class SnapshotObserver final : public mbgl::MapSnapshotterObserver {
+ public:
+ ~SnapshotObserver() = default;
+ void onDidFinishLoadingStyle() override {
+ if (didFinishLoadingStyleCallback) {
+ didFinishLoadingStyleCallback();
+ }
+ }
+ std::function<void()> didFinishLoadingStyleCallback;
+ };
class MapSnapshotter {
public:
@@ -50,6 +61,8 @@ public:
void cancel(JNIEnv&);
+ void addLayer(JNIEnv&, jlong);
+
private:
MBGL_STORE_THREAD(tid);
@@ -60,7 +73,7 @@ private:
bool showLogo;
std::unique_ptr<mbgl::MapSnapshotter> snapshotter;
-
+ SnapshotObserver observer;
FileSource *jFileSource;
void activateFilesource(JNIEnv&);
void deactivateFilesource(JNIEnv&);