Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin committed Mar 23, 2020
1 parent 6139688 commit 382bd8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ MapSnapshotter::~MapSnapshotter() {
weakScheduler->schedule([ptr = snapshotter.release()]() mutable {
if (ptr) {
delete ptr;
ptr = nullptr;
}
});
}
Expand Down Expand Up @@ -191,10 +190,10 @@ void MapSnapshotter::onStyleImageMissing(const std::string& imageName) {

void MapSnapshotter::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint index) {
assert(nativeLayerPtr != 0);
auto layers = snapshotter->getStyle().getLayers();
const auto layers = snapshotter->getStyle().getLayers();
auto* layer = reinterpret_cast<Layer*>(nativeLayerPtr);
// Check index
int numLayers = layers.size() - 1;
const int numLayers = layers.size() - 1;
if (index > numLayers || index < 0) {
Log::Error(Event::JNI, "Index out of range: %i", index);
jni::ThrowNew(env,
Expand Down Expand Up @@ -229,27 +228,27 @@ void MapSnapshotter::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni:
auto* layer = reinterpret_cast<Layer*>(nativeLayerPtr);

// Find the sibling
auto layers = snapshotter->getStyle().getLayers();
const auto layers = snapshotter->getStyle().getLayers();
auto siblingId = jni::Make<std::string>(env, above);

size_t index = 0;
for (auto l : layers) {
for (auto* l : layers) {
++index;
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()) {
if (index > 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());
} else if (index + 1 < layers.size()) {
} else if (index < layers.size()) {
// Place before the sibling
before = {layers.at(index + 1)->getID()};
before = {layers.at(index)->getID()};
}

// Add the layer
Expand Down Expand Up @@ -309,13 +308,13 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
const jni::String&>,
"nativeInitialize",
"finalize",
METHOD(&MapSnapshotter::setStyleUrl, "nativeSetStyleUrl"),
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
METHOD(&MapSnapshotter::addLayerAt, "nativeAddLayerAt"),
METHOD(&MapSnapshotter::addLayerBelow, "nativeAddLayerBelow"),
METHOD(&MapSnapshotter::addLayerAbove, "nativeAddLayerAbove"),
METHOD(&MapSnapshotter::addSource, "nativeAddSource"),
METHOD(&MapSnapshotter::addImages, "nativeAddImages"),
METHOD(&MapSnapshotter::setStyleJson, "nativeSetStyleJson"),
METHOD(&MapSnapshotter::setStyleJson, "setStyleJson"),
METHOD(&MapSnapshotter::setSize, "setSize"),
METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"),
METHOD(&MapSnapshotter::setRegion, "setRegion"),
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/snapshotter/map_snapshotter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MapSnapshotter final : public mbgl::MapSnapshotterObserver {
jni::jboolean showLogo,
const jni::String& localIdeographFontFamily);

virtual ~MapSnapshotter();
virtual ~MapSnapshotter() override;

void setStyleUrl(JNIEnv&, const jni::String& styleURL);

Expand Down

0 comments on commit 382bd8b

Please sign in to comment.