#include "source.hpp" #include "../android_conversion.hpp" #include #include #include // Java -> C++ conversion #include #include // C++ -> Java conversion #include "../conversion/property_value.hpp" #include namespace mbgl { namespace android { /** * Invoked when the construction is initiated from the jvm through a subclass */ Source::Source(jni::JNIEnv&, std::unique_ptr coreSource) : ownedSource(std::move(coreSource)) , source(*ownedSource) { } Source::Source(mbgl::Map& coreMap, mbgl::style::Source& coreSource) : source(coreSource) , map(&coreMap) { } Source::~Source() { } style::Source& Source::get() { return source; } void Source::setSource(std::unique_ptr coreSource) { this->ownedSource = std::move(coreSource); } jni::String Source::getId(jni::JNIEnv& env) { return jni::Make(env, source.getID()); } jni::String Source::getAttribution(jni::JNIEnv& env) { auto attribution = source.getAttribution(); return attribution ? jni::Make(env, attribution.value()) : jni::Make(env,""); } void Source::addToMap(mbgl::Map& _map) { // Check to see if we own the source first if (!ownedSource) { throw std::runtime_error("Cannot add source twice"); } // Add source to map _map.getStyle().addSource(releaseCoreSource()); // Save pointer to the map this->map = &_map; } std::unique_ptr Source::releaseCoreSource() { assert(ownedSource != nullptr); return std::move(ownedSource); } jni::Class Source::javaClass; void Source::registerNative(jni::JNIEnv& env) { // Lookup the class Source::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer jni::RegisterNativePeer(env, Source::javaClass, "nativePtr", METHOD(&Source::getId, "nativeGetId"), METHOD(&Source::getAttribution, "nativeGetAttribution") ); } } // namespace android } // namespace mbgl