diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-03-22 15:05:03 +0200 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-03-28 15:44:22 +0300 |
commit | fa7489fb7ea8ec85cb746e0bc497518d72c638b9 (patch) | |
tree | 477c100890466ca0093af9e101554dca530f9ae8 /platform/android/src/geojson/feature.cpp | |
parent | f70f604e5b99062a24764716ccdeda64c36320be (diff) | |
download | qtlocation-mapboxgl-fa7489fb7ea8ec85cb746e0bc497518d72c638b9.tar.gz |
[android] geojson conversion optimisation
Diffstat (limited to 'platform/android/src/geojson/feature.cpp')
-rw-r--r-- | platform/android/src/geojson/feature.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
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<Feature> jFeature) { + // Convert + auto jGeometry = getGeometry(env, jFeature); + auto jProperties = Feature::getProperties(env, jFeature); + + std::experimental::optional<mapbox::geometry::identifier> id; + auto jId = Feature::getId(env, jFeature); + if (jId) { + id = { jni::Make<std::string>(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<Geometry> Feature::getGeometry(jni::JNIEnv& env, jni::Object<Feature> jFeature) { + static auto method = Feature::javaClass.GetMethod<jni::Object<Geometry> ()>(env, "getGeometry"); + return jFeature.Call(env, method); +} + +jni::Object<gson::JsonObject> Feature::getProperties(jni::JNIEnv& env, jni::Object<Feature> jFeature) { + static auto method = Feature::javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "getProperties"); + return jFeature.Call(env, method); +} + +jni::String Feature::getId(jni::JNIEnv& env, jni::Object<Feature> jFeature) { + static auto method = Feature::javaClass.GetMethod<jni::String ()>(env, "getId"); + return jFeature.Call(env, method); +} + +jni::Object<Feature> Feature::fromGeometry(jni::JNIEnv& env, jni::Object<Geometry> geometry, jni::Object<gson::JsonObject> properties, jni::String id) { + static auto method = Feature::javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<gson::JsonObject>, 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<Feature>::Find(env).NewGlobalRef(env).release(); +} + +jni::Class<Feature> Feature::javaClass; + +} // namespace geojson +} // namespace android +} // namespace mbgl
\ No newline at end of file |