style::Style::getImage() returns optional<style::Image>
This commit is contained in:
@@ -69,6 +69,7 @@ public:
|
||||
|
||||
class Impl;
|
||||
Immutable<Impl> baseImpl;
|
||||
explicit Image(Immutable<Impl> baseImpl_) : baseImpl(std::move(baseImpl_)) {}
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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>>();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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_) {
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user