|
14 | 14 | #include <mbgl/map/map.hpp>
|
15 | 15 | #include <mbgl/map/camera.hpp>
|
16 | 16 | #include <mbgl/annotation/annotation.hpp>
|
| 17 | +#include <mbgl/style/layer.hpp> |
17 | 18 | #include <mbgl/style/layers/custom_layer.hpp>
|
18 | 19 | #include <mbgl/sprite/sprite_image.hpp>
|
19 | 20 | #include <mbgl/platform/event.hpp>
|
@@ -158,6 +159,9 @@ jni::jmethodID* offlineRegionDeleteOnErrorId = nullptr;
|
158 | 159 |
|
159 | 160 | // Offline declarations end
|
160 | 161 |
|
| 162 | +jni::jclass* layerClass = nullptr; |
| 163 | +jni::jmethodID* layerConstructorId = nullptr; |
| 164 | + |
161 | 165 | bool attach_jni_thread(JavaVM* vm, JNIEnv** env, std::string threadName) {
|
162 | 166 | assert(vm != nullptr);
|
163 | 167 | assert(env != nullptr);
|
@@ -1085,8 +1089,20 @@ void nativeRemoveCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapView
|
1085 | 1089 | nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id));
|
1086 | 1090 | }
|
1087 | 1091 |
|
1088 |
| -void nativeGetLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) { |
1089 |
| - //TODO |
| 1092 | +jni::jobject* nativeGetLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* jLayerId) { |
| 1093 | + mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLayer"); |
| 1094 | + assert(nativeMapViewPtr != 0); |
| 1095 | + |
| 1096 | + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); |
| 1097 | + |
| 1098 | + std::string layerId = std_string_from_jstring(env, jLayerId); |
| 1099 | + mbgl::style::Layer* layer = nativeMapView->getMap().getLayer(layerId); |
| 1100 | + |
| 1101 | + if (layer != nullptr) { |
| 1102 | + return &jni::NewObject(*env, *layerClass, *layerConstructorId, jLayerId); |
| 1103 | + } else { |
| 1104 | + return NULL; |
| 1105 | + } |
1090 | 1106 | }
|
1091 | 1107 |
|
1092 | 1108 | // Offline calls begin
|
@@ -1801,6 +1817,12 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
1801 | 1817 |
|
1802 | 1818 | // Offline end
|
1803 | 1819 |
|
| 1820 | + // Style |
| 1821 | + |
| 1822 | + layerClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Layer"); |
| 1823 | + layerClass = jni::NewGlobalRef(env, layerClass).release(); |
| 1824 | + layerConstructorId = &jni::GetMethodID(env, *layerClass, "<init>", "(J)V"); |
| 1825 | + |
1804 | 1826 | char release[PROP_VALUE_MAX] = "";
|
1805 | 1827 | __system_property_get("ro.build.version.release", release);
|
1806 | 1828 | androidRelease = std::string(release);
|
|
0 commit comments