#include "geometry_collection.hpp" #include "../java/util.hpp" namespace mbgl { namespace android { namespace geojson { jni::Local> GeometryCollection::New(jni::JNIEnv& env, const mapbox::geometry::geometry_collection& collection) { // Create an array of geometries auto jarray = jni::Array>::New(env, collection.size()); for (size_t i = 0; i < collection.size(); i++) { jarray.Set(env, i, Geometry::New(env, collection.at(i))); } // create the GeometryCollection static auto& javaClass = jni::Class::Singleton(env); static auto method = javaClass.GetStaticMethod (jni::Object)>(env, "fromGeometries"); return javaClass.Call(env, method, java::util::Arrays::asList(env, jarray)); } mapbox::geometry::geometry_collection GeometryCollection::convert(jni::JNIEnv &env, const jni::Object& jCollection) { // Get geometries static auto& javaClass = jni::Class::Singleton(env); static auto getGeometries = javaClass.GetMethod ()>(env, "geometries"); // Turn into array auto jarray = java::util::List::toArray(env, jCollection.Call(env, getGeometries)); // Convert each geometry mapbox::geometry::geometry_collection collection{}; auto size = jarray.Length(env); for (jni::jsize i = 0; i < size; i++) { collection.push_back(Geometry::convert(env, jarray.Get(env, i))); } return collection; } void GeometryCollection::registerNative(jni::JNIEnv &env) { jni::Class::Singleton(env); } } // namespace geojson } // namespace android } // namespace mbgl