Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 049e9ef

Browse files
committedJul 11, 2016
[android] #5610 - added jni binding for NativeMapView#getLayer
1 parent a301ef5 commit 049e9ef

File tree

2 files changed

+30
-8
lines changed
  • platform/android
    • MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers
    • src

2 files changed

+30
-8
lines changed
 

‎platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
/**
44
* Base class for the different Layer types
55
*/
6-
public abstract class Layer {
6+
public class Layer {
77

8-
private final String nativeMapId;
8+
private final long nativeMapPtr;
99

10-
protected Layer(String nativeMapId) {
11-
this.nativeMapId = nativeMapId;
10+
public Layer(long nativeMapId) {
11+
this.nativeMapPtr = nativeMapId;
1212
}
1313

1414
public void setProperty(Property<?> property) {
15-
nativeSetProperty(nativeMapId, property);
15+
nativeSetProperty(nativeMapPtr, property);
1616
}
1717

1818

19-
private native void nativeSetProperty(String nativeMapId, Property<?> property);
19+
private native void nativeSetProperty(long nativeMapPtr, Property<?> property);
2020

2121
}

‎platform/android/src/jni.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <mbgl/map/map.hpp>
1515
#include <mbgl/map/camera.hpp>
1616
#include <mbgl/annotation/annotation.hpp>
17+
#include <mbgl/style/layer.hpp>
1718
#include <mbgl/style/layers/custom_layer.hpp>
1819
#include <mbgl/sprite/sprite_image.hpp>
1920
#include <mbgl/platform/event.hpp>
@@ -158,6 +159,9 @@ jni::jmethodID* offlineRegionDeleteOnErrorId = nullptr;
158159

159160
// Offline declarations end
160161

162+
jni::jclass* layerClass = nullptr;
163+
jni::jmethodID* layerConstructorId = nullptr;
164+
161165
bool attach_jni_thread(JavaVM* vm, JNIEnv** env, std::string threadName) {
162166
assert(vm != nullptr);
163167
assert(env != nullptr);
@@ -1085,8 +1089,20 @@ void nativeRemoveCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapView
10851089
nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id));
10861090
}
10871091

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+
}
10901106
}
10911107

10921108
// Offline calls begin
@@ -1801,6 +1817,12 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
18011817

18021818
// Offline end
18031819

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+
18041826
char release[PROP_VALUE_MAX] = "";
18051827
__system_property_get("ro.build.version.release", release);
18061828
androidRelease = std::string(release);

0 commit comments

Comments
 (0)
Failed to load comments.