diff options
author | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2016-09-21 11:04:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-21 11:04:32 +0200 |
commit | eb97dbe383ca7697feab5860995b97181c39c607 (patch) | |
tree | 70bdd7b6ebea32aec132413fa703e92a2a0f63d0 /platform/android/src/jni.cpp | |
parent | 3b546b964609d0f596dac32e155b1489bb85645e (diff) | |
download | qtlocation-mapboxgl-eb97dbe383ca7697feab5860995b97181c39c607.tar.gz |
[android] Sources: peer model, mutability (#6054)
Diffstat (limited to 'platform/android/src/jni.cpp')
-rwxr-xr-x | platform/android/src/jni.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 6752c1bbdb..1a5efce726 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -22,6 +22,7 @@ #include <mbgl/map/camera.hpp> #include <mbgl/annotation/annotation.hpp> #include <mbgl/style/layer.hpp> +#include <mbgl/style/source.hpp> #include <mbgl/sprite/sprite_image.hpp> #include <mbgl/platform/event.hpp> #include <mbgl/platform/log.hpp> @@ -1185,23 +1186,35 @@ void nativeRemoveLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, j } } -void nativeAddSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id, jni::jobject* jsource) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddSource"); +jni::jobject* nativeGetSource(JNIEnv *env, jni::jobject* obj, jni::jlong nativeMapViewPtr, jni::jstring* sourceId) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetSource"); + + assert(env); assert(nativeMapViewPtr != 0); - assert(id != nullptr); - assert(jsource != nullptr); - //Convert - mbgl::optional<std::unique_ptr<mbgl::style::Source>> source = convertToNativeSource( - *env, - jni::Object<jni::jobject>(jsource), jni::String(id) - ); + //Get the native map peer + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - //Add to map view - if (source) { - NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); - nativeMapView->getMap().addSource(std::move(*source)); + //Find the source + mbgl::style::Source* coreSource = nativeMapView->getMap().getSource(std_string_from_jstring(env, sourceId)); + if (!coreSource) { + mbgl::Log::Debug(mbgl::Event::JNI, "No source found"); + return jni::Object<Source>(); } + + //Create and return the source's native peer + return createJavaSourcePeer(*env, nativeMapView->getMap(), *coreSource); +} + +void nativeAddSource(JNIEnv *env, jni::jobject* obj, jni::jlong nativeMapViewPtr, jni::jlong nativeSourcePtr) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddSource"); + assert(nativeMapViewPtr != 0); + assert(nativeSourcePtr != 0); + + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + Source *source = reinterpret_cast<Source *>(nativeSourcePtr); + + nativeMapView->getMap().addSource(source->releaseCoreSource()); } void nativeRemoveSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) { @@ -1687,6 +1700,7 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { java::registerNatives(env); registerNativeLayers(env); + registerNativeSources(env); latLngClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/geometry/LatLng"); latLngClass = jni::NewGlobalRef(env, latLngClass).release(); @@ -1838,7 +1852,8 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { MAKE_NATIVE_METHOD(nativeGetLayer, "(JLjava/lang/String;)Lcom/mapbox/mapboxsdk/style/layers/Layer;"), MAKE_NATIVE_METHOD(nativeAddLayer, "(JJLjava/lang/String;)V"), MAKE_NATIVE_METHOD(nativeRemoveLayer, "(JLjava/lang/String;)V"), - MAKE_NATIVE_METHOD(nativeAddSource, "(JLjava/lang/String;Lcom/mapbox/mapboxsdk/style/sources/Source;)V"), + MAKE_NATIVE_METHOD(nativeGetSource, "(JLjava/lang/String;)Lcom/mapbox/mapboxsdk/style/sources/Source;"), + MAKE_NATIVE_METHOD(nativeAddSource, "(JJ)V"), MAKE_NATIVE_METHOD(nativeRemoveSource, "(JLjava/lang/String;)V"), MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V"), MAKE_NATIVE_METHOD(nativeScheduleTakeSnapshot, "(J)V"), |