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

Commit

Permalink
Implement addImages function
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin committed Mar 17, 2020
1 parent 47c2ab5 commit 827af4c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
36 changes: 30 additions & 6 deletions platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ void MapSnapshotter::addSource(JNIEnv& env, const jni::Object<Source>& obj, jlon
jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/sources/CannotAddSourceException"), error.what());
}
}

void MapSnapshotter::addImages(JNIEnv& env, const jni::Array<jni::Object<mbgl::android::Image>>& 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<mbgl::style::Image>(image));
}
}

// Static methods //

void MapSnapshotter::registerNative(jni::JNIEnv& env) {
Expand All @@ -261,22 +272,35 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)

// Register the peer
jni::RegisterNativePeer<MapSnapshotter>(env, javaClass, "nativePtr",
jni::MakePeer<MapSnapshotter, const jni::Object<MapSnapshotter>&, const jni::Object<FileSource>&, jni::jfloat, jni::jint, jni::jint, const jni::String&, const jni::String&, const jni::Object<LatLngBounds>&, const jni::Object<CameraPosition>&, jni::jboolean, const jni::String&>,
"nativeInitialize",
"finalize",
jni::RegisterNativePeer<MapSnapshotter>(env,
javaClass,
"nativePtr",
jni::MakePeer<MapSnapshotter,
const jni::Object<MapSnapshotter>&,
const jni::Object<FileSource>&,
jni::jfloat,
jni::jint,
jni::jint,
const jni::String&,
const jni::String&,
const jni::Object<LatLngBounds>&,
const jni::Object<CameraPosition>&,
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
Expand Down
8 changes: 4 additions & 4 deletions platform/android/src/snapshotter/map_snapshotter.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#pragma once

#include <jni/jni.hpp>
#include <mbgl/map/map_snapshotter.hpp>
#include <mbgl/util/util.hpp>
#include <memory>

#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 <jni/jni.hpp>

#include <memory>

namespace mbgl {
namespace android {

Expand Down Expand Up @@ -56,6 +55,7 @@ class MapSnapshotter final : public mbgl::MapSnapshotterObserver {
void addLayerBelow(JNIEnv&, jlong, const jni::String&);
void addLayerAbove(JNIEnv&, jlong, const jni::String&);
void addSource(JNIEnv&, const jni::Object<Source>&, jlong nativePtr);
void addImages(JNIEnv&, const jni::Array<jni::Object<mbgl::android::Image>>&);

// MapSnapshotterObserver overrides
void onDidFailLoadingStyle(const std::string&) override;
Expand Down

0 comments on commit 827af4c

Please sign in to comment.