diff options
Diffstat (limited to 'platform/android/src/style')
| -rw-r--r-- | platform/android/src/style/conversion/geojson.hpp | 10 | ||||
| -rw-r--r-- | platform/android/src/style/sources/geojson_source.cpp | 23 | ||||
| -rw-r--r-- | platform/android/src/style/sources/geojson_source.hpp | 10 | ||||
| -rw-r--r-- | platform/android/src/style/sources/vector_source.cpp | 6 | ||||
| -rw-r--r-- | platform/android/src/style/sources/vector_source.hpp | 6 | ||||
| -rw-r--r-- | platform/android/src/style/value.cpp | 32 | ||||
| -rw-r--r-- | platform/android/src/style/value.hpp | 4 |
7 files changed, 50 insertions, 41 deletions
diff --git a/platform/android/src/style/conversion/geojson.hpp b/platform/android/src/style/conversion/geojson.hpp index db474e8542..32a473b092 100644 --- a/platform/android/src/style/conversion/geojson.hpp +++ b/platform/android/src/style/conversion/geojson.hpp @@ -1,11 +1,8 @@ #pragma once -#include "../value.hpp" - #include <mapbox/geojson.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/geojson.hpp> -#include <mbgl/util/logging.hpp> #include <jni/jni.hpp> namespace mbgl { @@ -14,14 +11,13 @@ namespace conversion { template <> optional<GeoJSON> convertGeoJSON(const mbgl::android::Value& value, Error& error) { - // Value should be a string wrapped in an object - mbgl::android::Value jsonValue = value.get("data"); - if(value.isNull()) { + + if(value.isNull() || !value.isString()) { error = { "no json data found" }; return {}; } - return convertGeoJSON(value.get("data").toString(), error); + return convertGeoJSON(value.toString(), error); } template <> diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 0c2d25f9fc..ad55889858 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -8,8 +8,8 @@ // C++ -> Java conversion #include "../../conversion/conversion.hpp" #include "../../conversion/collection.hpp" -#include "../../geometry/conversion/feature.hpp" - +#include "../../geojson/conversion/feature.hpp" +#include "../conversion/url_or_tileset.hpp" #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/geojson_options.hpp> @@ -47,7 +47,7 @@ namespace android { GeoJSONSource::~GeoJSONSource() = default; - void GeoJSONSource::setGeoJSON(jni::JNIEnv& env, jni::Object<> json) { + void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, jni::String json) { using namespace mbgl::style::conversion; // Convert the jni object @@ -62,15 +62,25 @@ namespace android { source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(*converted); } + void GeoJSONSource::setFeatureCollection(jni::JNIEnv& env, jni::Object<geojson::FeatureCollection> jFeatures) { + using namespace mbgl::android::geojson; + + // Convert the jni object + auto features = FeatureCollection::convert(env, jFeatures); + + // Update the core source + source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(GeoJSON(features)); + } + void GeoJSONSource::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::Array<jni::Object<Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env, + jni::Array<jni::Object<geojson::Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { using namespace mbgl::android::conversion; - using namespace mapbox::geometry; + using namespace mbgl::android::geojson; auto filter = toFilter(env, jfilter); auto features = source.querySourceFeatures({ {}, filter }); @@ -96,7 +106,8 @@ namespace android { std::make_unique<GeoJSONSource, JNIEnv&, jni::String, jni::Object<>>, "initialize", "finalize", - METHOD(&GeoJSONSource::setGeoJSON, "nativeSetGeoJson"), + METHOD(&GeoJSONSource::setGeoJSONString, "nativeSetGeoJsonString"), + METHOD(&GeoJSONSource::setFeatureCollection, "nativeSetFeatureCollection"), METHOD(&GeoJSONSource::setURL, "nativeSetUrl"), METHOD(&GeoJSONSource::querySourceFeatures, "querySourceFeatures") ); diff --git a/platform/android/src/style/sources/geojson_source.hpp b/platform/android/src/style/sources/geojson_source.hpp index 5b529fc52a..98d98e26b3 100644 --- a/platform/android/src/style/sources/geojson_source.hpp +++ b/platform/android/src/style/sources/geojson_source.hpp @@ -2,7 +2,8 @@ #include "source.hpp" #include <mbgl/style/sources/geojson_source.hpp> -#include "../../geometry/feature.hpp" +#include "../../geojson/feature.hpp" +#include "../../geojson/feature_collection.hpp" #include <jni/jni.hpp> namespace mbgl { @@ -23,11 +24,14 @@ public: ~GeoJSONSource(); - void setGeoJSON(jni::JNIEnv&, jni::Object<>); + void setGeoJSONString(jni::JNIEnv&, jni::String); + + void setFeatureCollection(jni::JNIEnv&, jni::Object<geojson::FeatureCollection>); void setURL(jni::JNIEnv&, jni::String); - jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::Object<>> jfilter); + jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, + jni::Array<jni::Object<>> jfilter); jni::jobject* createJavaPeer(jni::JNIEnv&); diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp index 4852a9b84f..53aa144450 100644 --- a/platform/android/src/style/sources/vector_source.cpp +++ b/platform/android/src/style/sources/vector_source.cpp @@ -7,7 +7,7 @@ // C++ -> Java conversion #include "../../conversion/conversion.hpp" #include "../../conversion/collection.hpp" -#include "../../geometry/conversion/feature.hpp" +#include "../../geojson/conversion/feature.hpp" #include "../conversion/url_or_tileset.hpp" #include <mbgl/util/variant.hpp> @@ -34,11 +34,11 @@ namespace android { VectorSource::~VectorSource() = default; - jni::Array<jni::Object<Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env, + jni::Array<jni::Object<geojson::Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env, jni::Array<jni::String> jSourceLayerIds, jni::Array<jni::Object<>> jfilter) { using namespace mbgl::android::conversion; - using namespace mapbox::geometry; + using namespace mbgl::android::geojson; mbgl::optional<std::vector<std::string>> sourceLayerIds = { toVector(env, jSourceLayerIds) }; auto filter = toFilter(env, jfilter); diff --git a/platform/android/src/style/sources/vector_source.hpp b/platform/android/src/style/sources/vector_source.hpp index f7e7645c5b..cac687bb6f 100644 --- a/platform/android/src/style/sources/vector_source.hpp +++ b/platform/android/src/style/sources/vector_source.hpp @@ -2,7 +2,7 @@ #include "source.hpp" #include <mbgl/style/sources/vector_source.hpp> -#include "../../geometry/feature.hpp" +#include "../../geojson/feature.hpp" #include <jni/jni.hpp> namespace mbgl { @@ -23,8 +23,8 @@ public: ~VectorSource(); - jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>, - jni::Array<jni::Object<>> jfilter); + jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>, + jni::Array<jni::Object<>> jfilter); jni::jobject* createJavaPeer(jni::JNIEnv&); diff --git a/platform/android/src/style/value.cpp b/platform/android/src/style/value.cpp index da953c14be..e1cd81d7fd 100644 --- a/platform/android/src/style/value.cpp +++ b/platform/android/src/style/value.cpp @@ -22,7 +22,7 @@ namespace android { // Instance - Value::Value(jni::JNIEnv& env, jni::jobject* _value) : jenv(env), value(_value, ObjectDeleter(env)) {} + Value::Value(jni::JNIEnv& _env, jni::jobject* _value) : env(_env), value(_value, ObjectDeleter(env)) {} Value::~Value() = default; @@ -31,59 +31,59 @@ namespace android { } bool Value::isArray() const { - return jni::IsInstanceOf(jenv, value.get(), *java::ObjectArray::jclass); + return jni::IsInstanceOf(env, value.get(), *java::ObjectArray::jclass); } bool Value::isObject() const { - return jni::IsInstanceOf(jenv, value.get(), *java::Map::jclass);; + return jni::IsInstanceOf(env, value.get(), *java::Map::jclass);; } bool Value::isString() const { - return jni::IsInstanceOf(jenv, value.get(), *java::String::jclass); + return jni::IsInstanceOf(env, value.get(), *java::String::jclass); } bool Value::isBool() const { - return jni::IsInstanceOf(jenv, value.get(), *java::Boolean::jclass); + return jni::IsInstanceOf(env, value.get(), *java::Boolean::jclass); } bool Value::isNumber() const { - return jni::IsInstanceOf(jenv, value.get(), *java::Number::jclass); + return jni::IsInstanceOf(env, value.get(), *java::Number::jclass); } std::string Value::toString() const { jni::jstring* string = reinterpret_cast<jni::jstring*>(value.get()); - return jni::Make<std::string>(jenv, jni::String(string)); + return jni::Make<std::string>(env, jni::String(string)); } float Value::toFloat() const { - return jni::CallMethod<jni::jfloat>(jenv, value.get(), *java::Number::floatValueMethodId); + return jni::CallMethod<jni::jfloat>(env, value.get(), *java::Number::floatValueMethodId); } double Value::toDouble() const { - return jni::CallMethod<jni::jdouble>(jenv, value.get(), *java::Number::doubleValueMethodId); + return jni::CallMethod<jni::jdouble>(env, value.get(), *java::Number::doubleValueMethodId); } long Value::toLong() const { - return jni::CallMethod<jni::jlong>(jenv, value.get(), *java::Number::longValueMethodId); + return jni::CallMethod<jni::jlong>(env, value.get(), *java::Number::longValueMethodId); } bool Value::toBool() const { - return jni::CallMethod<jni::jboolean>(jenv, value.get(), *java::Boolean::booleanValueMethodId); + return jni::CallMethod<jni::jboolean>(env, value.get(), *java::Boolean::booleanValueMethodId); } Value Value::get(const char* key) const { - jni::jobject* member = jni::CallMethod<jni::jobject*>(jenv, value.get(), *java::Map::getMethodId, jni::Make<jni::String>(jenv, std::string(key)).Get()); - return Value(jenv, member); + jni::jobject* member = jni::CallMethod<jni::jobject*>(env, value.get(), *java::Map::getMethodId, jni::Make<jni::String>(env, std::string(key)).Get()); + return Value(env, member); } int Value::getLength() const { auto array = (jni::jarray<jni::jobject>*) value.get(); - return jni::GetArrayLength(jenv, *array); + return jni::GetArrayLength(env, *array); } - Value Value::get(const int index ) const { + Value Value::get(const int index) const { auto array = (jni::jarray<jni::jobject>*) value.get(); - return Value(jenv, jni::GetObjectArrayElement(jenv, *array, index)); + return Value(env, jni::GetObjectArrayElement(env, *array, index)); } } } diff --git a/platform/android/src/style/value.hpp b/platform/android/src/style/value.hpp index 761ce4d730..7464bae832 100644 --- a/platform/android/src/style/value.hpp +++ b/platform/android/src/style/value.hpp @@ -29,9 +29,7 @@ public: int getLength() const; Value get(const int index ) const; -private: - - jni::JNIEnv& jenv; + jni::JNIEnv& env; std::shared_ptr<jni::jobject> value; }; |
