summaryrefslogtreecommitdiff
path: root/platform/android/src/style/sources/image_source.cpp
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-25 14:36:05 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-06-19 09:50:08 -0700
commitb7c7d3fdab283d7bf03d8acf68b9cfd478d6973f (patch)
treed0e2d24300e5b28fe3a5f91d37456ffcb988d287 /platform/android/src/style/sources/image_source.cpp
parentab5b310a9eb7c88935cc457da1af81349fbe8d41 (diff)
downloadqtlocation-mapboxgl-b7c7d3fdab283d7bf03d8acf68b9cfd478d6973f.tar.gz
[android] Add ImageSource bindings
Diffstat (limited to 'platform/android/src/style/sources/image_source.cpp')
-rw-r--r--platform/android/src/style/sources/image_source.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/platform/android/src/style/sources/image_source.cpp b/platform/android/src/style/sources/image_source.cpp
index 9909675f44..cc7e1e7404 100644
--- a/platform/android/src/style/sources/image_source.cpp
+++ b/platform/android/src/style/sources/image_source.cpp
@@ -6,15 +6,19 @@
// C++ -> Java conversion
#include "../../conversion/conversion.hpp"
#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/premultiply.hpp>
+#include "../../bitmap.hpp"
#include <string>
+#include <array>
namespace mbgl {
namespace android {
- ImageSource::ImageSource(jni::JNIEnv& env, jni::String sourceId)
+ ImageSource::ImageSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<LatLngQuad> coordinatesObject)
: Source(env, std::make_unique<mbgl::style::ImageSource>(
- jni::Make<std::string>(env, sourceId)
+ jni::Make<std::string>(env, sourceId),
+ LatLngQuad::getLatLngArray(env, coordinatesObject)
)
) {
}
@@ -25,31 +29,20 @@ namespace android {
ImageSource::~ImageSource() = default;
- void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, jni::String json) {
- using namespace mbgl::style::conversion;
-
- // Convert the jni object
- Error error;
- optional<GeoJSON> converted = convert<GeoJSON>(Value(env, json), error);
- if(!converted) {
- mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + error.message);
- return;
- }
-
- // Update the core source
- source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(*converted);
- }
-
void ImageSource::setURL(jni::JNIEnv& env, jni::String url) {
// Update the core source
- source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setURL(jni::Make<std::string>(env, url));
+ source.as<mbgl::style::ImageSource>()->ImageSource::setURL(jni::Make<std::string>(env, url));
}
jni::String ImageSource::getURL(jni::JNIEnv& env) {
- std::string url = source.as<mbgl::style::ImageSource>()->ImageSource::getURL();
- return !url.empty() ? jni::Make<jni::String>(env, url) : jni::String();
+ optional<std::string> url = source.as<mbgl::style::ImageSource>()->ImageSource::getURL();
+ return url ? jni::Make<jni::String>(env, *url) : jni::String();
}
+ void ImageSource::setImage(jni::JNIEnv& env, jni::Object<Bitmap> bitmap) {
+ UnassociatedImage image = util::unpremultiply(Bitmap::GetImage(env, bitmap));
+ source.as<mbgl::style::ImageSource>()->setImage(std:: move(image));
+ }
jni::Class<ImageSource> ImageSource::javaClass;
@@ -66,14 +59,13 @@ namespace android {
// Register the peer
jni::RegisterNativePeer<ImageSource>(
- env, ImageSource::javaClass, "nativePtr",
- std::make_unique<ImageSource, JNIEnv&, jni::String, jni::Object<>>,
- "initialize",
- "finalize",
- METHOD(&ImageSource::setGeoJSONString, "nativeSetGeoJsonString"),
- METHOD(&ImageSource::setURL, "nativeSetUrl"),
- METHOD(&ImageSource::getURL, "nativeGetUrl"),
- METHOD(&ImageSource::getURL, "nativeGetUrl"),
+ env, ImageSource::javaClass, "nativePtr",
+ std::make_unique<ImageSource, JNIEnv&, jni::String, jni::Object<LatLngQuad>>,
+ "initialize",
+ "finalize",
+ METHOD(&ImageSource::setURL, "nativeSetUrl"),
+ METHOD(&ImageSource::getURL, "nativeGetUrl"),
+ METHOD(&ImageSource::setImage, "nativeSetImage")
);
}