summaryrefslogtreecommitdiff
path: root/platform/android/src
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-02-24 17:18:26 +0200
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-02-28 09:33:04 -0800
commitdc21396d71ea28b736ee6fb3dcd476fed80fbd5d (patch)
tree7ffda504ae73e9ddb4998e8290601bba5ddcfa9f /platform/android/src
parent3040d407723ed8a8e2dfa27ad0ba49f534772342 (diff)
downloadqtlocation-mapboxgl-dc21396d71ea28b736ee6fb3dcd476fed80fbd5d.tar.gz
[android] insert layer above
Diffstat (limited to 'platform/android/src')
-rwxr-xr-xplatform/android/src/native_map_view.cpp38
-rwxr-xr-xplatform/android/src/native_map_view.hpp2
2 files changed, 40 insertions, 0 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 5587300c1c..34e18754e9 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -779,6 +779,43 @@ void NativeMapView::addLayer(JNIEnv& env, jlong nativeLayerPtr, jni::String befo
}
}
+void NativeMapView::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, jni::String above) {
+ assert(nativeLayerPtr != 0);
+
+ Layer *layer = reinterpret_cast<Layer *>(nativeLayerPtr);
+
+ // Find the sibling
+ auto layers = map->getLayers();
+ auto siblingId = jni::Make<std::string>(env, above);
+
+ size_t index = 0;
+ for (auto l : layers) {
+ if (l->getID() == siblingId) {
+ break;
+ }
+ index++;
+ }
+
+ // Check if we found a sibling to place before
+ mbgl::optional<std::string> before;
+ if (index + 1 > layers.size()) {
+ // Not found
+ jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"),
+ std::string("Could not find layer: ").append(siblingId).c_str());
+ return;
+ } else if (index + 1 < layers.size()) {
+ // Place before the sibling
+ before = { layers.at(index + 1)->getID() };
+ }
+
+ // Add the layer
+ try {
+ layer->addToMap(*map, before);
+ } catch (const std::runtime_error& error) {
+ jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), error.what());
+ }
+}
+
/**
* Remove by layer id.
*/
@@ -1380,6 +1417,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::getLayers, "nativeGetLayers"),
METHOD(&NativeMapView::getLayer, "nativeGetLayer"),
METHOD(&NativeMapView::addLayer, "nativeAddLayer"),
+ METHOD(&NativeMapView::addLayerAbove, "nativeAddLayerAbove"),
METHOD(&NativeMapView::removeLayerById, "nativeRemoveLayerById"),
METHOD(&NativeMapView::removeLayer, "nativeRemoveLayer"),
METHOD(&NativeMapView::getSources, "nativeGetSources"),
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 7b3694e73c..9f02f4a25c 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -207,6 +207,8 @@ public:
void addLayer(JNIEnv&, jlong, jni::String);
+ void addLayerAbove(JNIEnv&, jlong, jni::String);
+
jni::Object<Layer> removeLayerById(JNIEnv&, jni::String);
void removeLayer(JNIEnv&, jlong);