blob: 8eebd5355037bf52d709d04ade49434563b2ed05 (
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
|
#include "line_string.hpp"
#include "point.hpp"
namespace mbgl {
namespace android {
namespace geojson {
mapbox::geojson::line_string LineString::convert(jni::JNIEnv &env, jni::Object<LineString> jLineString) {
mapbox::geojson::line_string lineString;
if (jLineString) {
auto jPointList = LineString::coordinates(env, jLineString);
lineString = LineString::convert(env, jPointList);
jni::DeleteLocalRef(env, jPointList);
}
return lineString;
}
mapbox::geojson::line_string LineString::convert(jni::JNIEnv &env, jni::Object<java::util::List/*<Point>*/> jPointList) {
mapbox::geojson::line_string lineString;
if (jPointList) {
auto jPointArray = java::util::List::toArray<Point>(env, jPointList);
auto size = jPointArray.Length(env);
lineString.reserve(size);
for (std::size_t i = 0; i < size; i++) {
auto jPoint = jPointArray.Get(env, i);
lineString.push_back(Point::convert(env, jPoint));
jni::DeleteLocalRef(env, jPoint);
}
jni::DeleteLocalRef(env, jPointArray);
}
return lineString;
}
jni::Object<java::util::List> LineString::coordinates(jni::JNIEnv &env, jni::Object<LineString> jLineString) {
static auto method = LineString::javaClass.GetMethod<jni::Object<java::util::List> ()>(env, "coordinates");
return jLineString.Call(env, method);
}
void LineString::registerNative(jni::JNIEnv &env) {
// Lookup the class
javaClass = *jni::Class<LineString>::Find(env).NewGlobalRef(env).release();
}
jni::Class<LineString> LineString::javaClass;
} // namespace geojson
} // namespace android
} // namespace mbgl
|