summaryrefslogtreecommitdiff
path: root/platform/android
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
commitab5b310a9eb7c88935cc457da1af81349fbe8d41 (patch)
treee1485c8aa2f00e2b50daa0aa7f997ddda59c2562 /platform/android
parent7b05606464ac4d57b59b64015629e9578cbebac2 (diff)
downloadqtlocation-mapboxgl-ab5b310a9eb7c88935cc457da1af81349fbe8d41.tar.gz
[iOS][macOS] Add ImageSource bindings
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/src/style/sources/image_source.cpp81
-rw-r--r--platform/android/src/style/sources/image_source.hpp33
2 files changed, 114 insertions, 0 deletions
diff --git a/platform/android/src/style/sources/image_source.cpp b/platform/android/src/style/sources/image_source.cpp
new file mode 100644
index 0000000000..9909675f44
--- /dev/null
+++ b/platform/android/src/style/sources/image_source.cpp
@@ -0,0 +1,81 @@
+#include "image_source.hpp"
+
+// Java -> C++ conversion
+#include "../android_conversion.hpp"
+
+// C++ -> Java conversion
+#include "../../conversion/conversion.hpp"
+#include <mbgl/style/conversion.hpp>
+
+#include <string>
+
+namespace mbgl {
+namespace android {
+
+ ImageSource::ImageSource(jni::JNIEnv& env, jni::String sourceId)
+ : Source(env, std::make_unique<mbgl::style::ImageSource>(
+ jni::Make<std::string>(env, sourceId)
+ )
+ ) {
+ }
+
+ ImageSource::ImageSource(mbgl::Map& map, mbgl::style::ImageSource& coreSource)
+ : Source(map, coreSource) {
+ }
+
+ 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));
+ }
+
+ 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();
+ }
+
+
+ jni::Class<ImageSource> ImageSource::javaClass;
+
+ jni::jobject* ImageSource::createJavaPeer(jni::JNIEnv& env) {
+ static auto constructor = ImageSource::javaClass.template GetConstructor<jni::jlong>(env);
+ return ImageSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
+ }
+
+ void ImageSource::registerNative(jni::JNIEnv& env) {
+ // Lookup the class
+ ImageSource::javaClass = *jni::Class<ImageSource>::Find(env).NewGlobalRef(env).release();
+
+ #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
+
+ // 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"),
+ );
+ }
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/style/sources/image_source.hpp b/platform/android/src/style/sources/image_source.hpp
new file mode 100644
index 0000000000..d5802ed5a1
--- /dev/null
+++ b/platform/android/src/style/sources/image_source.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "source.hpp"
+#include <mbgl/style/sources/image_source.hpp>
+#include <jni/jni.hpp>
+
+namespace mbgl {
+namespace android {
+
+class ImageSource : public Source {
+public:
+
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/ImageSource"; };
+
+ static jni::Class<ImageSource> javaClass;
+
+ static void registerNative(jni::JNIEnv&);
+
+ ImageSource(jni::JNIEnv&, jni::String, jni::Object<>);
+
+ ImageSource(mbgl::Map&, mbgl::style::ImageSource&);
+
+ ~ImageSource();
+
+ void setURL(jni::JNIEnv&, jni::String);
+ jni::String getURL(jni::JNIEnv&);
+
+ jni::jobject* createJavaPeer(jni::JNIEnv&);
+
+}; // class ImageSource
+
+} // namespace android
+} // namespace mbgl