diff options
Diffstat (limited to 'src/mbgl/style')
-rw-r--r-- | src/mbgl/style/observer.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/source_observer.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/sources/vector_source.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/style/style_impl.cpp | 48 | ||||
-rw-r--r-- | src/mbgl/style/style_impl.hpp | 6 |
5 files changed, 50 insertions, 29 deletions
diff --git a/src/mbgl/style/observer.hpp b/src/mbgl/style/observer.hpp index ea19c599e9..d9dee0344b 100644 --- a/src/mbgl/style/observer.hpp +++ b/src/mbgl/style/observer.hpp @@ -13,8 +13,8 @@ public: virtual void onStyleLoading() {} virtual void onStyleLoaded() {} virtual void onUpdate(Update) {} - virtual void onStyleError(std::exception_ptr) {} - virtual void onResourceError(std::exception_ptr) {} + virtual void onStyleError(std::exception_ptr, EventSeverity = EventSeverity::Error) {} + virtual void onResourceError(std::exception_ptr, EventSeverity = EventSeverity::Error) {} }; } // namespace style diff --git a/src/mbgl/style/source_observer.hpp b/src/mbgl/style/source_observer.hpp index c99eda955e..610897c4ce 100644 --- a/src/mbgl/style/source_observer.hpp +++ b/src/mbgl/style/source_observer.hpp @@ -1,5 +1,7 @@ #pragma once +#include <mbgl/util/event.hpp> + #include <exception> namespace mbgl { @@ -13,7 +15,7 @@ public: virtual void onSourceLoaded(Source&) {} virtual void onSourceChanged(Source&) {} - virtual void onSourceError(Source&, std::exception_ptr) {} + virtual void onSourceError(Source&, std::exception_ptr, EventSeverity = EventSeverity::Error) {} // Source description needs to be reloaded virtual void onSourceDescriptionChanged(Source&) {} diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp index ccdd453c75..b7ba869384 100644 --- a/src/mbgl/style/sources/vector_source.cpp +++ b/src/mbgl/style/sources/vector_source.cpp @@ -4,6 +4,7 @@ #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/tileset.hpp> #include <mbgl/storage/file_source.hpp> +#include <mbgl/storage/resource_error.hpp> #include <mbgl/util/mapbox.hpp> #include <mbgl/util/constants.hpp> @@ -46,17 +47,21 @@ void VectorSource::loadDescription(FileSource& fileSource) { const std::string& url = urlOrTileset.get<std::string>(); req = fileSource.request(Resource::source(url), [this, url](Response res) { - if (res.error) { - observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message))); - } else if (res.notModified) { + if (!res.error && res.notModified) { return; - } else if (res.noContent) { - observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON"))); + } else if (res.error || res.noContent) { + const auto severity = loaded ? EventSeverity::Warning : EventSeverity::Error; + const std::string& message = + res.error ? res.error->message : "unexpectedly empty TileJSON"; + const util::ResourceError err(message, ResourceKind::Source, res.error->status, url); + observer->onSourceError(*this, std::make_exception_ptr(err), severity); } else { conversion::Error error; optional<Tileset> tileset = conversion::convertJSON<Tileset>(*res.data, error); if (!tileset) { - observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(error.message))); + const auto severity = loaded ? EventSeverity::Warning : EventSeverity::Error; + observer->onSourceError( + *this, std::make_exception_ptr(std::runtime_error(error.message)), severity); return; } diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index 9cc2588ca7..f469769406 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -19,6 +19,7 @@ #include <mbgl/storage/file_source.hpp> #include <mbgl/storage/resource.hpp> #include <mbgl/storage/response.hpp> +#include <mbgl/storage/resource_error.hpp> namespace mbgl { namespace style { @@ -62,10 +63,15 @@ void Style::Impl::loadURL(const std::string& url_) { } if (res.error) { - const std::string message = "loading style failed: " + res.error->message; - Log::Error(Event::Setup, message.c_str()); - observer->onStyleError(std::make_exception_ptr(util::StyleLoadException(message))); - observer->onResourceError(std::make_exception_ptr(std::runtime_error(res.error->message))); + const std::string message = "Failed to load style: " + res.error->message; + const auto severity = loaded ? EventSeverity::Warning : EventSeverity::Error; + Log::Record(severity, Event::Setup, message.c_str()); + observer->onStyleError(std::make_exception_ptr(util::StyleLoadException(message)), + severity); + observer->onResourceError( + std::make_exception_ptr(util::ResourceError(res.error->message, ResourceKind::Style, + res.error->status, url)), + severity); } else if (res.notModified || res.noContent) { return; } else { @@ -111,7 +117,6 @@ void Style::Impl::parse(const std::string& json_) { defaultPitch = parser.pitch; setLight(std::make_unique<Light>(parser.light)); - spriteLoaded = false; spriteLoader->load(parser.spriteURL, scheduler, fileSource); glyphURL = parser.glyphURL; @@ -264,7 +269,7 @@ bool Style::Impl::isLoaded() const { return false; } - if (!spriteLoaded) { + if (!isSpriteLoaded()) { return false; } @@ -277,6 +282,10 @@ bool Style::Impl::isLoaded() const { return true; } +bool Style::Impl::isSpriteLoaded() const { + return spriteLoader->isLoaded(); +} + void Style::Impl::addImage(std::unique_ptr<style::Image> image) { images.remove(image->getID()); // We permit using addImage to update. images.add(std::move(image)); @@ -306,12 +315,16 @@ void Style::Impl::onSourceChanged(Source& source) { observer->onUpdate(Update::Repaint); } -void Style::Impl::onSourceError(Source& source, std::exception_ptr error) { - lastError = error; - Log::Error(Event::Style, "Failed to load source %s: %s", - source.getID().c_str(), util::toString(error).c_str()); - observer->onSourceError(source, error); - observer->onResourceError(error); +void Style::Impl::onSourceError(Source& source, + std::exception_ptr error, + const EventSeverity severity) { + if (severity == EventSeverity::Error) { + lastError = error; + } + Log::Record(severity, Event::Style, "Failed to load source %s: %s", source.getID().c_str(), + util::toString(error).c_str()); + observer->onSourceError(source, error, severity); + observer->onResourceError(error, severity); } void Style::Impl::onSourceDescriptionChanged(Source& source) { @@ -326,14 +339,15 @@ void Style::Impl::onSpriteLoaded(std::vector<std::unique_ptr<Image>>&& images_) for (auto& image : images_) { addImage(std::move(image)); } - spriteLoaded = true; observer->onUpdate(Update::Repaint); // For *-pattern properties. } -void Style::Impl::onSpriteError(std::exception_ptr error) { - lastError = error; - Log::Error(Event::Style, "Failed to load sprite: %s", util::toString(error).c_str()); - observer->onResourceError(error); +void Style::Impl::onSpriteError(std::exception_ptr error, const EventSeverity severity) { + if (severity == EventSeverity::Error) { + lastError = error; + } + Log::Record(severity, Event::Style, "Failed to load sprite: %s", util::toString(error).c_str()); + observer->onResourceError(error, severity); } void Style::Impl::onLayerChanged(Layer& layer) { diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp index 76f244d5a4..4eead24ca1 100644 --- a/src/mbgl/style/style_impl.hpp +++ b/src/mbgl/style/style_impl.hpp @@ -48,6 +48,7 @@ public: void setObserver(Observer*); bool isLoaded() const; + bool isSpriteLoaded() const; std::exception_ptr getLastError() const { return lastError; @@ -94,7 +95,6 @@ public: bool mutated = false; bool loaded = false; - bool spriteLoaded = false; private: void parse(const std::string&); @@ -124,12 +124,12 @@ private: // SpriteLoaderObserver implementation. void onSpriteLoaded(std::vector<std::unique_ptr<Image>>&&) override; - void onSpriteError(std::exception_ptr) override; + void onSpriteError(std::exception_ptr, EventSeverity) override; // SourceObserver implementation. void onSourceLoaded(Source&) override; void onSourceChanged(Source&) override; - void onSourceError(Source&, std::exception_ptr) override; + void onSourceError(Source&, std::exception_ptr, EventSeverity) override; void onSourceDescriptionChanged(Source&) override; // LayerObserver implementation. |