From 91c76dad529ea85a011f3c57030721eda40a6c68 Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 17 Mar 2020 14:02:48 +0800 Subject: Implement addImages function --- .../android/src/snapshotter/map_snapshotter.cpp | 36 ++++++++++++++++++---- .../android/src/snapshotter/map_snapshotter.hpp | 8 ++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 3ec16e8baa..62ee5ff67e 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -252,6 +252,17 @@ void MapSnapshotter::addSource(JNIEnv& env, const jni::Object& obj, jlon jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/sources/CannotAddSourceException"), error.what()); } } + +void MapSnapshotter::addImages(JNIEnv& env, const jni::Array>& jimages) { + jni::NullCheck(env, &jimages); + std::size_t len = jimages.Length(env); + + for (std::size_t i = 0; i < len; i++) { + auto image = mbgl::android::Image::getImage(env, jimages.Get(env, i)); + snapshotter->getStyle().addImage(std::make_unique(image)); + } +} + // Static methods // void MapSnapshotter::registerNative(jni::JNIEnv& env) { @@ -261,22 +272,35 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) { #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer - jni::RegisterNativePeer(env, javaClass, "nativePtr", - jni::MakePeer&, const jni::Object&, jni::jfloat, jni::jint, jni::jint, const jni::String&, const jni::String&, const jni::Object&, const jni::Object&, jni::jboolean, const jni::String&>, - "nativeInitialize", - "finalize", + jni::RegisterNativePeer(env, + javaClass, + "nativePtr", + jni::MakePeer&, + const jni::Object&, + jni::jfloat, + jni::jint, + jni::jint, + const jni::String&, + const jni::String&, + const jni::Object&, + const jni::Object&, + jni::jboolean, + const jni::String&>, + "nativeInitialize", + "finalize", METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"), METHOD(&MapSnapshotter::addLayerAt, "nativeAddLayerAt"), METHOD(&MapSnapshotter::addLayerBelow, "nativeAddLayerBelow"), METHOD(&MapSnapshotter::addLayerAbove, "nativeAddLayerAbove"), METHOD(&MapSnapshotter::addSource, "nativeAddSource"), + METHOD(&MapSnapshotter::addImages, "nativeAddImages"), METHOD(&MapSnapshotter::setStyleJson, "setStyleJson"), METHOD(&MapSnapshotter::setSize, "setSize"), METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"), METHOD(&MapSnapshotter::setRegion, "setRegion"), METHOD(&MapSnapshotter::start, "nativeStart"), - METHOD(&MapSnapshotter::cancel, "nativeCancel") - ); + METHOD(&MapSnapshotter::cancel, "nativeCancel")); } } // namespace android diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 9239a5ea19..87bc470272 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -1,18 +1,17 @@ #pragma once +#include #include #include +#include #include "../file_source.hpp" #include "../geometry/lat_lng_bounds.hpp" #include "../map/camera_position.hpp" +#include "../map/image.hpp" #include "../style/layers/layer.hpp" #include "../style/sources/source.hpp" -#include - -#include - namespace mbgl { namespace android { @@ -56,6 +55,7 @@ public: void addLayerBelow(JNIEnv&, jlong, const jni::String&); void addLayerAbove(JNIEnv&, jlong, const jni::String&); void addSource(JNIEnv&, const jni::Object&, jlong nativePtr); + void addImages(JNIEnv&, const jni::Array>&); // MapSnapshotterObserver overrides void onDidFailLoadingStyle(const std::string&) override; -- cgit v1.2.1