summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson/geometry.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-03-22 15:05:03 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-28 15:44:22 +0300
commitfa7489fb7ea8ec85cb746e0bc497518d72c638b9 (patch)
tree477c100890466ca0093af9e101554dca530f9ae8 /platform/android/src/geojson/geometry.cpp
parentf70f604e5b99062a24764716ccdeda64c36320be (diff)
downloadqtlocation-mapboxgl-fa7489fb7ea8ec85cb746e0bc497518d72c638b9.tar.gz
[android] geojson conversion optimisation
Diffstat (limited to 'platform/android/src/geojson/geometry.cpp')
-rw-r--r--platform/android/src/geojson/geometry.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/platform/android/src/geojson/geometry.cpp b/platform/android/src/geojson/geometry.cpp
new file mode 100644
index 0000000000..33bb4ee3db
--- /dev/null
+++ b/platform/android/src/geojson/geometry.cpp
@@ -0,0 +1,52 @@
+#include "geometry.hpp"
+
+#include "point.hpp"
+#include "multi_point.hpp"
+#include "line_string.hpp"
+#include "multi_line_string.hpp"
+#include "polygon.hpp"
+#include "multi_polygon.hpp"
+
+#include <string>
+
+namespace mbgl {
+namespace android {
+namespace geojson {
+
+mapbox::geojson::geometry Geometry::convert(jni::JNIEnv &env, jni::Object<Geometry> jGeometry) {
+ auto type = Geometry::getType(env, jGeometry);
+ if (type == Point::Type()) {
+ return { Point::convert(env, jni::Object<Point>(jGeometry.Get())) };
+ } else if (type == MultiPoint::Type()) {
+ return { MultiPoint::convert(env, jni::Object<MultiPoint>(jGeometry.Get())) };
+ } else if (type == LineString::Type()) {
+ return { LineString::convert(env, jni::Object<LineString>(jGeometry.Get())) };
+ } else if (type == MultiLineString::Type()) {
+ return { MultiLineString::convert(env, jni::Object<MultiLineString>(jGeometry.Get())) };
+ } else if (type == Polygon::Type()) {
+ return { Polygon::convert(env, jni::Object<Polygon>(jGeometry.Get())) };
+ } else if (type == MultiPolygon::Type()) {
+ return { MultiPolygon::convert(env, jni::Object<MultiPolygon>(jGeometry.Get())) };
+ }
+
+ throw std::runtime_error(std::string {"Unsupported GeoJSON type: " } + type);
+}
+
+std::string Geometry::getType(jni::JNIEnv &env, jni::Object<Geometry> jGeometry) {
+ static auto method = Geometry::javaClass.GetMethod<jni::String ()>(env, "getType");
+ auto jType = jGeometry.Call(env, method);
+ auto type = jni::Make<std::string>(env, jType);
+ jni::DeleteLocalRef(env, jType);
+ return type;
+}
+
+void Geometry::registerNative(jni::JNIEnv &env) {
+ // Lookup the class
+ javaClass = *jni::Class<Geometry>::Find(env).NewGlobalRef(env).release();
+}
+
+jni::Class<Geometry> Geometry::javaClass;
+
+} // namespace geojson
+} // namespace android
+} // namespace mbgl \ No newline at end of file