summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-10-27 20:08:47 +0300
committerIvo van Dongen <info@ivovandongen.nl>2017-10-31 10:05:40 +0200
commit1c4b6a78328f0f39992fd39df68a9b609c32c059 (patch)
tree59a11f7ce237b192b52b98bbf6cea14817a5d018
parentd65676db51b14f7d11d447428c65a00c999b4d7c (diff)
downloadqtlocation-mapboxgl-upstream/ivd-mapsnapshotter-extensions.tar.gz
[android] map snapshotter - expose attributionsupstream/ivd-mapsnapshotter-extensions
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java11
-rw-r--r--platform/android/src/jni/collection.hpp26
-rw-r--r--platform/android/src/snapshotter/map_snapshot.cpp6
-rw-r--r--platform/android/src/snapshotter/map_snapshot.hpp4
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp6
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");