diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-03-05 16:55:58 -0800 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-03-09 13:11:23 -0800 |
commit | b2b5f9e571e9fedfd682081a3832db7618b1049a (patch) | |
tree | a35978d009c4cf6f86cf26b4bf0a83c0b0f6cc16 /platform/android/src/style | |
parent | 12568f21a39dfec7788ebee2815c4c0b2ee964d8 (diff) | |
download | qtlocation-mapboxgl-b2b5f9e571e9fedfd682081a3832db7618b1049a.tar.gz |
[android] query source features
Diffstat (limited to 'platform/android/src/style')
5 files changed, 80 insertions, 3 deletions
diff --git a/platform/android/src/style/conversion/filter.hpp b/platform/android/src/style/conversion/filter.hpp new file mode 100644 index 0000000000..fc36d3a044 --- /dev/null +++ b/platform/android/src/style/conversion/filter.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "../android_conversion.hpp" +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/filter.hpp> + +#include <jni/jni.hpp> + +#include <tuple> +#include <map> + +namespace mbgl { +namespace android { +namespace conversion { + +inline optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { + mbgl::optional<mbgl::style::Filter> filter; + if (jfilter) { + Value filterValue(env, jfilter); + auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(filterValue); + if (!converted) { + mbgl::Log::Error(mbgl::Event::JNI, "Error converting filter: " + converted.error().message); + } + filter = std::move(*converted); + } + return filter; +} + +} // namespace conversion +} // namespace android +} // namespace mbgl
\ No newline at end of file diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 37ce0644c1..7ab98e47c0 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -1,7 +1,15 @@ #include "geojson_source.hpp" +// Java -> C++ conversion #include "../android_conversion.hpp" +#include "../conversion/filter.hpp" #include "../conversion/geojson.hpp" + +// C++ -> Java conversion +#include "../../conversion/conversion.hpp" +#include "../../conversion/collection.hpp" +#include "../../geometry/conversion/feature.hpp" +#include "../conversion/url_or_tileset.hpp" #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/geojson_options.hpp> @@ -43,6 +51,16 @@ namespace android { 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<>> jfilter) { + using namespace mbgl::android::conversion; + using namespace mapbox::geometry; + + auto filter = toFilter(env, jfilter); + auto features = source.querySourceFeatures({ {}, filter }); + return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features); + } + jni::Class<GeoJSONSource> GeoJSONSource::javaClass; jni::jobject* GeoJSONSource::createJavaPeer(jni::JNIEnv& env) { @@ -63,7 +81,8 @@ namespace android { "initialize", "finalize", METHOD(&GeoJSONSource::setGeoJSON, "nativeSetGeoJson"), - METHOD(&GeoJSONSource::setURL, "nativeSetUrl") + 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 10c51e81b2..5b529fc52a 100644 --- a/platform/android/src/style/sources/geojson_source.hpp +++ b/platform/android/src/style/sources/geojson_source.hpp @@ -2,6 +2,7 @@ #include "source.hpp" #include <mbgl/style/sources/geojson_source.hpp> +#include "../../geometry/feature.hpp" #include <jni/jni.hpp> namespace mbgl { @@ -26,6 +27,8 @@ public: void setURL(jni::JNIEnv&, jni::String); + jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::Object<>> jfilter); + jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class GeoJSONSource diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp index e60d8d4641..67777f50d4 100644 --- a/platform/android/src/style/sources/vector_source.cpp +++ b/platform/android/src/style/sources/vector_source.cpp @@ -1,12 +1,19 @@ #include "vector_source.hpp" +// Java -> C++ conversion #include "../android_conversion.hpp" -#include "../value.hpp" +#include "../conversion/filter.hpp" + +// C++ -> Java conversion +#include "../../conversion/conversion.hpp" +#include "../../conversion/collection.hpp" +#include "../../geometry/conversion/feature.hpp" #include "../conversion/url_or_tileset.hpp" #include <mbgl/util/variant.hpp> #include <string> +#include <vector> namespace mbgl { namespace android { @@ -27,6 +34,18 @@ namespace android { VectorSource::~VectorSource() = default; + jni::Array<jni::Object<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; + + mbgl::optional<std::vector<std::string>> sourceLayerIds = { toVector(env, jSourceLayerIds) }; + auto filter = toFilter(env, jfilter); + auto features = source.querySourceFeatures({ sourceLayerIds, filter }); + return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features); + } + jni::Class<VectorSource> VectorSource::javaClass; jni::jobject* VectorSource::createJavaPeer(jni::JNIEnv& env) { @@ -45,7 +64,8 @@ namespace android { env, VectorSource::javaClass, "nativePtr", std::make_unique<VectorSource, JNIEnv&, jni::String, jni::Object<>>, "initialize", - "finalize" + "finalize", + METHOD(&VectorSource::querySourceFeatures, "querySourceFeatures") ); } diff --git a/platform/android/src/style/sources/vector_source.hpp b/platform/android/src/style/sources/vector_source.hpp index 95d22ef7b7..f7e7645c5b 100644 --- a/platform/android/src/style/sources/vector_source.hpp +++ b/platform/android/src/style/sources/vector_source.hpp @@ -2,6 +2,7 @@ #include "source.hpp" #include <mbgl/style/sources/vector_source.hpp> +#include "../../geometry/feature.hpp" #include <jni/jni.hpp> namespace mbgl { @@ -22,6 +23,9 @@ public: ~VectorSource(); + jni::Array<jni::Object<Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>, + jni::Array<jni::Object<>> jfilter); + jni::jobject* createJavaPeer(jni::JNIEnv&); }; // class VectorSource |