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
|
#include "feature.hpp"
#include "../../gson/json_object.hpp"
namespace mbgl {
namespace android {
namespace conversion {
using namespace gson;
/**
* Turn feature identifier into std::string
*/
class FeatureIdVisitor {
public:
template<class T>
std::string operator()(const T& i) const {
return std::to_string(i);
}
std::string operator()(const std::string& i) const {
return i;
}
std::string operator()(const std::nullptr_t&) const {
return "";
}
};
jni::Object<android::geojson::Feature> convertFeature(jni::JNIEnv& env, const mbgl::Feature& value) {
using namespace mbgl::android::geojson;
return Feature::fromGeometry(env,
*jni::SeizeLocal(env, Geometry::New(env, value.geometry)),
*jni::SeizeLocal(env, JsonObject::New(env, value.properties)),
*jni::SeizeLocal(env, jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")));
}
Result<jni::Array<jni::Object<android::geojson::Feature>>> Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>>::operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const {
using namespace mbgl::android::geojson;
auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
for (size_t i = 0; i < value.size(); i = i + 1) {
features.Set(env, i, *jni::SeizeLocal(env, convertFeature(env, value.at(i))));
}
return {features};
}
} // namespace conversion
} // namespace android
} // namespace mbgl
|