Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

add style json setter/getter to map snapshotter #12031

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void MapSnapshotter::setStyleUrl(JNIEnv& env, jni::String styleURL) {
snapshotter->setStyleURL(jni::Make<std::string>(env, styleURL));
}

void MapSnapshotter::setStyleJson(JNIEnv& env, jni::String styleJSON) {
snapshotter->setStyleJSON(jni::Make<std::string>(env, styleJSON));
}

void MapSnapshotter::setSize(JNIEnv&, jni::jint width, jni::jint height) {
auto size = mbgl::Size { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
snapshotter->setSize(size);
Expand All @@ -121,6 +125,7 @@ void MapSnapshotter::setRegion(JNIEnv& env, jni::Object<LatLngBounds> region) {
snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region));
}


// Private methods //

void MapSnapshotter::activateFilesource(JNIEnv& env) {
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/snapshotter/map_snapshotter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CameraPosition> position);
Expand Down
19 changes: 19 additions & 0 deletions platform/default/mbgl/map/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions platform/default/mbgl/map/map_snapshotter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down