diff options
Diffstat (limited to 'src/mbgl/map/map.cpp')
-rw-r--r-- | src/mbgl/map/map.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index f4e994c931..24ae5643ee 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -16,6 +16,7 @@ #include <mbgl/storage/file_source.hpp> #include <mbgl/storage/resource.hpp> #include <mbgl/storage/response.hpp> +#include <mbgl/util/exception.hpp> #include <mbgl/util/projection.hpp> #include <mbgl/util/math.hpp> #include <mbgl/util/exception.hpp> @@ -58,10 +59,10 @@ public: ConstrainMode, ViewportMode); - void onSourceAttributionChanged(style::Source&, const std::string&) override; + void onSourceChanged(style::Source&) override; void onUpdate(Update) override; void onStyleLoaded() override; - void onStyleError() override; + void onStyleError(std::exception_ptr) override; void onResourceError(std::exception_ptr) override; void render(View&); @@ -70,6 +71,7 @@ public: void loadStyleJSON(const std::string&); Map& map; + MapObserver& observer; Backend& backend; FileSource& fileSource; Scheduler& scheduler; @@ -134,10 +136,11 @@ Map::Impl::Impl(Map& map_, ConstrainMode constrainMode_, ViewportMode viewportMode_) : map(map_), + observer(backend_), backend(backend_), fileSource(fileSource_), scheduler(scheduler_), - transform([this](MapChange change) { backend.notifyMapChange(change); }, + transform(observer, constrainMode_, viewportMode_), mode(mode_), @@ -264,10 +267,10 @@ void Map::Impl::render(View& view) { if (mode == MapMode::Continuous) { if (renderState == RenderState::Never) { - backend.notifyMapChange(MapChangeWillStartRenderingMap); + observer.onWillStartRenderingMap(); } - backend.notifyMapChange(MapChangeWillStartRenderingFrame); + observer.onWillStartRenderingFrame(); FrameData frameData { timePoint, pixelRatio, @@ -282,18 +285,16 @@ void Map::Impl::render(View& view) { painter->cleanup(); - backend.notifyMapChange(style->isLoaded() ? - MapChangeDidFinishRenderingFrameFullyRendered : - MapChangeDidFinishRenderingFrame); + observer.onDidFinishRenderingFrame(style->isLoaded() ? MapObserver::RenderMode::Full : MapObserver::RenderMode::Partial); if (!style->isLoaded()) { renderState = RenderState::Partial; } else if (renderState != RenderState::Fully) { renderState = RenderState::Fully; - backend.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered); + observer.onDidFinishRenderingMap(MapObserver::RenderMode::Full); if (loading) { loading = false; - backend.notifyMapChange(MapChangeDidFinishLoadingMap); + observer.onDidFinishLoadingMap(); } } @@ -341,7 +342,7 @@ void Map::setStyleURL(const std::string& url) { impl->loading = true; - impl->backend.notifyMapChange(MapChangeWillStartLoadingMap); + impl->observer.onWillStartLoadingMap(); impl->styleRequest = nullptr; impl->styleURL = url; @@ -364,11 +365,14 @@ void Map::setStyleURL(const std::string& url) { if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound && util::mapbox::isMapboxURL(impl->styleURL)) { - Log::Error(Event::Setup, "style %s could not be found or is an incompatible legacy map or style", impl->styleURL.c_str()); + const std::string message = "style " + impl->styleURL + " could not be found or is an incompatible legacy map or style"; + Log::Error(Event::Setup, message.c_str()); + impl->onStyleError(std::make_exception_ptr(util::NotFoundException(message))); } else { - Log::Error(Event::Setup, "loading style failed: %s", res.error->message.c_str()); + const std::string message = "loading style failed: " + res.error->message; + Log::Error(Event::Setup, message.c_str()); + impl->onStyleError(std::make_exception_ptr(util::StyleLoadException(message))); } - impl->onStyleError(); impl->onResourceError(std::make_exception_ptr(std::runtime_error(res.error->message))); } else if (res.notModified || res.noContent) { return; @@ -385,7 +389,7 @@ void Map::setStyleJSON(const std::string& json) { impl->loading = true; - impl->backend.notifyMapChange(MapChangeWillStartLoadingMap); + impl->observer.onWillStartLoadingMap(); impl->styleURL.clear(); impl->styleJSON.clear(); @@ -1085,8 +1089,8 @@ void Map::onLowMemory() { } } -void Map::Impl::onSourceAttributionChanged(style::Source&, const std::string&) { - backend.notifyMapChange(MapChangeSourceDidChange); +void Map::Impl::onSourceChanged(style::Source& source) { + observer.onSourceChanged(source); } void Map::Impl::onUpdate(Update flags) { @@ -1095,11 +1099,11 @@ void Map::Impl::onUpdate(Update flags) { } void Map::Impl::onStyleLoaded() { - backend.notifyMapChange(MapChangeDidFinishLoadingStyle); + observer.onDidFinishLoadingStyle(); } -void Map::Impl::onStyleError() { - backend.notifyMapChange(MapChangeDidFailLoadingMap); +void Map::Impl::onStyleError(std::exception_ptr error) { + observer.onDidFailLoadingMap(error); } void Map::Impl::onResourceError(std::exception_ptr error) { |