[android] jni.hpp 4.0.0
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "custom_geometry_source.hpp"
|
||||
#include "../../attach_env.hpp"
|
||||
|
||||
#include <mbgl/renderer/query.hpp>
|
||||
|
||||
@@ -21,7 +22,7 @@ namespace android {
|
||||
// the value was originally a CustomGeometrySourceOptions object on the Java side. If it fails
|
||||
// to convert, it's a bug in our serialization or Java-side static typing.
|
||||
static style::CustomGeometrySource::Options convertCustomGeometrySourceOptions(jni::JNIEnv& env,
|
||||
jni::Local<jni::Object<>> options,
|
||||
const jni::Object<>& options,
|
||||
style::TileFunction fetchFn,
|
||||
style::TileFunction cancelFn) {
|
||||
using namespace mbgl::style::conversion;
|
||||
@@ -29,7 +30,7 @@ namespace android {
|
||||
return style::CustomGeometrySource::Options();
|
||||
}
|
||||
Error error;
|
||||
optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, std::move(options)), error);
|
||||
optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, options), error);
|
||||
if (!result) {
|
||||
throw std::logic_error(error.message);
|
||||
}
|
||||
@@ -39,11 +40,11 @@ namespace android {
|
||||
}
|
||||
|
||||
CustomGeometrySource::CustomGeometrySource(jni::JNIEnv& env,
|
||||
jni::String sourceId,
|
||||
jni::Object<> options)
|
||||
const jni::String& sourceId,
|
||||
const jni::Object<>& options)
|
||||
: Source(env, std::make_unique<mbgl::style::CustomGeometrySource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
convertCustomGeometrySourceOptions(env, jni::SeizeLocal(env, std::move(options)),
|
||||
convertCustomGeometrySourceOptions(env, options,
|
||||
std::bind(&CustomGeometrySource::fetchTile, this, std::placeholders::_1),
|
||||
std::bind(&CustomGeometrySource::cancelTile, this, std::placeholders::_1)))) {
|
||||
}
|
||||
@@ -61,48 +62,48 @@ namespace android {
|
||||
void CustomGeometrySource::fetchTile (const mbgl::CanonicalTileID& tileID) {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto fetchTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "fetchTile");
|
||||
|
||||
assert(javaPeer);
|
||||
|
||||
auto peer = jni::Cast(*_env, javaClass, *javaPeer);
|
||||
auto peer = jni::Cast(*_env, javaClass, javaPeer);
|
||||
peer.Call(*_env, fetchTile, (int)tileID.z, (int)tileID.x, (int)tileID.y);
|
||||
};
|
||||
|
||||
void CustomGeometrySource::cancelTile(const mbgl::CanonicalTileID& tileID) {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto cancelTile = javaClass.GetMethod<void (jni::jint, jni::jint, jni::jint)>(*_env, "cancelTile");
|
||||
|
||||
assert(javaPeer);
|
||||
|
||||
auto peer = jni::Cast(*_env, javaClass, *javaPeer);
|
||||
auto peer = jni::Cast(*_env, javaClass, javaPeer);
|
||||
peer.Call(*_env, cancelTile, (int)tileID.z, (int)tileID.x, (int)tileID.y);
|
||||
};
|
||||
|
||||
void CustomGeometrySource::startThreads() {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto startThreads = javaClass.GetMethod<void ()>(*_env, "startThreads");
|
||||
|
||||
assert(javaPeer);
|
||||
|
||||
auto peer = jni::Cast(*_env, javaClass, *javaPeer);
|
||||
auto peer = jni::Cast(*_env, javaClass, javaPeer);
|
||||
peer.Call(*_env, startThreads);
|
||||
}
|
||||
|
||||
void CustomGeometrySource::releaseThreads() {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto releaseThreads = javaClass.GetMethod<void ()>(*_env, "releaseThreads");
|
||||
|
||||
assert(javaPeer);
|
||||
|
||||
auto peer = jni::Cast(*_env, javaClass, *javaPeer);
|
||||
auto peer = jni::Cast(*_env, javaClass, javaPeer);
|
||||
peer.Call(*_env, releaseThreads);
|
||||
};
|
||||
|
||||
@@ -111,12 +112,12 @@ namespace android {
|
||||
jni::jint y) {
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
|
||||
static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
|
||||
|
||||
assert(javaPeer);
|
||||
|
||||
auto peer = jni::Cast(*_env, javaClass, *javaPeer);
|
||||
auto peer = jni::Cast(*_env, javaClass, javaPeer);
|
||||
return peer.Call(*_env, isCancelled, z, x, y);
|
||||
};
|
||||
|
||||
@@ -124,7 +125,7 @@ namespace android {
|
||||
jni::jint z,
|
||||
jni::jint x,
|
||||
jni::jint y,
|
||||
jni::Object<geojson::FeatureCollection> jFeatures) {
|
||||
const jni::Object<geojson::FeatureCollection>& jFeatures) {
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
// Convert the jni object
|
||||
@@ -140,36 +141,35 @@ namespace android {
|
||||
source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::invalidateTile(CanonicalTileID(z, x, y));
|
||||
}
|
||||
|
||||
void CustomGeometrySource::invalidateBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> jBounds) {
|
||||
void CustomGeometrySource::invalidateBounds(jni::JNIEnv& env, const jni::Object<LatLngBounds>& jBounds) {
|
||||
auto bounds = LatLngBounds::getLatLngBounds(env, jBounds);
|
||||
source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::invalidateRegion(bounds);
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<geojson::Feature>> CustomGeometrySource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> CustomGeometrySource::querySourceFeatures(jni::JNIEnv& env,
|
||||
const jni::Array<jni::Object<>>& jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
std::vector<mbgl::Feature> features;
|
||||
if (rendererFrontend) {
|
||||
features = rendererFrontend->querySourceFeatures(source.getID(),
|
||||
{ {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
|
||||
features = rendererFrontend->querySourceFeatures(source.getID(), { {}, toFilter(env, jfilter) });
|
||||
}
|
||||
return Feature::convert(env, features);
|
||||
}
|
||||
|
||||
jni::Object<Source> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> CustomGeometrySource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void CustomGeometrySource::addToMap(JNIEnv& env, jni::Object<Source> obj, mbgl::Map& map, AndroidRendererFrontend& frontend) {
|
||||
void CustomGeometrySource::addToMap(JNIEnv& env, const jni::Object<Source>& obj, mbgl::Map& map, AndroidRendererFrontend& frontend) {
|
||||
Source::addToMap(env, obj, map, frontend);
|
||||
startThreads();
|
||||
}
|
||||
|
||||
bool CustomGeometrySource::removeFromMap(JNIEnv& env, jni::Object<Source> source, mbgl::Map& map) {
|
||||
bool CustomGeometrySource::removeFromMap(JNIEnv& env, const jni::Object<Source>& source, mbgl::Map& map) {
|
||||
bool successfullyRemoved = Source::removeFromMap(env, source, map);
|
||||
if (successfullyRemoved) {
|
||||
releaseThreads();
|
||||
@@ -179,14 +179,14 @@ namespace android {
|
||||
|
||||
void CustomGeometrySource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<CustomGeometrySource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<CustomGeometrySource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<CustomGeometrySource, JNIEnv&, jni::String, jni::Object<>>,
|
||||
jni::MakePeer<CustomGeometrySource, const jni::String&, const jni::Object<>&>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&CustomGeometrySource::querySourceFeatures, "querySourceFeatures"),
|
||||
|
||||
@@ -15,17 +15,17 @@ namespace android {
|
||||
|
||||
class CustomGeometrySource : public Source {
|
||||
public:
|
||||
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/CustomGeometrySource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
CustomGeometrySource(jni::JNIEnv&, jni::String, jni::Object<>);
|
||||
CustomGeometrySource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
|
||||
CustomGeometrySource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
~CustomGeometrySource();
|
||||
|
||||
bool removeFromMap(JNIEnv&, jni::Object<Source>, mbgl::Map&) override;
|
||||
void addToMap(JNIEnv&, jni::Object<Source>, mbgl::Map&, AndroidRendererFrontend&) override;
|
||||
bool removeFromMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map&) override;
|
||||
void addToMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map&, AndroidRendererFrontend&) override;
|
||||
|
||||
void fetchTile(const mbgl::CanonicalTileID& tileID);
|
||||
void cancelTile(const mbgl::CanonicalTileID& tileID);
|
||||
@@ -34,15 +34,15 @@ public:
|
||||
void releaseThreads();
|
||||
|
||||
private:
|
||||
void setTileData(jni::JNIEnv& env, jni::jint z, jni::jint x, jni::jint y, jni::Object<geojson::FeatureCollection> jf);
|
||||
void setTileData(jni::JNIEnv& env, jni::jint z, jni::jint x, jni::jint y, const jni::Object<geojson::FeatureCollection>& jf);
|
||||
|
||||
void invalidateTile(jni::JNIEnv& env, jni::jint z, jni::jint x, jni::jint y);
|
||||
void invalidateBounds(jni::JNIEnv& env, jni::Object<LatLngBounds> bounds);
|
||||
void invalidateBounds(jni::JNIEnv& env, const jni::Object<LatLngBounds>& bounds);
|
||||
|
||||
jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&,
|
||||
jni::Array<jni::Object<>> );
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> querySourceFeatures(jni::JNIEnv&,
|
||||
const jni::Array<jni::Object<>>& );
|
||||
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class CustomGeometrySource
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "geojson_source.hpp"
|
||||
#include "../../attach_env.hpp"
|
||||
|
||||
#include <mbgl/renderer/query.hpp>
|
||||
|
||||
@@ -29,24 +30,24 @@ namespace android {
|
||||
// This conversion is expected not to fail because it's used only in contexts where
|
||||
// the value was originally a GeoJsonOptions object on the Java side. If it fails
|
||||
// to convert, it's a bug in our serialization or Java-side static typing.
|
||||
static style::GeoJSONOptions convertGeoJSONOptions(jni::JNIEnv& env, jni::Local<jni::Object<>> options) {
|
||||
static style::GeoJSONOptions convertGeoJSONOptions(jni::JNIEnv& env, const jni::Object<>& options) {
|
||||
using namespace mbgl::style::conversion;
|
||||
if (!options) {
|
||||
return style::GeoJSONOptions();
|
||||
}
|
||||
Error error;
|
||||
optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(
|
||||
mbgl::android::Value(env, std::move(options)), error);
|
||||
mbgl::android::Value(env, options), error);
|
||||
if (!result) {
|
||||
throw std::logic_error(error.message);
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
|
||||
GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> options)
|
||||
GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, const jni::String& sourceId, const jni::Object<>& options)
|
||||
: Source(env, std::make_unique<mbgl::style::GeoJSONSource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
convertGeoJSONOptions(env, jni::SeizeLocal(env, std::move(options)))))
|
||||
convertGeoJSONOptions(env, options)))
|
||||
, threadPool(sharedThreadPool())
|
||||
, converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) {
|
||||
}
|
||||
@@ -61,7 +62,7 @@ namespace android {
|
||||
|
||||
GeoJSONSource::~GeoJSONSource() = default;
|
||||
|
||||
void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, jni::String jString) {
|
||||
void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, const jni::String& jString) {
|
||||
|
||||
std::shared_ptr<std::string> json = std::make_shared<std::string>(jni::Make<std::string>(env, jString));
|
||||
|
||||
@@ -72,54 +73,54 @@ namespace android {
|
||||
setAsync(converterFn);
|
||||
}
|
||||
|
||||
void GeoJSONSource::setFeatureCollection(jni::JNIEnv& env, jni::Object<geojson::FeatureCollection> jFeatures) {
|
||||
void GeoJSONSource::setFeatureCollection(jni::JNIEnv& env, const jni::Object<geojson::FeatureCollection>& jFeatures) {
|
||||
setCollectionAsync(env, jFeatures);
|
||||
}
|
||||
|
||||
void GeoJSONSource::setFeature(jni::JNIEnv& env, jni::Object<geojson::Feature> jFeature) {
|
||||
void GeoJSONSource::setFeature(jni::JNIEnv& env, const jni::Object<geojson::Feature>& jFeature) {
|
||||
setCollectionAsync(env, jFeature);
|
||||
}
|
||||
|
||||
void GeoJSONSource::setGeometry(jni::JNIEnv& env, jni::Object<geojson::Geometry> jGeometry) {
|
||||
void GeoJSONSource::setGeometry(jni::JNIEnv& env, const jni::Object<geojson::Geometry>& jGeometry) {
|
||||
setCollectionAsync(env, jGeometry);
|
||||
}
|
||||
|
||||
void GeoJSONSource::setURL(jni::JNIEnv& env, jni::String url) {
|
||||
void GeoJSONSource::setURL(jni::JNIEnv& env, const jni::String& url) {
|
||||
// Update the core source
|
||||
source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setURL(jni::Make<std::string>(env, url));
|
||||
}
|
||||
|
||||
jni::String GeoJSONSource::getURL(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> GeoJSONSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::String();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<geojson::Feature>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> GeoJSONSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
const jni::Array<jni::Object<>>& jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
std::vector<mbgl::Feature> features;
|
||||
if (rendererFrontend) {
|
||||
features = rendererFrontend->querySourceFeatures(source.getID(),
|
||||
{ {}, toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
|
||||
{ {}, toFilter(env, jfilter) });
|
||||
}
|
||||
return Feature::convert(env, features);
|
||||
}
|
||||
|
||||
jni::Object<Source> GeoJSONSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<GeoJSONSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> GeoJSONSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<GeoJSONSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
template <class JNIType>
|
||||
void GeoJSONSource::setCollectionAsync(jni::JNIEnv& env, jni::Object<JNIType> jObject) {
|
||||
|
||||
std::shared_ptr<jni::jobject> object = std::shared_ptr<jni::jobject>(jObject.NewGlobalRef(env).release().Get(), GenericGlobalRefDeleter());
|
||||
void GeoJSONSource::setCollectionAsync(jni::JNIEnv& env, const jni::Object<JNIType>& jObject) {
|
||||
auto global = jni::NewGlobal<jni::EnvAttachingDeleter>(env, jObject);
|
||||
auto object = std::make_shared<decltype(global)>(std::move(global));
|
||||
|
||||
Update::Converter converterFn = [this, object](ActorRef<Callback> _callback) {
|
||||
converter->self().invoke(&FeatureConverter::convertObject<JNIType>, jni::Object<JNIType>(*object), _callback);
|
||||
converter->self().invoke(&FeatureConverter::convertObject<JNIType>, object, _callback);
|
||||
};
|
||||
|
||||
setAsync(converterFn);
|
||||
@@ -159,14 +160,14 @@ namespace android {
|
||||
|
||||
void GeoJSONSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<GeoJSONSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<GeoJSONSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<GeoJSONSource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<GeoJSONSource, JNIEnv&, jni::String, jni::Object<>>,
|
||||
jni::MakePeer<GeoJSONSource, const jni::String&, const jni::Object<>&>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&GeoJSONSource::setGeoJSONString, "nativeSetGeoJsonString"),
|
||||
@@ -196,13 +197,13 @@ namespace android {
|
||||
callback.invoke(&Callback::operator(), *converted);
|
||||
}
|
||||
|
||||
template<class JNIType>
|
||||
void FeatureConverter::convertObject(jni::Object<JNIType> jObject, ActorRef<Callback> callback) {
|
||||
template <class JNIType>
|
||||
void FeatureConverter::convertObject(std::shared_ptr<jni::Global<jni::Object<JNIType>, jni::EnvAttachingDeleter>> jObject, ActorRef<Callback> callback) {
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
// Convert the jni object
|
||||
auto geometry = JNIType::convert(*_env, jObject);
|
||||
auto geometry = JNIType::convert(*_env, *jObject);
|
||||
callback.invoke(&Callback::operator(), GeoJSON(geometry));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ struct FeatureConverter {
|
||||
void convertJson(std::shared_ptr<std::string>, ActorRef<Callback>);
|
||||
|
||||
template <class JNIType>
|
||||
void convertObject(jni::Object<JNIType>, ActorRef<Callback>);
|
||||
void convertObject(std::shared_ptr<jni::Global<jni::Object<JNIType>, jni::EnvAttachingDeleter>>, ActorRef<Callback>);
|
||||
};
|
||||
|
||||
struct Update {
|
||||
@@ -30,34 +30,35 @@ struct Update {
|
||||
|
||||
class GeoJSONSource : public Source {
|
||||
public:
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/GeoJsonSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
GeoJSONSource(jni::JNIEnv&, jni::String, jni::Object<>);
|
||||
GeoJSONSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
|
||||
GeoJSONSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
~GeoJSONSource();
|
||||
|
||||
private:
|
||||
void setGeoJSONString(jni::JNIEnv&, jni::String);
|
||||
void setFeatureCollection(jni::JNIEnv&, jni::Object<geojson::FeatureCollection>);
|
||||
void setFeature(jni::JNIEnv&, jni::Object<geojson::Feature>);
|
||||
void setGeometry(jni::JNIEnv&, jni::Object<geojson::Geometry>);
|
||||
void setURL(jni::JNIEnv&, jni::String);
|
||||
void setGeoJSONString(jni::JNIEnv&, const jni::String&);
|
||||
void setFeatureCollection(jni::JNIEnv&, const jni::Object<geojson::FeatureCollection>&);
|
||||
void setFeature(jni::JNIEnv&, const jni::Object<geojson::Feature>&);
|
||||
void setGeometry(jni::JNIEnv&, const jni::Object<geojson::Geometry>&);
|
||||
void setURL(jni::JNIEnv&, const jni::String&);
|
||||
|
||||
jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&,
|
||||
jni::Array<jni::Object<>>);
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> querySourceFeatures(jni::JNIEnv&,
|
||||
const jni::Array<jni::Object<>>&);
|
||||
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getURL(jni::JNIEnv&);
|
||||
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
std::unique_ptr<Update> awaitingUpdate;
|
||||
std::unique_ptr<Update> update;
|
||||
std::shared_ptr<ThreadPool> threadPool;
|
||||
std::unique_ptr<Actor<FeatureConverter>> converter;
|
||||
|
||||
template <class JNIType>
|
||||
void setCollectionAsync(jni::JNIEnv&, jni::Object<JNIType>);
|
||||
void setCollectionAsync(jni::JNIEnv&, const jni::Object<JNIType>&);
|
||||
|
||||
void setAsync(Update::Converter);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
ImageSource::ImageSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<LatLngQuad> coordinatesObject)
|
||||
ImageSource::ImageSource(jni::JNIEnv& env, const jni::String& sourceId, const jni::Object<LatLngQuad>& coordinatesObject)
|
||||
: Source(env, std::make_unique<mbgl::style::ImageSource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
LatLngQuad::getLatLngArray(env, coordinatesObject)
|
||||
@@ -31,41 +31,41 @@ namespace android {
|
||||
|
||||
ImageSource::~ImageSource() = default;
|
||||
|
||||
void ImageSource::setURL(jni::JNIEnv& env, jni::String url) {
|
||||
void ImageSource::setURL(jni::JNIEnv& env, const jni::String& url) {
|
||||
// Update the core source
|
||||
source.as<mbgl::style::ImageSource>()->ImageSource::setURL(jni::Make<std::string>(env, url));
|
||||
}
|
||||
|
||||
jni::String ImageSource::getURL(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> ImageSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::ImageSource>()->ImageSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::String();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
void ImageSource::setImage(jni::JNIEnv& env, jni::Object<Bitmap> bitmap) {
|
||||
void ImageSource::setImage(jni::JNIEnv& env, const jni::Object<Bitmap>& bitmap) {
|
||||
source.as<mbgl::style::ImageSource>()->setImage(Bitmap::GetImage(env, bitmap));
|
||||
}
|
||||
|
||||
void ImageSource::setCoordinates(jni::JNIEnv& env, jni::Object<LatLngQuad> coordinatesObject) {
|
||||
void ImageSource::setCoordinates(jni::JNIEnv& env, const jni::Object<LatLngQuad>& coordinatesObject) {
|
||||
source.as<mbgl::style::ImageSource>()->setCoordinates(
|
||||
LatLngQuad::getLatLngArray(env, coordinatesObject));
|
||||
}
|
||||
|
||||
jni::Object<Source> ImageSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<ImageSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> ImageSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<ImageSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void ImageSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<ImageSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<ImageSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<ImageSource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<ImageSource, JNIEnv&, jni::String, jni::Object<LatLngQuad>>,
|
||||
jni::MakePeer<ImageSource, const jni::String&, const jni::Object<LatLngQuad>&>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&ImageSource::setURL, "nativeSetUrl"),
|
||||
|
||||
@@ -12,26 +12,26 @@ class Bitmap;
|
||||
|
||||
class ImageSource : public Source {
|
||||
public:
|
||||
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/ImageSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
ImageSource(jni::JNIEnv&, jni::String, jni::Object<LatLngQuad>);
|
||||
ImageSource(jni::JNIEnv&, const jni::String&, const jni::Object<LatLngQuad>&);
|
||||
|
||||
ImageSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
|
||||
~ImageSource();
|
||||
|
||||
void setURL(jni::JNIEnv&, jni::String);
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
void setURL(jni::JNIEnv&, const jni::String&);
|
||||
jni::Local<jni::String> getURL(jni::JNIEnv&);
|
||||
|
||||
void setImage(jni::JNIEnv&, jni::Object<Bitmap>);
|
||||
void setImage(jni::JNIEnv&, const jni::Object<Bitmap>&);
|
||||
|
||||
void setCoordinates(jni::JNIEnv&, jni::Object<LatLngQuad>);
|
||||
void setCoordinates(jni::JNIEnv&, const jni::Object<LatLngQuad>&);
|
||||
|
||||
private:
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class ImageSource
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
RasterDEMSource::RasterDEMSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> urlOrTileSet, jni::jint tileSize)
|
||||
RasterDEMSource::RasterDEMSource(jni::JNIEnv& env, const jni::String& sourceId, const jni::Object<>& urlOrTileSet, jni::jint tileSize)
|
||||
: Source(
|
||||
env,
|
||||
std::make_unique<mbgl::style::RasterDEMSource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet)))),
|
||||
convertURLOrTileset(Value(env, urlOrTileSet)),
|
||||
tileSize
|
||||
)
|
||||
) {
|
||||
@@ -31,27 +31,27 @@ namespace android {
|
||||
|
||||
RasterDEMSource::~RasterDEMSource() = default;
|
||||
|
||||
jni::String RasterDEMSource::getURL(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> RasterDEMSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::RasterDEMSource>()->RasterDEMSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::String();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
jni::Object<Source> RasterDEMSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<RasterDEMSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> RasterDEMSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<RasterDEMSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void RasterDEMSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<RasterDEMSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<RasterDEMSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<RasterDEMSource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<RasterDEMSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>,
|
||||
jni::MakePeer<RasterDEMSource, const jni::String&, const jni::Object<>&, jni::jint>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&RasterDEMSource::getURL, "nativeGetUrl")
|
||||
|
||||
@@ -9,18 +9,19 @@ namespace android {
|
||||
|
||||
class RasterDEMSource : public Source {
|
||||
public:
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/RasterDemSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
RasterDEMSource(jni::JNIEnv&, jni::String, jni::Object<>, jni::jint);
|
||||
RasterDEMSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&, jni::jint);
|
||||
RasterDEMSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
~RasterDEMSource();
|
||||
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getURL(jni::JNIEnv&);
|
||||
|
||||
private:
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class RasterDEMSource
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
RasterSource::RasterSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> urlOrTileSet, jni::jint tileSize)
|
||||
RasterSource::RasterSource(jni::JNIEnv& env, const jni::String& sourceId, const jni::Object<>& urlOrTileSet, jni::jint tileSize)
|
||||
: Source(
|
||||
env,
|
||||
std::make_unique<mbgl::style::RasterSource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet)))),
|
||||
convertURLOrTileset(Value(env, urlOrTileSet)),
|
||||
tileSize
|
||||
)
|
||||
) {
|
||||
@@ -30,27 +30,27 @@ namespace android {
|
||||
|
||||
RasterSource::~RasterSource() = default;
|
||||
|
||||
jni::String RasterSource::getURL(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> RasterSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::RasterSource>()->RasterSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::String();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
jni::Object<Source> RasterSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<RasterSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> RasterSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<RasterSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void RasterSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<RasterSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<RasterSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<RasterSource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<RasterSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>,
|
||||
jni::MakePeer<RasterSource, const jni::String&, const jni::Object<>&, jni::jint>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&RasterSource::getURL, "nativeGetUrl")
|
||||
|
||||
@@ -9,18 +9,19 @@ namespace android {
|
||||
|
||||
class RasterSource : public Source {
|
||||
public:
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/RasterSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
RasterSource(jni::JNIEnv&, jni::String, jni::Object<>, jni::jint);
|
||||
RasterSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&, jni::jint);
|
||||
RasterSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
~RasterSource();
|
||||
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getURL(jni::JNIEnv&);
|
||||
|
||||
private:
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class RasterSource
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "source.hpp"
|
||||
#include "../android_conversion.hpp"
|
||||
#include "../../attach_env.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
@@ -47,16 +48,16 @@ namespace android {
|
||||
}
|
||||
}
|
||||
|
||||
jni::Object<Source> Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) {
|
||||
const jni::Object<Source>& Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) {
|
||||
if (!coreSource.peer.has_value()) {
|
||||
coreSource.peer = createSourcePeer(env, coreSource, frontend);
|
||||
}
|
||||
return *coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer;
|
||||
return coreSource.peer.get<std::unique_ptr<Source>>()->javaPeer;
|
||||
}
|
||||
|
||||
Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, jni::Object<Source> obj, AndroidRendererFrontend& frontend)
|
||||
Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, const jni::Object<Source>& obj, AndroidRendererFrontend& frontend)
|
||||
: source(coreSource)
|
||||
, javaPeer(obj.NewGlobalRef(env))
|
||||
, javaPeer(jni::NewGlobal(env, obj))
|
||||
, rendererFrontend(&frontend) {
|
||||
}
|
||||
|
||||
@@ -76,23 +77,23 @@ namespace android {
|
||||
if (ownedSource.get() == nullptr && javaPeer.get() != nullptr) {
|
||||
// Manually clear the java peer
|
||||
android::UniqueEnv env = android::AttachEnv();
|
||||
static auto javaClass = jni::Class<Source>::Singleton(*env);
|
||||
static auto& javaClass = jni::Class<Source>::Singleton(*env);
|
||||
static auto nativePtrField = javaClass.GetField<jlong>(*env, "nativePtr");
|
||||
javaPeer->Set(*env, nativePtrField, (jlong) 0);
|
||||
javaPeer.Set(*env, nativePtrField, (jlong) 0);
|
||||
javaPeer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
jni::String Source::getId(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> Source::getId(jni::JNIEnv& env) {
|
||||
return jni::Make<jni::String>(env, source.getID());
|
||||
}
|
||||
|
||||
jni::String Source::getAttribution(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> Source::getAttribution(jni::JNIEnv& env) {
|
||||
auto attribution = source.getAttribution();
|
||||
return attribution ? jni::Make<jni::String>(env, attribution.value()) : jni::Make<jni::String>(env,"");
|
||||
}
|
||||
|
||||
void Source::addToMap(JNIEnv& env, jni::Object<Source> obj, mbgl::Map& map, AndroidRendererFrontend& frontend) {
|
||||
void Source::addToMap(JNIEnv& env, const jni::Object<Source>& obj, mbgl::Map& map, AndroidRendererFrontend& frontend) {
|
||||
// Check to see if we own the source first
|
||||
if (!ownedSource) {
|
||||
throw std::runtime_error("Cannot add source twice");
|
||||
@@ -105,12 +106,12 @@ namespace android {
|
||||
source.peer = std::unique_ptr<Source>(this);
|
||||
|
||||
// Add strong reference to java source
|
||||
javaPeer = obj.NewGlobalRef(env);
|
||||
javaPeer = jni::NewGlobal(env, obj);
|
||||
|
||||
rendererFrontend = &frontend;
|
||||
}
|
||||
|
||||
bool Source::removeFromMap(JNIEnv&, jni::Object<Source>, mbgl::Map& map) {
|
||||
bool Source::removeFromMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map& map) {
|
||||
// Cannot remove if not attached yet
|
||||
if (ownedSource) {
|
||||
throw std::runtime_error("Cannot remove detached source");
|
||||
@@ -143,7 +144,7 @@ namespace android {
|
||||
|
||||
void Source::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<Source>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<Source>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ public:
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
static jni::Object<Source> peerForCoreSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
static const jni::Object<Source>& peerForCoreSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
|
||||
/*
|
||||
* Called when a Java object is created for a core source that belongs to a map.
|
||||
*/
|
||||
Source(jni::JNIEnv&, mbgl::style::Source&, jni::Object<Source>, AndroidRendererFrontend&);
|
||||
Source(jni::JNIEnv&, mbgl::style::Source&, const jni::Object<Source>&, AndroidRendererFrontend&);
|
||||
|
||||
/*
|
||||
* Called when a Java object is created for a new core source that does not belong to a map.
|
||||
@@ -33,15 +33,15 @@ public:
|
||||
|
||||
virtual ~Source();
|
||||
|
||||
virtual void addToMap(JNIEnv&, jni::Object<Source>, mbgl::Map&, AndroidRendererFrontend&);
|
||||
virtual void addToMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map&, AndroidRendererFrontend&);
|
||||
|
||||
virtual bool removeFromMap(JNIEnv&, jni::Object<Source>, mbgl::Map&);
|
||||
virtual bool removeFromMap(JNIEnv&, const jni::Object<Source>&, mbgl::Map&);
|
||||
|
||||
void releaseJavaPeer();
|
||||
|
||||
jni::String getId(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getId(jni::JNIEnv&);
|
||||
|
||||
jni::String getAttribution(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getAttribution(jni::JNIEnv&);
|
||||
|
||||
protected:
|
||||
// Set on newly created sources until added to the map.
|
||||
|
||||
@@ -18,15 +18,15 @@ namespace android {
|
||||
: Source(env, coreSource, createJavaPeer(env), frontend) {
|
||||
}
|
||||
|
||||
jni::Object<Source> UnknownSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<UnknownSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> UnknownSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<UnknownSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void UnknownSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<UnknownSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<UnknownSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace android {
|
||||
|
||||
class UnknownSource : public Source {
|
||||
public:
|
||||
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/UnknownSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
~UnknownSource() = default;
|
||||
|
||||
private:
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class UnknownSource
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
VectorSource::VectorSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> urlOrTileSet)
|
||||
VectorSource::VectorSource(jni::JNIEnv& env, const jni::String& sourceId, const jni::Object<>& urlOrTileSet)
|
||||
: Source(
|
||||
env,
|
||||
std::make_unique<mbgl::style::VectorSource>(
|
||||
jni::Make<std::string>(env, sourceId),
|
||||
convertURLOrTileset(Value(env, jni::SeizeLocal(env, std::move(urlOrTileSet))))
|
||||
convertURLOrTileset(Value(env, urlOrTileSet))
|
||||
)
|
||||
) {
|
||||
}
|
||||
@@ -38,41 +38,41 @@ namespace android {
|
||||
|
||||
VectorSource::~VectorSource() = default;
|
||||
|
||||
jni::String VectorSource::getURL(jni::JNIEnv& env) {
|
||||
jni::Local<jni::String> VectorSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::VectorSource>()->VectorSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::String();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
jni::Array<jni::Object<geojson::Feature>> VectorSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
jni::Array<jni::String> jSourceLayerIds,
|
||||
jni::Array<jni::Object<>> jfilter) {
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> VectorSource::querySourceFeatures(jni::JNIEnv& env,
|
||||
const jni::Array<jni::String>& jSourceLayerIds,
|
||||
const jni::Array<jni::Object<>>& jfilter) {
|
||||
using namespace mbgl::android::conversion;
|
||||
using namespace mbgl::android::geojson;
|
||||
|
||||
std::vector<mbgl::Feature> features;
|
||||
if (rendererFrontend) {
|
||||
features = rendererFrontend->querySourceFeatures(source.getID(),
|
||||
{ toVector(env, jSourceLayerIds), toFilter(env, jni::SeizeLocal(env, std::move(jfilter))) });
|
||||
{ toVector(env, jSourceLayerIds), toFilter(env, jfilter) });
|
||||
}
|
||||
return Feature::convert(env, features);
|
||||
}
|
||||
|
||||
jni::Object<Source> VectorSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto javaClass = jni::Class<VectorSource>::Singleton(env);
|
||||
jni::Local<jni::Object<Source>> VectorSource::createJavaPeer(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<VectorSource>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
|
||||
return jni::Object<Source>(javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get());
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
|
||||
}
|
||||
|
||||
void VectorSource::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<VectorSource>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<VectorSource>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<VectorSource>(
|
||||
env, javaClass, "nativePtr",
|
||||
std::make_unique<VectorSource, JNIEnv&, jni::String, jni::Object<>>,
|
||||
jni::MakePeer<VectorSource, const jni::String&, const jni::Object<>&>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&VectorSource::querySourceFeatures, "querySourceFeatures"),
|
||||
|
||||
@@ -10,21 +10,22 @@ namespace android {
|
||||
|
||||
class VectorSource : public Source {
|
||||
public:
|
||||
using SuperTag = Source;
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/VectorSource"; };
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
VectorSource(jni::JNIEnv&, jni::String, jni::Object<>);
|
||||
VectorSource(jni::JNIEnv&, const jni::String&, const jni::Object<>&);
|
||||
VectorSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&);
|
||||
~VectorSource();
|
||||
|
||||
private:
|
||||
jni::Array<jni::Object<geojson::Feature>> querySourceFeatures(jni::JNIEnv&, jni::Array<jni::String>,
|
||||
jni::Array<jni::Object<>> jfilter);
|
||||
jni::Local<jni::Array<jni::Object<geojson::Feature>>> querySourceFeatures(jni::JNIEnv&, const jni::Array<jni::String>&,
|
||||
const jni::Array<jni::Object<>>& jfilter);
|
||||
|
||||
jni::String getURL(jni::JNIEnv&);
|
||||
jni::Local<jni::String> getURL(jni::JNIEnv&);
|
||||
|
||||
jni::Object<Source> createJavaPeer(jni::JNIEnv&);
|
||||
jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&);
|
||||
|
||||
}; // class VectorSource
|
||||
|
||||
|
||||
Reference in New Issue
Block a user