From fa7489fb7ea8ec85cb746e0bc497518d72c638b9 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Wed, 22 Mar 2017 15:05:03 +0200 Subject: [android] geojson conversion optimisation --- platform/android/src/geojson/feature.cpp | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 platform/android/src/geojson/feature.cpp (limited to 'platform/android/src/geojson/feature.cpp') diff --git a/platform/android/src/geojson/feature.cpp b/platform/android/src/geojson/feature.cpp new file mode 100644 index 0000000000..a6b387cd15 --- /dev/null +++ b/platform/android/src/geojson/feature.cpp @@ -0,0 +1,63 @@ +#include "feature.hpp" + +#include "geometry.hpp" + +namespace mbgl { +namespace android { +namespace geojson { + +mbgl::Feature Feature::convert(jni::JNIEnv& env, jni::Object jFeature) { + // Convert + auto jGeometry = getGeometry(env, jFeature); + auto jProperties = Feature::getProperties(env, jFeature); + + std::experimental::optional id; + auto jId = Feature::getId(env, jFeature); + if (jId) { + id = { jni::Make(env, jId) }; + } + + auto feature = mbgl::Feature { + Geometry::convert(env, jGeometry), + gson::JsonObject::convert(env, jProperties), + id + }; + + // Cleanup + jni::DeleteLocalRef(env, jGeometry); + jni::DeleteLocalRef(env, jProperties); + jni::DeleteLocalRef(env, jId); + + return feature; +} + +jni::Object Feature::getGeometry(jni::JNIEnv& env, jni::Object jFeature) { + static auto method = Feature::javaClass.GetMethod ()>(env, "getGeometry"); + return jFeature.Call(env, method); +} + +jni::Object Feature::getProperties(jni::JNIEnv& env, jni::Object jFeature) { + static auto method = Feature::javaClass.GetMethod ()>(env, "getProperties"); + return jFeature.Call(env, method); +} + +jni::String Feature::getId(jni::JNIEnv& env, jni::Object jFeature) { + static auto method = Feature::javaClass.GetMethod(env, "getId"); + return jFeature.Call(env, method); +} + +jni::Object Feature::fromGeometry(jni::JNIEnv& env, jni::Object geometry, jni::Object properties, jni::String id) { + static auto method = Feature::javaClass.GetStaticMethod (jni::Object, jni::Object, jni::String)>(env, "fromGeometry"); + return Feature::javaClass.Call(env, method, geometry, properties, id); +} + +void Feature::registerNative(jni::JNIEnv& env) { + // Lookup the class + Feature::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); +} + +jni::Class Feature::javaClass; + +} // namespace geojson +} // namespace android +} // namespace mbgl \ No newline at end of file -- cgit v1.2.1