diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-10-27 20:08:47 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-10-31 19:52:08 +0200 |
commit | e0a305247abcf58c4d1d0ef234d7a9b1ba768554 (patch) | |
tree | bf859963e29318eaf15c2fa74a3e6c7c0a0e1d48 /platform | |
parent | 2d81186fc1b05921c4ca996461b7c743b0a97dec (diff) | |
download | qtlocation-mapboxgl-e0a305247abcf58c4d1d0ef234d7a9b1ba768554.tar.gz |
[android] map snapshotter - expose attributions
Diffstat (limited to 'platform')
5 files changed, 48 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java index 2d1412aeda..aefa962402 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java @@ -14,13 +14,15 @@ public class MapSnapshot { private long nativePtr = 0; private Bitmap bitmap; + private String[] attributions; /** * Created from native side */ - private MapSnapshot(long nativePtr, Bitmap bitmap) { + private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions) { this.nativePtr = nativePtr; this.bitmap = bitmap; + this.attributions = attributions; } /** @@ -38,6 +40,13 @@ public class MapSnapshot { */ public native PointF pixelForLatLng(LatLng latLng); + /** + * @return The attributions for the sources of this snapshot. + */ + protected String[] getAttributions() { + return attributions; + } + // Unused, needed for peer binding private native void initialize(); diff --git a/platform/android/src/jni/collection.hpp b/platform/android/src/jni/collection.hpp new file mode 100644 index 0000000000..5f94ec29ce --- /dev/null +++ b/platform/android/src/jni/collection.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include <jni/jni.hpp> + +#include <string> +#include <vector> + +namespace jni { + +inline Array<String> MakeAnything(ThingToMake<Array<String>>, JNIEnv& env, const std::vector<std::string>& vector) +{ + static auto clazz = *Class<StringTag>::Find(env).NewGlobalRef(env).release(); + auto result = Array<String>::New(env, vector.size(), clazz); + + std::size_t index = 0; + for (auto&& item : vector) { + auto element = Make<jni::String>(env, item); + result.Set(env, index, element); + DeleteLocalRef(env, element); + index++; + } + + return result; +} + +} diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp index 09e83bbb8a..843a8a487a 100644 --- a/platform/android/src/snapshotter/map_snapshot.cpp +++ b/platform/android/src/snapshotter/map_snapshot.cpp @@ -1,6 +1,7 @@ #include "map_snapshot.hpp" #include "../bitmap.hpp" +#include "../jni/collection.hpp" #include <memory> @@ -25,14 +26,15 @@ jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<La jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, + std::vector<std::string> 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::jlong, jni::Object<Bitmap>>(env); + static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>>(env); auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn); - return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap); + return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions)); } jni::Class<MapSnapshot> MapSnapshot::javaClass; diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp index 6d60d49728..64090bb48b 100644 --- a/platform/android/src/snapshotter/map_snapshot.hpp +++ b/platform/android/src/snapshotter/map_snapshot.hpp @@ -7,6 +7,9 @@ #include "../geometry/lat_lng.hpp" #include "../graphics/pointf.hpp" +#include <vector> +#include <string> + namespace mbgl { namespace android { @@ -22,6 +25,7 @@ public: static jni::Object<MapSnapshot> New(JNIEnv& env, PremultipliedImage&& image, float pixelRatio, + std::vector<std::string> attributions, PointForFn pointForFn); MapSnapshot(jni::JNIEnv&) {}; diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index a13e91ccd3..3c6623af40 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -58,7 +58,9 @@ MapSnapshotter::~MapSnapshotter() = default; void MapSnapshotter::start(JNIEnv&) { MBGL_VERIFY_THREAD(tid); - snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(*Scheduler::GetCurrent(), [this](std::exception_ptr err, PremultipliedImage image, mbgl::MapSnapshotter::PointForFn pointForFn) { + 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_VERIFY_THREAD(tid); android::UniqueEnv _env = android::AttachEnv(); @@ -68,7 +70,7 @@ void MapSnapshotter::start(JNIEnv&) { javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err))); } else { // Create the wrapper - auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, pointForFn); + auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, pointForFn); // invoke callback static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady"); |