1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "source.hpp"
#include "../android_conversion.hpp"
#include <jni/jni.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/logging.hpp>
// Java -> C++ conversion
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/source.hpp>
// C++ -> Java conversion
#include "../conversion/property_value.hpp"
#include <string>
namespace mbgl {
namespace android {
/**
* Invoked when the construction is initiated from the jvm through a subclass
*/
Source::Source(jni::JNIEnv&, std::unique_ptr<mbgl::style::Source> coreSource)
: ownedSource(std::move(coreSource))
, source(*ownedSource) {
}
Source::Source(mbgl::style::Source& coreSource)
: source(coreSource) {
}
Source::~Source() = default;
style::Source& Source::get() {
return source;
}
void Source::setSource(std::unique_ptr<style::Source> coreSource) {
this->ownedSource = std::move(coreSource);
}
jni::String Source::getId(jni::JNIEnv& env) {
return jni::Make<jni::String>(env, source.getID());
}
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(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());
}
void Source::setRendererFrontend(AndroidRendererFrontend& frontend_) {
rendererFrontend = &frontend_;
}
std::unique_ptr<mbgl::style::Source> Source::releaseCoreSource() {
assert(ownedSource != nullptr);
return std::move(ownedSource);
}
jni::Class<Source> Source::javaClass;
void Source::registerNative(jni::JNIEnv& env) {
// Lookup the class
Source::javaClass = *jni::Class<Source>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
// Register the peer
jni::RegisterNativePeer<Source>(env, Source::javaClass, "nativePtr",
METHOD(&Source::getId, "nativeGetId"),
METHOD(&Source::getAttribution, "nativeGetAttribution")
);
}
} // namespace android
} // namespace mbgl
|