Move JNI bindings code from mapbox-gl-native to this repo. (#301)
This commit is contained in:
23
MapboxGLAndroidSDK/src/cpp/annotation/marker.cpp
Normal file
23
MapboxGLAndroidSDK/src/cpp/annotation/marker.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "marker.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
mbgl::Point<double> Marker::getPosition(jni::JNIEnv& env, const jni::Object<Marker>& marker) {
|
||||
static auto& javaClass = jni::Class<Marker>::Singleton(env);
|
||||
static auto positionField = javaClass.GetField<jni::Object<LatLng>>(env, "position");
|
||||
return LatLng::getGeometry(env, marker.Get(env, positionField));
|
||||
}
|
||||
|
||||
std::string Marker::getIconId(jni::JNIEnv& env, const jni::Object<Marker>& marker) {
|
||||
static auto& javaClass = jni::Class<Marker>::Singleton(env);
|
||||
static auto iconIdField = javaClass.GetField<jni::String>(env, "iconId");
|
||||
return jni::Make<std::string>(env, marker.Get(env, iconIdField));
|
||||
}
|
||||
|
||||
void Marker::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Marker>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
28
MapboxGLAndroidSDK/src/cpp/annotation/marker.hpp
Normal file
28
MapboxGLAndroidSDK/src/cpp/annotation/marker.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../geometry/lat_lng.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Marker : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Marker"; };
|
||||
|
||||
static mbgl::Point<double> getPosition(jni::JNIEnv&, const jni::Object<Marker>&);
|
||||
|
||||
static std::string getIconId(jni::JNIEnv&, const jni::Object<Marker>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
34
MapboxGLAndroidSDK/src/cpp/annotation/multi_point.hpp
Normal file
34
MapboxGLAndroidSDK/src/cpp/annotation/multi_point.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../geometry/lat_lng.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class MultiPoint : protected mbgl::util::noncopyable {
|
||||
|
||||
protected:
|
||||
|
||||
template <class Geometry>
|
||||
static Geometry toGeometry(JNIEnv& env, const jni::Object<java::util::List>& pointsList) {
|
||||
auto jarray = java::util::List::toArray<LatLng>(env, pointsList);
|
||||
|
||||
std::size_t size = jarray.Length(env);
|
||||
|
||||
Geometry geometry;
|
||||
geometry.reserve(size);
|
||||
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
geometry.push_back(LatLng::getGeometry(env, jarray.Get(env, i)));
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
40
MapboxGLAndroidSDK/src/cpp/annotation/polygon.cpp
Normal file
40
MapboxGLAndroidSDK/src/cpp/annotation/polygon.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "polygon.hpp"
|
||||
|
||||
#include "../conversion/color.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
mbgl::FillAnnotation Polygon::toAnnotation(jni::JNIEnv& env, const jni::Object<Polygon>& polygon) {
|
||||
static auto& javaClass = jni::Class<Polygon>::Singleton(env);
|
||||
static auto points = javaClass.GetField<jni::Object<java::util::List>>(env, "points");
|
||||
static auto holes = javaClass.GetField<jni::Object<java::util::List>>(env, "holes");
|
||||
static auto alpha = javaClass.GetField<float>(env, "alpha");
|
||||
static auto fillColor = javaClass.GetField<int>(env, "fillColor");
|
||||
static auto strokeColor = javaClass.GetField<int>(env, "strokeColor");
|
||||
|
||||
mbgl::Polygon<double> geometry {
|
||||
MultiPoint::toGeometry<mbgl::LinearRing<double>>(env, polygon.Get(env, points))
|
||||
};
|
||||
|
||||
auto jHoleListsArray = java::util::List::toArray<java::util::List>(env, polygon.Get(env, holes));
|
||||
|
||||
std::size_t jHoleListsSize = jHoleListsArray.Length(env);
|
||||
for (std::size_t i = 0; i < jHoleListsSize; i++) {
|
||||
geometry.push_back(MultiPoint::toGeometry<mbgl::LinearRing<double>>(env, jHoleListsArray.Get(env, i)));
|
||||
}
|
||||
|
||||
mbgl::FillAnnotation annotation { geometry };
|
||||
annotation.opacity = polygon.Get(env, alpha);
|
||||
annotation.color = *conversion::convert<mbgl::Color>(env, polygon.Get(env, fillColor));
|
||||
annotation.outlineColor = *conversion::convert<mbgl::Color>(env, polygon.Get(env, strokeColor));
|
||||
|
||||
return annotation;
|
||||
}
|
||||
|
||||
void Polygon::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Polygon>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
21
MapboxGLAndroidSDK/src/cpp/annotation/polygon.hpp
Normal file
21
MapboxGLAndroidSDK/src/cpp/annotation/polygon.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/annotation/annotation.hpp>
|
||||
|
||||
#include "multi_point.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Polygon : private MultiPoint {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Polygon"; };
|
||||
|
||||
static mbgl::FillAnnotation toAnnotation(jni::JNIEnv&, const jni::Object<Polygon>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
31
MapboxGLAndroidSDK/src/cpp/annotation/polyline.cpp
Normal file
31
MapboxGLAndroidSDK/src/cpp/annotation/polyline.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "polyline.hpp"
|
||||
|
||||
#include "../conversion/color.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
mbgl::LineAnnotation Polyline::toAnnotation(jni::JNIEnv& env, const jni::Object<Polyline>& polyline) {
|
||||
static auto& javaClass = jni::Class<Polyline>::Singleton(env);
|
||||
static auto points = javaClass.GetField<jni::Object<java::util::List>>(env, "points");
|
||||
static auto alpha = javaClass.GetField<float>(env, "alpha");
|
||||
static auto color = javaClass.GetField<int>(env, "color");
|
||||
static auto width = javaClass.GetField<float>(env, "width");
|
||||
|
||||
mbgl::LineAnnotation annotation {
|
||||
MultiPoint::toGeometry<mbgl::LineString<double>>(env, polyline.Get(env, points))
|
||||
};
|
||||
|
||||
annotation.opacity = polyline.Get(env, alpha);
|
||||
annotation.color = *conversion::convert<mbgl::Color>(env, polyline.Get(env, color));
|
||||
annotation.width = polyline.Get(env, width);
|
||||
|
||||
return annotation;
|
||||
}
|
||||
|
||||
void Polyline::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Polyline>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
21
MapboxGLAndroidSDK/src/cpp/annotation/polyline.hpp
Normal file
21
MapboxGLAndroidSDK/src/cpp/annotation/polyline.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/annotation/annotation.hpp>
|
||||
|
||||
#include "multi_point.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Polyline : private MultiPoint {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/annotations/Polyline"; };
|
||||
|
||||
static mbgl::LineAnnotation toAnnotation(jni::JNIEnv&, const jni::Object<Polyline>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user