summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-11 12:12:57 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-11 14:34:46 +0200
commit3bd2d0e4d7d52dc88d30081922e1708f0d5a4bcf (patch)
treef2b143fc74c48283e8ad43005c4da8050bb88042
parentf38330a9f58ca3b2664168c7830811055870bc42 (diff)
downloadqtlocation-mapboxgl-3bd2d0e4d7d52dc88d30081922e1708f0d5a4bcf.tar.gz
style::Style::getImage() returns optional<style::Image>
-rw-r--r--include/mbgl/style/image.hpp1
-rw-r--r--include/mbgl/style/style.hpp5
-rw-r--r--platform/android/src/native_map_view.cpp4
-rw-r--r--platform/darwin/src/MGLStyle.mm2
-rw-r--r--src/mbgl/map/map_impl.cpp4
-rw-r--r--src/mbgl/style/style.cpp9
-rw-r--r--src/mbgl/style/style_impl.cpp6
-rw-r--r--src/mbgl/style/style_impl.hpp2
8 files changed, 15 insertions, 18 deletions
diff --git a/include/mbgl/style/image.hpp b/include/mbgl/style/image.hpp
index 0d9c863e85..dd62d9e0ae 100644
--- a/include/mbgl/style/image.hpp
+++ b/include/mbgl/style/image.hpp
@@ -69,6 +69,7 @@ public:
class Impl;
Immutable<Impl> baseImpl;
+ explicit Image(Immutable<Impl> baseImpl_) : baseImpl(std::move(baseImpl_)) {}
};
} // namespace style
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index 2e47198930..c5e8d7f156 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -1,9 +1,9 @@
#pragma once
#include <mbgl/map/camera.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/util/geo.hpp>
-#include <mbgl/util/image.hpp>
#include <mbgl/util/immutable.hpp>
#include <string>
@@ -17,7 +17,6 @@ class FileSource;
namespace style {
class Light;
-class Image;
class Source;
class Layer;
@@ -47,7 +46,7 @@ public:
void setLight(std::unique_ptr<Light>);
// Images
- const PremultipliedImage* getImage(const std::string&) const;
+ optional<Image> getImage(const std::string&) const;
void addImage(std::unique_ptr<Image>);
void removeImage(const std::string&);
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 604fdbe2ae..db30d87a5b 100644
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -1099,8 +1099,8 @@ void NativeMapView::removeImage(JNIEnv& env, const jni::String& name) {
}
jni::Local<jni::Object<Bitmap>> NativeMapView::getImage(JNIEnv& env, const jni::String& name) {
- if (auto* image = map->getStyle().getImage(jni::Make<std::string>(env, name))) {
- return Bitmap::CreateBitmap(env, *image);
+ if (auto image = map->getStyle().getImage(jni::Make<std::string>(env, name))) {
+ return Bitmap::CreateBitmap(env, image->getImage());
}
return jni::Local<jni::Object<Bitmap>>();
}
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index cab0eaae28..6a496dc3c0 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -528,7 +528,7 @@ static_assert(6 == mbgl::util::default_styles::numOrderedStyles,
}
auto styleImage = self.rawStyle->getImage([name UTF8String]);
- return styleImage ? [[MGLImage alloc] initWithMGLStyleImage:styleImage] : nil;
+ return styleImage ? [[MGLImage alloc] initWithMGLStyleImage:&(*styleImage)] : nil;
}
#pragma mark Style transitions
diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp
index e4eb2e3e8c..af18720916 100644
--- a/src/mbgl/map/map_impl.cpp
+++ b/src/mbgl/map/map_impl.cpp
@@ -170,9 +170,7 @@ void Map::Impl::jumpTo(const CameraOptions& camera) {
}
void Map::Impl::onStyleImageMissing(const std::string& id, std::function<void()> done) {
- if (style->getImage(id) == nullptr) {
- observer.onStyleImageMissing(id);
- }
+ if (!style->getImage(id)) observer.onStyleImageMissing(id);
done();
onUpdate();
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 1814ba8adb..902cc1687c 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -60,11 +60,10 @@ const Light* Style::getLight() const {
return impl->getLight();
}
-const PremultipliedImage* Style::getImage(const std::string& name) const {
- if (auto* image = impl->getImage(name)) {
- return &(image->image);
- }
- return nullptr;
+optional<Image> Style::getImage(const std::string& name) const {
+ auto image = impl->getImage(name);
+ if (!image) return nullopt;
+ return style::Image(std::move(*image));
}
void Style::addImage(std::unique_ptr<Image> image) {
diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp
index 2d4376073d..59cb57aca6 100644
--- a/src/mbgl/style/style_impl.cpp
+++ b/src/mbgl/style/style_impl.cpp
@@ -301,10 +301,10 @@ void Style::Impl::removeImage(const std::string& id) {
images = std::move(newImages);
}
-const style::Image::Impl* Style::Impl::getImage(const std::string& id) const {
+optional<Immutable<style::Image::Impl>> Style::Impl::getImage(const std::string& id) const {
auto found = std::find_if(images->begin(), images->end(), [&id](const auto& image) { return image->id == id; });
- if (found == images->end()) return nullptr;
- return found->get();
+ if (found == images->end()) return nullopt;
+ return *found;
}
void Style::Impl::setObserver(style::Observer* observer_) {
diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp
index f7dc7af293..c16b82e90b 100644
--- a/src/mbgl/style/style_impl.hpp
+++ b/src/mbgl/style/style_impl.hpp
@@ -78,7 +78,7 @@ public:
void setLight(std::unique_ptr<Light>);
Light* getLight() const;
- const style::Image::Impl* getImage(const std::string&) const;
+ optional<Immutable<style::Image::Impl>> getImage(const std::string&) const;
void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);