summaryrefslogtreecommitdiff
path: root/platform/android/src
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-02-27 20:12:42 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-02-28 09:33:04 -0800
commit99786e1e3ff1cb79f6befe93e02c968e5e6b6781 (patch)
tree8a28a4e1b468f211eb535d9a2853c96f165df19d /platform/android/src
parenta9d2929819a5b4268a83e8ccd90eeb0b1f1e2f72 (diff)
downloadqtlocation-mapboxgl-99786e1e3ff1cb79f6befe93e02c968e5e6b6781.tar.gz
[android] insert layer at index
Diffstat (limited to 'platform/android/src')
-rwxr-xr-xplatform/android/src/native_map_view.cpp24
-rwxr-xr-xplatform/android/src/native_map_view.hpp2
2 files changed, 26 insertions, 0 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 986a5f6120..996fa2d7f3 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -816,6 +816,29 @@ void NativeMapView::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, jni::String
}
}
+void NativeMapView::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint index) {
+ assert(nativeLayerPtr != 0);
+
+ Layer *layer = reinterpret_cast<Layer *>(nativeLayerPtr);
+ auto layers = map->getLayers();
+
+ // Check index
+ int numLayers = layers.size() - 1;
+ if (index > numLayers || index < 0) {
+ Log::Error(Event::JNI, "Index out of range: %i", index);
+ jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"),
+ std::string("Invalid index").c_str());
+ return;
+ }
+
+ // Insert it below the current at that index
+ try {
+ layer->addToMap(*map, layers.at(index)->getID());
+ } catch (const std::runtime_error& error) {
+ jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), error.what());
+ }
+}
+
/**
* Remove by layer id.
*/
@@ -1439,6 +1462,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
+ METHOD(&NativeMapView::addLayerAt, "nativeAddLayerAt"),
METHOD(&NativeMapView::removeLayerById, "nativeRemoveLayerById"),
METHOD(&NativeMapView::removeLayerAt, "nativeRemoveLayerAt"),
METHOD(&NativeMapView::removeLayer, "nativeRemoveLayer"),
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 4c70b48e41..c38afd3e6c 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -209,6 +209,8 @@ public:
void addLayerAbove(JNIEnv&, jlong, jni::String);
+ void addLayerAt(JNIEnv&, jni::jlong, jni::jint);
+
jni::Object<Layer> removeLayerById(JNIEnv&, jni::String);
jni::Object<Layer> removeLayerAt(JNIEnv&, jni::jint);