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 | |
parent | 12568f21a39dfec7788ebee2815c4c0b2ee964d8 (diff) | |
download | qtlocation-mapboxgl-b2b5f9e571e9fedfd682081a3832db7618b1049a.tar.gz |
[android] query source features
Diffstat (limited to 'platform/android/src')
-rw-r--r-- | platform/android/src/conversion/collection.hpp | 3 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 17 | ||||
-rw-r--r-- | platform/android/src/style/conversion/filter.hpp | 31 | ||||
-rw-r--r-- | platform/android/src/style/sources/geojson_source.cpp | 21 | ||||
-rw-r--r-- | platform/android/src/style/sources/geojson_source.hpp | 3 | ||||
-rw-r--r-- | platform/android/src/style/sources/vector_source.cpp | 24 | ||||
-rw-r--r-- | platform/android/src/style/sources/vector_source.hpp | 4 |
7 files changed, 83 insertions, 20 deletions
diff --git a/platform/android/src/conversion/collection.hpp b/platform/android/src/conversion/collection.hpp index da5eed64d2..549121c7ef 100644 --- a/platform/android/src/conversion/collection.hpp +++ b/platform/android/src/conversion/collection.hpp @@ -39,8 +39,9 @@ inline std::vector<std::string> toVector(JNIEnv& env, jni::jarray<jni::jobject>& } inline std::vector<std::string> toVector(JNIEnv& env, jni::Array<jni::String> array) { - std::vector<std::string> vector; std::size_t len = array.Length(env); + std::vector<std::string> vector; + vector.reserve(len); for (std::size_t i = 0; i < len; i++) { jni::String jstr = array.Get(env, i); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index c97bdbbfe3..d6307ad80d 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -36,6 +36,7 @@ // C++ -> Java conversion #include "conversion/conversion.hpp" #include "conversion/collection.hpp" +#include "style/conversion/filter.hpp" #include "geometry/conversion/feature.hpp" #include "jni.hpp" @@ -721,22 +722,6 @@ jni::Array<jlong> NativeMapView::queryPointAnnotations(JNIEnv& env, jni::Object< return result; } -static inline optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { - using namespace mbgl::style; - using namespace mbgl::style::conversion; - - mbgl::optional<Filter> filter; - if (jfilter) { - Value filterValue(env, jfilter); - auto converted = convert<Filter>(filterValue); - if (!converted) { - mbgl::Log::Error(mbgl::Event::JNI, "Error setting filter: " + converted.error().message); - } - filter = std::move(*converted); - } - return filter; -} - jni::Array<jni::Object<Feature>> NativeMapView::queryRenderedFeaturesForPoint(JNIEnv& env, jni::jfloat x, jni::jfloat y, jni::Array<jni::String> layerIds, jni::Array<jni::Object<>> jfilter) { 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 |