summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson/feature_collection.cpp
blob: f90d5226b78da436a04df4b3695c3a3fda6b4cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "feature_collection.hpp"

#include "feature.hpp"

namespace mbgl {
namespace android {
namespace geojson {

mbgl::FeatureCollection FeatureCollection::convert(jni::JNIEnv& env, const jni::Object<FeatureCollection>& jCollection) {
    auto collection = mbgl::FeatureCollection();

    if (jCollection) {
        auto jFeatureList = FeatureCollection::features(env, jCollection);
        auto jFeatures = java::util::List::toArray<Feature>(env, jFeatureList);
        auto size = size_t(jFeatures.Length(env));
        collection.reserve(size);

        for (size_t i = 0; i < size; i++) {
            collection.push_back(Feature::convert(env, jFeatures.Get(env, i)));
        }
    }
    return collection;
}

jni::Local<jni::Object<java::util::List>> FeatureCollection::features(jni::JNIEnv& env, const jni::Object<FeatureCollection>& jCollection) {
    static auto& javaClass = jni::Class<FeatureCollection>::Singleton(env);
    static auto method = javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "features");
    return jCollection.Call(env, method);
}

void FeatureCollection::registerNative(jni::JNIEnv& env) {
    jni::Class<FeatureCollection>::Singleton(env);
}

} // namespace geojson
} // namespace android
} // namespace mbgl