summaryrefslogtreecommitdiff
path: root/platform/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src')
-rwxr-xr-xplatform/android/src/jni.cpp19
-rw-r--r--platform/android/src/style/sources/source.cpp8
-rw-r--r--platform/android/src/style/sources/source.hpp7
3 files changed, 31 insertions, 3 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 6c346ec931..44a1915b4f 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -1170,11 +1170,23 @@ void nativeAddSource(JNIEnv *env, jni::jobject* obj, jni::jlong nativeMapViewPtr
}
}
-void nativeRemoveSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) {
+void nativeRemoveSourceById(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) {
+ assert(nativeMapViewPtr != 0);
+ NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
+ try {
+ nativeMapView->getMap().removeSource(std_string_from_jstring(env, id));
+ } catch (const std::runtime_error& error) {
+ jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what());
+ }
+}
+
+void nativeRemoveSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong sourcePtr) {
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
+ mbgl::android::Source *source = reinterpret_cast<mbgl::android::Source *>(sourcePtr);
try {
- nativeMapView->getMap().removeSource(std_string_from_jstring(env, id));
+ std::unique_ptr<mbgl::style::Source> coreSource = nativeMapView->getMap().removeSource(source->get().getID());
+ source->setSource(std::move(coreSource));
} catch (const std::runtime_error& error) {
jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what());
}
@@ -1861,7 +1873,8 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
MAKE_NATIVE_METHOD(nativeRemoveLayer, "(JJ)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(nativeRemoveSourceById, "(JLjava/lang/String;)V"),
+ MAKE_NATIVE_METHOD(nativeRemoveSource, "(JJ)V"),
MAKE_NATIVE_METHOD(nativeAddImage, "(JLjava/lang/String;IIF[B)V"),
MAKE_NATIVE_METHOD(nativeRemoveImage, "(JLjava/lang/String;)V"),
MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V"),
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp
index 24fce79e94..36023d2ff7 100644
--- a/platform/android/src/style/sources/source.cpp
+++ b/platform/android/src/style/sources/source.cpp
@@ -31,6 +31,14 @@ namespace android {
Source::~Source() {
}
+ 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());
}
diff --git a/platform/android/src/style/sources/source.hpp b/platform/android/src/style/sources/source.hpp
index b24dc891b4..0e5d354d93 100644
--- a/platform/android/src/style/sources/source.hpp
+++ b/platform/android/src/style/sources/source.hpp
@@ -32,6 +32,13 @@ public:
virtual ~Source();
+ /**
+ * Set core source (ie return ownership after remove)
+ */
+ void setSource(std::unique_ptr<style::Source>);
+
+ style::Source& get();
+
void addToMap(mbgl::Map&);
virtual jni::jobject* createJavaPeer(jni::JNIEnv&) = 0;