summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson/feature_collection.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-03-22 15:05:03 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-28 15:44:22 +0300
commitfa7489fb7ea8ec85cb746e0bc497518d72c638b9 (patch)
tree477c100890466ca0093af9e101554dca530f9ae8 /platform/android/src/geojson/feature_collection.cpp
parentf70f604e5b99062a24764716ccdeda64c36320be (diff)
downloadqtlocation-mapboxgl-fa7489fb7ea8ec85cb746e0bc497518d72c638b9.tar.gz
[android] geojson conversion optimisation
Diffstat (limited to 'platform/android/src/geojson/feature_collection.cpp')
-rw-r--r--platform/android/src/geojson/feature_collection.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/platform/android/src/geojson/feature_collection.cpp b/platform/android/src/geojson/feature_collection.cpp
new file mode 100644
index 0000000000..2f156532ae
--- /dev/null
+++ b/platform/android/src/geojson/feature_collection.cpp
@@ -0,0 +1,40 @@
+#include "feature_collection.hpp"
+
+#include "feature.hpp"
+
+namespace mbgl {
+namespace android {
+namespace geojson {
+
+mbgl::FeatureCollection FeatureCollection::convert(jni::JNIEnv& env, jni::Object<FeatureCollection> jCollection) {
+ auto jFeatureList = FeatureCollection::getFeatures(env, jCollection);
+ auto jFeatures = java::util::List::toArray<Feature>(env, jFeatureList);
+ auto size = size_t(jFeatures.Length(env));
+
+ auto collection = mbgl::FeatureCollection();
+ collection.reserve(size);
+
+ for (size_t i = 0; i < size; i++) {
+ auto jFeature = jFeatures.Get(env, i);
+ collection.push_back(Feature::convert(env, jFeature));
+ jni::DeleteLocalRef(env, jFeature);
+ }
+
+ return collection;
+}
+
+jni::Object<java::util::List> FeatureCollection::getFeatures(jni::JNIEnv& env, jni::Object<FeatureCollection> jCollection) {
+ static auto method = FeatureCollection::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "getFeatures");
+ return jCollection.Call(env, method);
+}
+
+void FeatureCollection::registerNative(jni::JNIEnv& env) {
+ // Lookup the class
+ javaClass = *jni::Class<FeatureCollection>::Find(env).NewGlobalRef(env).release();
+}
+
+jni::Class<FeatureCollection> FeatureCollection::javaClass;
+
+} // namespace geojson
+} // namespace android
+} // namespace mbgl \ No newline at end of file