diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java index 641c2837986..a2c7ed5dfd9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java @@ -278,6 +278,12 @@ public void start(@NonNull SnapshotReadyCallback callback, ErrorHandler errorHan */ public native void setStyleUrl(String styleUrl); + /** + * Updates the snapshotter with a new style json + * + * @param styleJson the style json + */ + public native void setStyleJson(String styleJson); /** * Must be called in on the thread diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index ca1307dd169..8c064f5707c 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -107,6 +107,10 @@ void MapSnapshotter::setStyleUrl(JNIEnv& env, jni::String styleURL) { snapshotter->setStyleURL(jni::Make(env, styleURL)); } +void MapSnapshotter::setStyleJson(JNIEnv& env, jni::String styleJSON) { + snapshotter->setStyleJSON(jni::Make(env, styleJSON)); +} + void MapSnapshotter::setSize(JNIEnv&, jni::jint width, jni::jint height) { auto size = mbgl::Size { static_cast(width), static_cast(height) }; snapshotter->setSize(size); @@ -121,6 +125,7 @@ void MapSnapshotter::setRegion(JNIEnv& env, jni::Object region) { snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region)); } + // Private methods // void MapSnapshotter::activateFilesource(JNIEnv& env) { @@ -153,6 +158,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) { "nativeInitialize", "finalize", METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"), + METHOD(&MapSnapshotter::setStyleJson, "setStyleJson"), METHOD(&MapSnapshotter::setSize, "setSize"), METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"), METHOD(&MapSnapshotter::setRegion, "setRegion"), diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 33d32e01a17..3be2cb4f6c2 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -44,6 +44,8 @@ class MapSnapshotter { void setStyleUrl(JNIEnv&, jni::String styleURL); + void setStyleJson(JNIEnv&, jni::String styleJSON); + void setSize(JNIEnv&, jni::jint width, jni::jint height); void setCameraPosition(JNIEnv&, jni::Object position); diff --git a/platform/default/mbgl/map/map_snapshotter.cpp b/platform/default/mbgl/map/map_snapshotter.cpp index da3a250e0f9..39f96d72107 100644 --- a/platform/default/mbgl/map/map_snapshotter.cpp +++ b/platform/default/mbgl/map/map_snapshotter.cpp @@ -25,6 +25,9 @@ class MapSnapshotter::Impl { void setStyleURL(std::string styleURL); std::string getStyleURL() const; + void setStyleJSON(std::string styleJSON); + std::string getStyleJSON() const; + void setSize(Size); Size getSize() const; @@ -107,6 +110,14 @@ std::string MapSnapshotter::Impl::getStyleURL() const { return map.getStyle().getURL(); } +void MapSnapshotter::Impl::setStyleJSON(std::string styleJSON) { + map.getStyle().loadJSON(styleJSON); +} + +std::string MapSnapshotter::Impl::getStyleJSON() const { + return map.getStyle().getJSON(); +} + void MapSnapshotter::Impl::setSize(Size size) { map.setSize(size); frontend.setSize(size); @@ -160,6 +171,14 @@ std::string MapSnapshotter::getStyleURL() const { return impl->actor().ask(&Impl::getStyleURL).get(); } +void MapSnapshotter::setStyleJSON(const std::string& styleJSON) { + impl->actor().invoke(&Impl::setStyleJSON, styleJSON); +} + +std::string MapSnapshotter::getStyleJSON() const { + return impl->actor().ask(&Impl::getStyleJSON).get(); +} + void MapSnapshotter::setSize(const Size& size) { impl->actor().invoke(&Impl::setSize, size); } diff --git a/platform/default/mbgl/map/map_snapshotter.hpp b/platform/default/mbgl/map/map_snapshotter.hpp index a71da121c06..e0363a7b380 100644 --- a/platform/default/mbgl/map/map_snapshotter.hpp +++ b/platform/default/mbgl/map/map_snapshotter.hpp @@ -39,6 +39,9 @@ class MapSnapshotter { void setStyleURL(const std::string& styleURL); std::string getStyleURL() const; + void setStyleJSON(const std::string& styleJSON); + std::string getStyleJSON() const; + void setSize(const Size&); Size getSize() const;