Rename Gradle targets Android (#2226)
This commit is contained in:
88
platform/android/MapLibreAndroid/src/cpp/geojson/feature.cpp
Normal file
88
platform/android/MapLibreAndroid/src/cpp/geojson/feature.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "feature.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "../gson/json_object.hpp"
|
||||
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
using namespace gson;
|
||||
|
||||
mbgl::GeoJSONFeature Feature::convert(jni::JNIEnv& env, const jni::Object<Feature>& jFeature) {
|
||||
static auto& javaClass = jni::Class<Feature>::Singleton(env);
|
||||
static auto id = javaClass.GetMethod<jni::String()>(env, "id");
|
||||
static auto geometry = javaClass.GetMethod<jni::Object<Geometry>()>(env, "geometry");
|
||||
static auto properties = javaClass.GetMethod<jni::Object<gson::JsonObject>()>(env, "properties");
|
||||
|
||||
auto jId = jFeature.Call(env, id);
|
||||
|
||||
using mbid = mapbox::feature::identifier;
|
||||
|
||||
return mbgl::GeoJSONFeature{Geometry::convert(env, jFeature.Call(env, geometry)),
|
||||
JsonObject::convert(env, jFeature.Call(env, properties)),
|
||||
jId ? mbid{jni::Make<std::string>(env, jId)} : mbid{mapbox::feature::null_value}};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn feature identifier into std::string
|
||||
*/
|
||||
class FeatureIdVisitor {
|
||||
public:
|
||||
template <class T>
|
||||
std::string operator()(const T& i) const {
|
||||
return util::toString(i);
|
||||
}
|
||||
|
||||
std::string operator()(const std::string& i) const { return i; }
|
||||
|
||||
std::string operator()(const std::nullptr_t&) const { return {}; }
|
||||
|
||||
std::string operator()(const mapbox::feature::null_value_t&) const { return {}; }
|
||||
};
|
||||
|
||||
jni::Local<jni::Object<Feature>> convertFeature(jni::JNIEnv& env, const mbgl::GeoJSONFeature& value) {
|
||||
static auto& javaClass = jni::Class<Feature>::Singleton(env);
|
||||
static auto method =
|
||||
javaClass.GetStaticMethod<jni::Object<Feature>(jni::Object<Geometry>, jni::Object<JsonObject>, jni::String)>(
|
||||
env, "fromGeometry");
|
||||
|
||||
return javaClass.Call(
|
||||
env,
|
||||
method,
|
||||
Geometry::New(env, value.geometry),
|
||||
JsonObject::New(env, value.properties),
|
||||
jni::Make<jni::String>(env,
|
||||
value.id.is<mbgl::NullValue>() ? std::string{} : value.id.match(FeatureIdVisitor())));
|
||||
}
|
||||
|
||||
jni::Local<jni::Array<jni::Object<Feature>>> Feature::convert(jni::JNIEnv& env,
|
||||
const std::vector<mbgl::Feature>& value) {
|
||||
auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
|
||||
|
||||
for (size_t i = 0; i < value.size(); ++i) {
|
||||
features.Set(env, i, convertFeature(env, static_cast<mbgl::GeoJSONFeature>(value.at(i))));
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
jni::Local<jni::Array<jni::Object<Feature>>> Feature::convert(jni::JNIEnv& env,
|
||||
const std::vector<mbgl::GeoJSONFeature>& value) {
|
||||
auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
|
||||
|
||||
for (size_t i = 0; i < value.size(); ++i) {
|
||||
features.Set(env, i, convertFeature(env, value.at(i)));
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
void Feature::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Feature>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
24
platform/android/MapLibreAndroid/src/cpp/geojson/feature.hpp
Normal file
24
platform/android/MapLibreAndroid/src/cpp/geojson/feature.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/feature.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Feature {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/Feature"; };
|
||||
|
||||
static mbgl::GeoJSONFeature convert(jni::JNIEnv&, const jni::Object<Feature>&);
|
||||
static jni::Local<jni::Array<jni::Object<Feature>>> convert(jni::JNIEnv&, const std::vector<mbgl::Feature>&);
|
||||
static jni::Local<jni::Array<jni::Object<Feature>>> convert(jni::JNIEnv&, const std::vector<mbgl::GeoJSONFeature>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "feature_collection.hpp"
|
||||
|
||||
#include "feature.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
mbgl::FeatureCollection FeatureCollection::convert(jni::JNIEnv& env,
|
||||
const jni::Object<FeatureCollection>& jCollection) {
|
||||
auto collection = mbgl::FeatureCollection();
|
||||
|
||||
if (jCollection) {
|
||||
auto jFeatureList = FeatureCollection::features(env, jCollection);
|
||||
auto jFeatures = java::util::List::toArray<Feature>(env, jFeatureList);
|
||||
auto size = size_t(jFeatures.Length(env));
|
||||
collection.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
collection.push_back(Feature::convert(env, jFeatures.Get(env, i)));
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> FeatureCollection::features(
|
||||
jni::JNIEnv& env, const jni::Object<FeatureCollection>& jCollection) {
|
||||
static auto& javaClass = jni::Class<FeatureCollection>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "features");
|
||||
return jCollection.Call(env, method);
|
||||
}
|
||||
|
||||
void FeatureCollection::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<FeatureCollection>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class FeatureCollection {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/FeatureCollection"; };
|
||||
|
||||
static mbgl::FeatureCollection convert(jni::JNIEnv&, const jni::Object<FeatureCollection>&);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> features(jni::JNIEnv&, const jni::Object<FeatureCollection>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,97 @@
|
||||
#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 "geometry_collection.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
/**
|
||||
* Turn mapbox::geometry type into Java GeoJson Geometries
|
||||
*/
|
||||
class GeometryEvaluator {
|
||||
public:
|
||||
jni::JNIEnv &env;
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::EmptyGeometry &) const {
|
||||
// FIXME: mapbox-java needs to have its own Empty type.
|
||||
return GeometryCollection::New(env, {});
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::Point<double> &geometry) const {
|
||||
return Point::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::LineString<double> &geometry) const {
|
||||
return LineString::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::MultiLineString<double> &geometry) const {
|
||||
return MultiLineString::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::MultiPoint<double> &geometry) const {
|
||||
return MultiPoint::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::Polygon<double> &geometry) const {
|
||||
return Polygon::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mbgl::MultiPolygon<double> &geometry) const {
|
||||
return MultiPolygon::New(env, geometry);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<Geometry>> operator()(const mapbox::geometry::geometry_collection<double> &geometry) const {
|
||||
return GeometryCollection::New(env, geometry);
|
||||
}
|
||||
};
|
||||
|
||||
jni::Local<jni::Object<Geometry>> Geometry::New(jni::JNIEnv &env, mbgl::Geometry<double> geometry) {
|
||||
GeometryEvaluator evaluator{env};
|
||||
return mbgl::Geometry<double>::visit(geometry, evaluator);
|
||||
}
|
||||
|
||||
mbgl::Geometry<double> Geometry::convert(jni::JNIEnv &env, const jni::Object<Geometry> &jGeometry) {
|
||||
auto type = Geometry::getType(env, jGeometry);
|
||||
if (type == Point::Type()) {
|
||||
return {Point::convert(env, jni::Cast(env, jni::Class<Point>::Singleton(env), jGeometry))};
|
||||
} else if (type == MultiPoint::Type()) {
|
||||
return {MultiPoint::convert(env, jni::Cast(env, jni::Class<MultiPoint>::Singleton(env), jGeometry))};
|
||||
} else if (type == LineString::Type()) {
|
||||
return {LineString::convert(env, jni::Cast(env, jni::Class<LineString>::Singleton(env), jGeometry))};
|
||||
} else if (type == MultiLineString::Type()) {
|
||||
return {MultiLineString::convert(env, jni::Cast(env, jni::Class<MultiLineString>::Singleton(env), jGeometry))};
|
||||
} else if (type == Polygon::Type()) {
|
||||
return {Polygon::convert(env, jni::Cast(env, jni::Class<Polygon>::Singleton(env), jGeometry))};
|
||||
} else if (type == MultiPolygon::Type()) {
|
||||
return {MultiPolygon::convert(env, jni::Cast(env, jni::Class<MultiPolygon>::Singleton(env), jGeometry))};
|
||||
} else if (type == GeometryCollection::Type()) {
|
||||
return {GeometryCollection::convert(env,
|
||||
jni::Cast(env, jni::Class<GeometryCollection>::Singleton(env), jGeometry))};
|
||||
}
|
||||
|
||||
throw std::runtime_error(std::string{"Unsupported GeoJSON type: "} + type);
|
||||
}
|
||||
|
||||
std::string Geometry::getType(jni::JNIEnv &env, const jni::Object<Geometry> &jGeometry) {
|
||||
static auto &javaClass = jni::Class<Geometry>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::String()>(env, "type");
|
||||
return jni::Make<std::string>(env, jGeometry.Call(env, method));
|
||||
}
|
||||
|
||||
void Geometry::registerNative(jni::JNIEnv &env) {
|
||||
jni::Class<Geometry>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Geometry {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/Geometry"; };
|
||||
|
||||
static jni::Local<jni::Object<Geometry>> New(jni::JNIEnv&, mbgl::Geometry<double>);
|
||||
|
||||
static mbgl::Geometry<double> convert(jni::JNIEnv&, const jni::Object<Geometry>&);
|
||||
|
||||
static std::string getType(jni::JNIEnv&, const jni::Object<Geometry>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "geometry_collection.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<GeometryCollection>> GeometryCollection::New(
|
||||
jni::JNIEnv& env, const mapbox::geometry::geometry_collection<double>& collection) {
|
||||
// Create an array of geometries
|
||||
auto jarray = jni::Array<jni::Object<Geometry>>::New(env, collection.size());
|
||||
|
||||
for (size_t i = 0; i < collection.size(); i++) {
|
||||
jarray.Set(env, i, Geometry::New(env, collection.at(i)));
|
||||
}
|
||||
|
||||
// create the GeometryCollection
|
||||
static auto& javaClass = jni::Class<GeometryCollection>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<GeometryCollection>(jni::Object<java::util::List>)>(
|
||||
env, "fromGeometries");
|
||||
return javaClass.Call(env, method, java::util::Arrays::asList(env, jarray));
|
||||
}
|
||||
|
||||
mapbox::geometry::geometry_collection<double> GeometryCollection::convert(
|
||||
jni::JNIEnv& env, const jni::Object<GeometryCollection>& jCollection) {
|
||||
// Get geometries
|
||||
static auto& javaClass = jni::Class<GeometryCollection>::Singleton(env);
|
||||
static auto getGeometries = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "geometries");
|
||||
|
||||
// Turn into array
|
||||
auto jarray = java::util::List::toArray<Geometry>(env, jCollection.Call(env, getGeometries));
|
||||
|
||||
// Convert each geometry
|
||||
mapbox::geometry::geometry_collection<double> collection{};
|
||||
|
||||
auto size = jarray.Length(env);
|
||||
for (jni::jsize i = 0; i < size; i++) {
|
||||
collection.push_back(Geometry::convert(env, jarray.Get(env, i)));
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
void GeometryCollection::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<GeometryCollection>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "geometry.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class GeometryCollection {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/GeometryCollection"; };
|
||||
static constexpr auto Type() { return "GeometryCollection"; };
|
||||
|
||||
static jni::Local<jni::Object<GeometryCollection>> New(jni::JNIEnv&,
|
||||
const mapbox::geometry::geometry_collection<double>&);
|
||||
|
||||
static mapbox::geometry::geometry_collection<double> convert(jni::JNIEnv&, const jni::Object<GeometryCollection>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "line_string.hpp"
|
||||
#include "point.hpp"
|
||||
#include "util.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<LineString>> LineString::New(jni::JNIEnv& env, const mbgl::LineString<double>& lineString) {
|
||||
static auto& javaClass = jni::Class<LineString>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<LineString>(jni::Object<java::util::List>)>(
|
||||
env, "fromLngLats");
|
||||
|
||||
return javaClass.Call(env, method, asPointsList(env, lineString));
|
||||
}
|
||||
|
||||
mapbox::geojson::line_string LineString::convert(jni::JNIEnv& env, const jni::Object<LineString>& jLineString) {
|
||||
mapbox::geojson::line_string lineString;
|
||||
|
||||
if (jLineString) {
|
||||
lineString = LineString::convert(env, LineString::coordinates(env, jLineString));
|
||||
}
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
mapbox::geojson::line_string LineString::convert(jni::JNIEnv& env,
|
||||
const 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++) {
|
||||
lineString.push_back(Point::convert(env, jPointArray.Get(env, i)));
|
||||
}
|
||||
}
|
||||
|
||||
return lineString;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> LineString::coordinates(jni::JNIEnv& env,
|
||||
const jni::Object<LineString>& jLineString) {
|
||||
static auto& javaClass = jni::Class<LineString>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "coordinates");
|
||||
return jLineString.Call(env, method);
|
||||
}
|
||||
|
||||
void LineString::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<LineString>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "geometry.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class LineString {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/LineString"; };
|
||||
static constexpr auto Type() { return "LineString"; };
|
||||
|
||||
static jni::Local<jni::Object<LineString>> New(jni::JNIEnv&, const mbgl::LineString<double>&);
|
||||
|
||||
static mapbox::geojson::line_string convert(jni::JNIEnv&, const jni::Object<LineString>&);
|
||||
|
||||
static mapbox::geojson::line_string convert(jni::JNIEnv&, const jni::Object<java::util::List /*<Point>*/>&);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> coordinates(jni::JNIEnv&, const jni::Object<LineString>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "multi_line_string.hpp"
|
||||
|
||||
#include "line_string.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<MultiLineString>> MultiLineString::New(jni::JNIEnv& env,
|
||||
const mbgl::MultiLineString<double>& multiLineString) {
|
||||
static auto& javaClass = jni::Class<MultiLineString>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<MultiLineString>(jni::Object<java::util::List>)>(
|
||||
env, "fromLngLats");
|
||||
|
||||
return javaClass.Call(env, method, asPointsListsList(env, multiLineString));
|
||||
}
|
||||
|
||||
mapbox::geojson::multi_line_string MultiLineString::convert(jni::JNIEnv& env,
|
||||
const jni::Object<MultiLineString>& jMultiLineString) {
|
||||
mapbox::geojson::multi_line_string multiLineString;
|
||||
|
||||
if (jMultiLineString) {
|
||||
multiLineString = MultiLineString::convert(env, MultiLineString::coordinates(env, jMultiLineString));
|
||||
}
|
||||
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
mapbox::geojson::multi_line_string MultiLineString::convert(
|
||||
jni::JNIEnv& env, const jni::Object<java::util::List /*<java::util::List<Point>>*/>& jPointListsList) {
|
||||
mapbox::geojson::multi_line_string multiLineString;
|
||||
|
||||
if (jPointListsList) {
|
||||
auto jPositionListsArray = java::util::List::toArray<java::util::List>(env, jPointListsList);
|
||||
|
||||
auto size = jPositionListsArray.Length(env);
|
||||
multiLineString.reserve(size);
|
||||
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
multiLineString.push_back(LineString::convert(env, jPositionListsArray.Get(env, i)));
|
||||
}
|
||||
}
|
||||
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> MultiLineString::coordinates(
|
||||
jni::JNIEnv& env, const jni::Object<MultiLineString>& jLineString) {
|
||||
static auto& javaClass = jni::Class<MultiLineString>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "coordinates");
|
||||
return jLineString.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiLineString::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<MultiLineString>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
#include "geometry.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiLineString {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/MultiLineString"; };
|
||||
static constexpr auto Type() { return "MultiLineString"; };
|
||||
|
||||
static jni::Local<jni::Object<MultiLineString>> New(jni::JNIEnv&, const mbgl::MultiLineString<double>&);
|
||||
|
||||
static mapbox::geojson::multi_line_string convert(jni::JNIEnv&, const jni::Object<MultiLineString>&);
|
||||
|
||||
static mapbox::geojson::multi_line_string convert(
|
||||
jni::JNIEnv&, const jni::Object<java::util::List /*<java::util::List<Point>>*/>&);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> coordinates(jni::JNIEnv&, const jni::Object<MultiLineString>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "multi_point.hpp"
|
||||
|
||||
#include "line_string.hpp"
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<MultiPoint>> MultiPoint::New(JNIEnv& env, const mbgl::MultiPoint<double>& multiPoint) {
|
||||
static auto& javaClass = jni::Class<MultiPoint>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<MultiPoint>(jni::Object<java::util::List>)>(
|
||||
env, "fromLngLats");
|
||||
|
||||
return javaClass.Call(env, method, asPointsList(env, multiPoint));
|
||||
}
|
||||
|
||||
mapbox::geojson::multi_point MultiPoint::convert(jni::JNIEnv& env, const jni::Object<MultiPoint>& jMultiPoint) {
|
||||
mapbox::geojson::multi_point multiPoint;
|
||||
|
||||
if (jMultiPoint) {
|
||||
multiPoint = convertExplicit<mapbox::geojson::multi_point>(
|
||||
LineString::convert(env, MultiPoint::coordinates(env, jMultiPoint)));
|
||||
}
|
||||
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> MultiPoint::coordinates(jni::JNIEnv& env,
|
||||
const jni::Object<MultiPoint>& jMultiPoint) {
|
||||
static auto& javaClass = jni::Class<MultiPoint>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "coordinates");
|
||||
return jMultiPoint.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiPoint::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<MultiPoint>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "geometry.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiPoint {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/MultiPoint"; };
|
||||
static constexpr auto Type() { return "MultiPoint"; };
|
||||
|
||||
static jni::Local<jni::Object<MultiPoint>> New(jni::JNIEnv&, const mbgl::MultiPoint<double>&);
|
||||
|
||||
static mapbox::geojson::multi_point convert(jni::JNIEnv&, const jni::Object<MultiPoint>&);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> coordinates(jni::JNIEnv&, const jni::Object<MultiPoint>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "multi_polygon.hpp"
|
||||
|
||||
#include "polygon.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<MultiPolygon>> MultiPolygon::New(JNIEnv& env, const mbgl::MultiPolygon<double>& multiPolygon) {
|
||||
static auto& javaClass = jni::Class<MultiPolygon>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<MultiPolygon>(jni::Object<java::util::List>)>(
|
||||
env, "fromLngLats");
|
||||
|
||||
auto jarray = jni::Array<jni::Object<java::util::List>>::New(env, multiPolygon.size());
|
||||
|
||||
for (size_t i = 0; i < multiPolygon.size(); i++) {
|
||||
jarray.Set(env, i, asPointsListsList(env, multiPolygon.at(i)));
|
||||
}
|
||||
|
||||
return javaClass.Call(env, method, java::util::Arrays::asList(env, jarray));
|
||||
}
|
||||
|
||||
mapbox::geojson::multi_polygon MultiPolygon::convert(jni::JNIEnv& env, const jni::Object<MultiPolygon>& jMultiPolygon) {
|
||||
mapbox::geojson::multi_polygon multiPolygon;
|
||||
|
||||
if (jMultiPolygon) {
|
||||
auto jPointListsListList = MultiPolygon::coordinates(env, jMultiPolygon);
|
||||
auto jPointListsListArray = java::util::List::toArray<java::util::List>(env, jPointListsListList);
|
||||
|
||||
auto size = jPointListsListArray.Length(env);
|
||||
multiPolygon.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
multiPolygon.push_back(Polygon::convert(env, jPointListsListArray.Get(env, i)));
|
||||
}
|
||||
}
|
||||
|
||||
return multiPolygon;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> MultiPolygon::coordinates(jni::JNIEnv& env,
|
||||
const jni::Object<MultiPolygon>& jPolygon) {
|
||||
static auto& javaClass = jni::Class<MultiPolygon>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "coordinates");
|
||||
return jPolygon.Call(env, method);
|
||||
}
|
||||
|
||||
void MultiPolygon::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<MultiPolygon>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "../java/util.hpp"
|
||||
#include "geometry.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class MultiPolygon {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/MultiPolygon"; };
|
||||
static constexpr auto Type() { return "MultiPolygon"; };
|
||||
|
||||
static jni::Local<jni::Object<MultiPolygon>> New(jni::JNIEnv&, const mbgl::MultiPolygon<double>&);
|
||||
|
||||
static mapbox::geojson::multi_polygon convert(jni::JNIEnv&, const jni::Object<MultiPolygon>&);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> coordinates(jni::JNIEnv&, const jni::Object<MultiPolygon>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
31
platform/android/MapLibreAndroid/src/cpp/geojson/point.cpp
Normal file
31
platform/android/MapLibreAndroid/src/cpp/geojson/point.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "point.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<Point>> Point::New(jni::JNIEnv& env, const mbgl::Point<double>& point) {
|
||||
static auto& javaClass = jni::Class<Point>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<Point>(jni::jdouble, jni::jdouble)>(env, "fromLngLat");
|
||||
return javaClass.Call(env, method, point.x, point.y);
|
||||
}
|
||||
|
||||
mbgl::Point<double> Point::convert(jni::JNIEnv& env, const jni::Object<Point>& jPoint) {
|
||||
static auto& javaClass = jni::Class<Point>::Singleton(env);
|
||||
static auto longitude = javaClass.GetMethod<jni::jdouble()>(env, "longitude");
|
||||
static auto latitude = javaClass.GetMethod<jni::jdouble()>(env, "latitude");
|
||||
|
||||
if (!jPoint) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {jPoint.Call(env, longitude), jPoint.Call(env, latitude)};
|
||||
}
|
||||
|
||||
void Point::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Point>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
27
platform/android/MapLibreAndroid/src/cpp/geojson/point.hpp
Normal file
27
platform/android/MapLibreAndroid/src/cpp/geojson/point.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
|
||||
#include "geometry.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Point {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/Point"; };
|
||||
static constexpr auto Type() { return "Point"; };
|
||||
|
||||
static jni::Local<jni::Object<Point>> New(jni::JNIEnv&, const mbgl::Point<double>&);
|
||||
static mbgl::Point<double> convert(jni::JNIEnv&, const jni::Object<Point>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
56
platform/android/MapLibreAndroid/src/cpp/geojson/polygon.cpp
Normal file
56
platform/android/MapLibreAndroid/src/cpp/geojson/polygon.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "polygon.hpp"
|
||||
|
||||
#include "multi_line_string.hpp"
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
jni::Local<jni::Object<Polygon>> Polygon::New(jni::JNIEnv& env, const mbgl::Polygon<double>& polygon) {
|
||||
static auto& javaClass = jni::Class<Polygon>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::Object<Polygon>(jni::Object<java::util::List>)>(env,
|
||||
"fromLngLats");
|
||||
|
||||
return javaClass.Call(env, method, asPointsListsList(env, polygon));
|
||||
}
|
||||
|
||||
mapbox::geojson::polygon Polygon::convert(jni::JNIEnv& env, const jni::Object<Polygon>& jPolygon) {
|
||||
mapbox::geojson::polygon polygon;
|
||||
|
||||
if (jPolygon) {
|
||||
polygon = Polygon::convert(env, Polygon::coordinates(env, jPolygon));
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
|
||||
mapbox::geojson::polygon Polygon::convert(
|
||||
jni::JNIEnv& env, const jni::Object<java::util::List /*<java::util::List<Point>>*/>& jPointListsList) {
|
||||
mapbox::geojson::polygon polygon;
|
||||
|
||||
if (jPointListsList) {
|
||||
auto multiLine = MultiLineString::convert(env, jPointListsList);
|
||||
polygon.reserve(multiLine.size());
|
||||
for (auto&& line : multiLine) {
|
||||
polygon.emplace_back(convertExplicit<mapbox::geojson::linear_ring>(std::move(line)));
|
||||
}
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<java::util::List>> Polygon::coordinates(jni::JNIEnv& env, const jni::Object<Polygon>& jPolygon) {
|
||||
static auto& javaClass = jni::Class<Polygon>::Singleton(env);
|
||||
static auto method = javaClass.GetMethod<jni::Object<java::util::List>()>(env, "coordinates");
|
||||
return jPolygon.Call(env, method);
|
||||
}
|
||||
|
||||
void Polygon::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Polygon>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
35
platform/android/MapLibreAndroid/src/cpp/geojson/polygon.hpp
Normal file
35
platform/android/MapLibreAndroid/src/cpp/geojson/polygon.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geojson.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include "geometry.hpp"
|
||||
#include "../java/util.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
class Polygon {
|
||||
public:
|
||||
using SuperTag = Geometry;
|
||||
static constexpr auto Name() { return "com/mapbox/geojson/Polygon"; };
|
||||
static constexpr auto Type() { return "Polygon"; };
|
||||
|
||||
static jni::Local<jni::Object<Polygon>> New(jni::JNIEnv &, const mbgl::Polygon<double> &);
|
||||
|
||||
static mapbox::geojson::polygon convert(jni::JNIEnv &, const jni::Object<Polygon> &);
|
||||
|
||||
static mapbox::geojson::polygon convert(jni::JNIEnv &,
|
||||
const jni::Object<java::util::List /*<java::util::List<Point>>*/> &);
|
||||
|
||||
static jni::Local<jni::Object<java::util::List>> coordinates(jni::JNIEnv &, const jni::Object<Polygon> &);
|
||||
|
||||
static void registerNative(jni::JNIEnv &);
|
||||
};
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
50
platform/android/MapLibreAndroid/src/cpp/geojson/util.hpp
Normal file
50
platform/android/MapLibreAndroid/src/cpp/geojson/util.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "point.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace geojson {
|
||||
|
||||
// Clang 3.8 fails to implicitly convert matching types, so we'll have to do it explicitly.
|
||||
template <typename To, typename From>
|
||||
To convertExplicit(From&& src) {
|
||||
static_assert(std::is_same<typename std::decay_t<From>::container_type, typename To::container_type>::value,
|
||||
"container types do not match");
|
||||
static_assert(std::is_rvalue_reference<From&&>::value, "argument must be rvalue reference");
|
||||
return *reinterpret_cast<std::add_pointer_t<To>>(&src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Geometry -> List<Point>
|
||||
*/
|
||||
template <class T>
|
||||
static jni::Local<jni::Object<java::util::List>> asPointsList(jni::JNIEnv& env, const T& pointsList) {
|
||||
auto jarray = jni::Array<jni::Object<Point>>::New(env, pointsList.size());
|
||||
|
||||
for (jni::jsize i = 0; i < pointsList.size(); i++) {
|
||||
jarray.Set(env, i, Point::New(env, pointsList.at(i)));
|
||||
}
|
||||
|
||||
return java::util::Arrays::asList(env, jarray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Geometry -> List<List<Point>>
|
||||
*/
|
||||
template <class SHAPE>
|
||||
static jni::Local<jni::Object<java::util::List>> asPointsListsList(JNIEnv& env, const SHAPE& value) {
|
||||
auto jarray = jni::Array<jni::Object<java::util::List>>::New(env, value.size());
|
||||
|
||||
for (size_t i = 0; i < value.size(); i++) {
|
||||
jarray.Set(env, i, asPointsList(env, value[i]));
|
||||
}
|
||||
|
||||
return java::util::Arrays::asList(env, jarray);
|
||||
}
|
||||
|
||||
} // namespace geojson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user