summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson/feature.cpp
blob: 1e02c756eb3b6e00da4c8181fcaf87047328a5a8 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "feature.hpp"

#include "geometry.hpp"

namespace mbgl {
namespace android {
namespace geojson {

mbgl::Feature Feature::convert(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
    auto jGeometry = jni::SeizeLocal(env, geometry(env, jFeature));
    auto jProperties = jni::SeizeLocal(env, Feature::properties(env, jFeature));

    std::experimental::optional<mapbox::geometry::identifier> id;
    auto jId = jni::SeizeLocal(env, Feature::id(env, jFeature));
    if (jId) {
        id = {  jni::Make<std::string>(env, *jId) };
    }

    return mbgl::Feature {
        Geometry::convert(env, *jGeometry),
        gson::JsonObject::convert(env, *jProperties),
        id
    };
}

jni::Object<Geometry> Feature::geometry(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
    static auto javaClass = jni::Class<Feature>::Singleton(env);
    static auto method = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
    return jFeature.Call(env, method);
}

jni::Object<gson::JsonObject> Feature::properties(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
    static auto javaClass = jni::Class<Feature>::Singleton(env);
    static auto method = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");
    return jFeature.Call(env, method);
}

jni::String Feature::id(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
    static auto javaClass = jni::Class<Feature>::Singleton(env);
    static auto method = javaClass.GetMethod<jni::String ()>(env, "id");
    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 javaClass = jni::Class<Feature>::Singleton(env);
    static auto method = javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String)>(env, "fromGeometry");
    return javaClass.Call(env, method, geometry, properties, id);
}

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

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