summaryrefslogtreecommitdiff
path: root/platform/android/src/style
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
parentab5b310a9eb7c88935cc457da1af81349fbe8d41 (diff)
downloadqtlocation-mapboxgl-b7c7d3fdab283d7bf03d8acf68b9cfd478d6973f.tar.gz
[android] Add ImageSource bindings
Diffstat (limited to 'platform/android/src/style')
-rw-r--r--platform/android/src/style/conversion/latlngquad.hpp24
-rw-r--r--platform/android/src/style/sources/image_source.cpp48
-rw-r--r--platform/android/src/style/sources/image_source.hpp7
-rw-r--r--platform/android/src/style/sources/sources.cpp5
4 files changed, 55 insertions, 29 deletions
diff --git a/platform/android/src/style/conversion/latlngquad.hpp b/platform/android/src/style/conversion/latlngquad.hpp
new file mode 100644
index 0000000000..9d1a83e164
--- /dev/null
+++ b/platform/android/src/style/conversion/latlngquad.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <mapbox/geojson.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/geojson.hpp>
+#include <jni/jni.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <>
+optional<std::array<LatLng, 4>> Converter<std::array<LatLng, 4>>::operator()(const mbgl::android::Value& value, Error& error) const {
+ if (value.isNull() || !value.isArray()) {
+ error = { "value cannot be converted to LatLng array" };
+ return {};
+ }
+
+ return convert<GeoJSON>(value.toString(), error);
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl
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")
);
}
diff --git a/platform/android/src/style/sources/image_source.hpp b/platform/android/src/style/sources/image_source.hpp
index d5802ed5a1..309d17a299 100644
--- a/platform/android/src/style/sources/image_source.hpp
+++ b/platform/android/src/style/sources/image_source.hpp
@@ -1,12 +1,15 @@
#pragma once
#include "source.hpp"
+#include "../../geometry/lat_lng_quad.hpp"
#include <mbgl/style/sources/image_source.hpp>
#include <jni/jni.hpp>
namespace mbgl {
namespace android {
+class Bitmap;
+
class ImageSource : public Source {
public:
@@ -16,7 +19,7 @@ public:
static void registerNative(jni::JNIEnv&);
- ImageSource(jni::JNIEnv&, jni::String, jni::Object<>);
+ ImageSource(jni::JNIEnv&, jni::String, jni::Object<LatLngQuad>);
ImageSource(mbgl::Map&, mbgl::style::ImageSource&);
@@ -25,6 +28,8 @@ public:
void setURL(jni::JNIEnv&, jni::String);
jni::String getURL(jni::JNIEnv&);
+ void setImage(jni::JNIEnv&, jni::Object<Bitmap>);
+
jni::jobject* createJavaPeer(jni::JNIEnv&);
}; // class ImageSource
diff --git a/platform/android/src/style/sources/sources.cpp b/platform/android/src/style/sources/sources.cpp
index b4e70202b4..7ca6328e71 100644
--- a/platform/android/src/style/sources/sources.cpp
+++ b/platform/android/src/style/sources/sources.cpp
@@ -2,11 +2,13 @@
#include <mbgl/style/source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/image_source.hpp>
#include <mbgl/style/sources/raster_source.hpp>
#include <mbgl/style/sources/vector_source.hpp>
#include "source.hpp"
#include "geojson_source.hpp"
+#include "image_source.hpp"
#include "raster_source.hpp"
#include "unknown_source.hpp"
#include "vector_source.hpp"
@@ -22,6 +24,8 @@ Source* initializeSourcePeer(mbgl::Map& map, mbgl::style::Source& coreSource) {
source = new RasterSource(map, *coreSource.as<mbgl::style::RasterSource>());
} else if (coreSource.is<mbgl::style::GeoJSONSource>()) {
source = new GeoJSONSource(map, *coreSource.as<mbgl::style::GeoJSONSource>());
+ } else if (coreSource.is<mbgl::style::ImageSource>()) {
+ source = new ImageSource(map, *coreSource.as<mbgl::style::ImageSource>());
} else {
source = new UnknownSource(map, coreSource);
}
@@ -39,6 +43,7 @@ jni::jobject* createJavaSourcePeer(jni::JNIEnv& env, mbgl::Map& map, mbgl::style
void registerNativeSources(jni::JNIEnv& env) {
Source::registerNative(env);
GeoJSONSource::registerNative(env);
+ ImageSource::registerNative(env);
RasterSource::registerNative(env);
UnknownSource::registerNative(env);
VectorSource::registerNative(env);