summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-08-22 10:22:23 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-09-07 09:44:12 -0700
commit115e8625e14d15f3fe18681e1e05a06271e2c2e0 (patch)
treeca93fe84add2be0d5c87a0a92569a3114fca58dc
parent53c3c327f0ebea276d977f58a59cdb9449165518 (diff)
downloadqtlocation-mapboxgl-115e8625e14d15f3fe18681e1e05a06271e2c2e0.tar.gz
[android] Simplify Feature conversion
-rw-r--r--platform/android/core-files.txt2
-rw-r--r--platform/android/src/geojson/conversion/feature.cpp55
-rw-r--r--platform/android/src/geojson/conversion/feature.hpp22
-rw-r--r--platform/android/src/geojson/feature.cpp72
-rw-r--r--platform/android/src/geojson/feature.hpp17
-rwxr-xr-xplatform/android/src/native_map_view.cpp6
-rw-r--r--platform/android/src/style/sources/custom_geometry_source.cpp4
-rw-r--r--platform/android/src/style/sources/geojson_source.cpp4
-rw-r--r--platform/android/src/style/sources/vector_source.cpp4
9 files changed, 55 insertions, 131 deletions
diff --git a/platform/android/core-files.txt b/platform/android/core-files.txt
index 9a57e76808..cd4028cd59 100644
--- a/platform/android/core-files.txt
+++ b/platform/android/core-files.txt
@@ -55,8 +55,6 @@ platform/android/src/conversion/color.hpp
platform/android/src/conversion/constant.cpp
platform/android/src/conversion/constant.hpp
platform/android/src/conversion/conversion.hpp
-platform/android/src/geojson/conversion/feature.cpp
-platform/android/src/geojson/conversion/feature.hpp
platform/android/src/style/conversion/filter.cpp
platform/android/src/style/conversion/filter.hpp
platform/android/src/style/conversion/position.cpp
diff --git a/platform/android/src/geojson/conversion/feature.cpp b/platform/android/src/geojson/conversion/feature.cpp
deleted file mode 100644
index 7386e29df5..0000000000
--- a/platform/android/src/geojson/conversion/feature.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "feature.hpp"
-
-#include "../../gson/json_object.hpp"
-
-namespace mbgl {
-namespace android {
-namespace conversion {
-
-using namespace gson;
-
-/**
- * Turn feature identifier into std::string
- */
-class FeatureIdVisitor {
-public:
-
- template<class T>
- std::string operator()(const T& i) const {
- return std::to_string(i);
- }
-
- std::string operator()(const std::string& i) const {
- return i;
- }
-
- std::string operator()(const std::nullptr_t&) const {
- return "";
- }
-
-};
-
-jni::Object<android::geojson::Feature> convertFeature(jni::JNIEnv& env, const mbgl::Feature& value) {
- using namespace mbgl::android::geojson;
-
- return Feature::fromGeometry(env,
- *jni::SeizeLocal(env, Geometry::New(env, value.geometry)),
- *jni::SeizeLocal(env, JsonObject::New(env, value.properties)),
- *jni::SeizeLocal(env, jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")));
-}
-
-Result<jni::Array<jni::Object<android::geojson::Feature>>> Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>>::operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const {
- using namespace mbgl::android::geojson;
-
- auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
-
- for (size_t i = 0; i < value.size(); i = i + 1) {
- features.Set(env, i, *jni::SeizeLocal(env, convertFeature(env, value.at(i))));
- }
-
- return {features};
-}
-
-} // namespace conversion
-} // namespace android
-} // namespace mbgl
diff --git a/platform/android/src/geojson/conversion/feature.hpp b/platform/android/src/geojson/conversion/feature.hpp
deleted file mode 100644
index d9fc0a0b67..0000000000
--- a/platform/android/src/geojson/conversion/feature.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include "../../conversion/conversion.hpp"
-#include "../feature.hpp"
-
-#include <mbgl/util/feature.hpp>
-#include <jni/jni.hpp>
-
-#include <vector>
-
-namespace mbgl {
-namespace android {
-namespace conversion {
-
-template <>
-struct Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>> {
- Result<jni::Array<jni::Object<android::geojson::Feature>>> operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const;
-};
-
-} // namespace conversion
-} // namespace android
-} // namespace mbgl
diff --git a/platform/android/src/geojson/feature.cpp b/platform/android/src/geojson/feature.cpp
index 1e02c756eb..809ac42ef7 100644
--- a/platform/android/src/geojson/feature.cpp
+++ b/platform/android/src/geojson/feature.cpp
@@ -1,50 +1,66 @@
#include "feature.hpp"
-
#include "geometry.hpp"
+#include "../gson/json_object.hpp"
namespace mbgl {
namespace android {
namespace geojson {
+using namespace gson;
+
mbgl::Feature Feature::convert(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- auto jGeometry = jni::SeizeLocal(env, geometry(env, jFeature));
- auto jProperties = jni::SeizeLocal(env, Feature::properties(env, jFeature));
+ static auto javaClass = jni::Class<Feature>::Singleton(env);
+ static auto id = javaClass.GetMethod<jni::String ()>(env, "id");
+ static auto geometry = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
+ static auto properties = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");
- std::experimental::optional<mapbox::geometry::identifier> id;
- auto jId = jni::SeizeLocal(env, Feature::id(env, jFeature));
- if (jId) {
- id = { jni::Make<std::string>(env, *jId) };
- }
+ auto jId = jni::SeizeLocal(env, jFeature.Call(env, id));
return mbgl::Feature {
- Geometry::convert(env, *jGeometry),
- gson::JsonObject::convert(env, *jProperties),
- id
+ Geometry::convert(env, *jni::SeizeLocal(env, jFeature.Call(env, geometry))),
+ JsonObject::convert(env, *jni::SeizeLocal(env, jFeature.Call(env, properties))),
+ jId ? std::experimental::optional<mapbox::geometry::identifier>(jni::Make<std::string>(env, *jId))
+ : std::experimental::nullopt
};
}
-jni::Object<Geometry> Feature::geometry(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
- return jFeature.Call(env, method);
-}
+/**
+ * Turn feature identifier into std::string
+ */
+class FeatureIdVisitor {
+public:
+ template<class T>
+ std::string operator()(const T& i) const {
+ return std::to_string(i);
+ }
-jni::Object<gson::JsonObject> Feature::properties(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");
- return jFeature.Call(env, method);
-}
+ std::string operator()(const std::string& i) const {
+ return i;
+ }
+
+ std::string operator()(const std::nullptr_t&) const {
+ return "";
+ }
+};
-jni::String Feature::id(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
+jni::Object<Feature> convertFeature(jni::JNIEnv& env, const mbgl::Feature& value) {
static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::String ()>(env, "id");
- return jFeature.Call(env, method);
+ static auto method = javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<JsonObject>, jni::String)>(env, "fromGeometry");
+
+ return javaClass.Call(env, method,
+ *jni::SeizeLocal(env, Geometry::New(env, value.geometry)),
+ *jni::SeizeLocal(env, JsonObject::New(env, value.properties)),
+ *jni::SeizeLocal(env, jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")));
}
-jni::Object<Feature> Feature::fromGeometry(jni::JNIEnv& env, jni::Object<Geometry> geometry, jni::Object<gson::JsonObject> properties, jni::String id) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String)>(env, "fromGeometry");
- return javaClass.Call(env, method, geometry, properties, id);
+jni::Array<jni::Object<Feature>> Feature::convert(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) {
+ auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
+
+ for (size_t i = 0; i < value.size(); i = i + 1) {
+ features.Set(env, i, *jni::SeizeLocal(env, convertFeature(env, value.at(i))));
+ }
+
+ return features;
}
void Feature::registerNative(jni::JNIEnv& env) {
diff --git a/platform/android/src/geojson/feature.hpp b/platform/android/src/geojson/feature.hpp
index de38e9b1e3..fba4815e0c 100644
--- a/platform/android/src/geojson/feature.hpp
+++ b/platform/android/src/geojson/feature.hpp
@@ -1,32 +1,19 @@
#pragma once
#include <mbgl/util/feature.hpp>
-#include <mbgl/util/geometry.hpp>
-#include <mbgl/util/noncopyable.hpp>
#include <jni/jni.hpp>
-#include "geometry.hpp"
-#include "../gson/json_object.hpp"
-
namespace mbgl {
namespace android {
namespace geojson {
-class Feature : private mbgl::util::noncopyable {
+class Feature : public jni::ObjectTag {
public:
-
static constexpr auto Name() { return "com/mapbox/geojson/Feature"; };
- static jni::Object<Feature> fromGeometry(jni::JNIEnv&, jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String);
-
static mbgl::Feature convert(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::Object<Geometry> geometry(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::String id(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::Object<gson::JsonObject> properties(jni::JNIEnv&, jni::Object<Feature>);
+ static jni::Array<jni::Object<Feature>> convert(jni::JNIEnv&, const std::vector<mbgl::Feature>&);
static void registerNative(jni::JNIEnv&);
};
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 26814fd6b8..d396e00b47 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -37,7 +37,7 @@
#include "conversion/conversion.hpp"
#include "conversion/collection.hpp"
#include "style/conversion/filter.hpp"
-#include "geojson/conversion/feature.hpp"
+#include "geojson/feature.hpp"
#include "jni.hpp"
#include "attach_env.hpp"
@@ -658,7 +658,7 @@ jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesFo
}
mapbox::geometry::point<double> point = {x, y};
- return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(
+ return Feature::convert(
env,
rendererFrontend->queryRenderedFeatures(point, { layers, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }));
}
@@ -678,7 +678,7 @@ jni::Array<jni::Object<geojson::Feature>> NativeMapView::queryRenderedFeaturesFo
mapbox::geometry::point<double>{ right, bottom }
};
- return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(
+ return Feature::convert(
env,
rendererFrontend->queryRenderedFeatures(box, { layers, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) }));
}
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp
index 029824eae0..9012948b0b 100644
--- a/platform/android/src/style/sources/custom_geometry_source.cpp
+++ b/platform/android/src/style/sources/custom_geometry_source.cpp
@@ -9,7 +9,7 @@
// C++ -> Java conversion
#include "../../conversion/conversion.hpp"
#include "../../conversion/collection.hpp"
-#include "../../geojson/conversion/feature.hpp"
+#include "../../geojson/feature.hpp"
#include <mbgl/style/conversion/custom_geometry_source_options.hpp>
#include <string>
@@ -155,7 +155,7 @@ namespace android {
features = rendererFrontend->querySourceFeatures(source.getID(),
{ {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
}
- return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
+ return Feature::convert(env, features);
}
jni::Object<Source> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) {
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp
index b9f3f73801..943cc48386 100644
--- a/platform/android/src/style/sources/geojson_source.cpp
+++ b/platform/android/src/style/sources/geojson_source.cpp
@@ -12,7 +12,7 @@
// C++ -> Java conversion
#include "../../conversion/conversion.hpp"
#include "../../conversion/collection.hpp"
-#include "../../geojson/conversion/feature.hpp"
+#include "../../geojson/feature.hpp"
#include "../conversion/url_or_tileset.hpp"
#include <string>
@@ -104,7 +104,7 @@ namespace android {
features = rendererFrontend->querySourceFeatures(source.getID(),
{ {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
}
- return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
+ return Feature::convert(env, features);
}
jni::Object<Source> GeoJSONSource::createJavaPeer(jni::JNIEnv& env) {
diff --git a/platform/android/src/style/sources/vector_source.cpp b/platform/android/src/style/sources/vector_source.cpp
index 69052bd98c..48eb4ca51c 100644
--- a/platform/android/src/style/sources/vector_source.cpp
+++ b/platform/android/src/style/sources/vector_source.cpp
@@ -9,7 +9,7 @@
// C++ -> Java conversion
#include "../../conversion/conversion.hpp"
#include "../../conversion/collection.hpp"
-#include "../../geojson/conversion/feature.hpp"
+#include "../../geojson/feature.hpp"
#include "../conversion/url_or_tileset.hpp"
#include <mbgl/util/variant.hpp>
@@ -54,7 +54,7 @@ namespace android {
features = rendererFrontend->querySourceFeatures(source.getID(),
{ toVector(env, jSourceLayerIds), toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
}
- return *convert<jni::Array<jni::Object<Feature>>, std::vector<mbgl::Feature>>(env, features);
+ return Feature::convert(env, features);
}
jni::Object<Source> VectorSource::createJavaPeer(jni::JNIEnv& env) {