From ec7588f1fd2dff16acef6dc88d06ac251eba6fff Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 21 Apr 2015 17:36:50 -0700 Subject: [PATCH] Implement Style::isLoaded --- src/mbgl/map/map_context.cpp | 2 +- src/mbgl/map/source.cpp | 14 ++++++++++++++ src/mbgl/map/source.hpp | 1 + src/mbgl/style/style.cpp | 20 ++++++++++++++++++++ src/mbgl/style/style.hpp | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 51a24b11b..eb3039b7e 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -236,7 +236,7 @@ void MapContext::render() { painter->render(*style, data.getTransformState(), data.getAnimationTime()); - if (data.mode == MapMode::Still && data.callback /* && loaded() */) { + if (data.mode == MapMode::Still && data.callback && style->isLoaded() && getSprite()->isLoaded()) { auto image = view.readStillImage(); // We are moving the callback out of the way and empty it in case the callback function diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 4e8c66ffb..7bdd1e253 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -118,6 +118,20 @@ Source::Source() Source::~Source() {} +bool Source::isLoaded() const { + if (!loaded) { + return false; + } + + for (const auto& tile : tiles) { + if (tile.second->data->state != TileData::State::parsed) { + return false; + } + } + + return true; +} + // Note: This is a separate function that must be called exactly once after creation // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 0bae1e408..342d414e2 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -60,6 +60,7 @@ public: void load(const std::string& accessToken, Environment&, std::function callback); + bool isLoaded() const; void load(MapData&, Environment&, std::function callback); void update(MapData&, diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 0a2a53075..4f26ee010 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -86,4 +86,24 @@ void Style::loadJSON(const uint8_t *const data) { glyph_url = parser.getGlyphURL(); } +bool Style::isLoaded() const { + // TODO: move loading into Style +// if (!loaded) { +// return false; +// } + + for (const auto& source : sources) { + if (!source->isLoaded()) { + return false; + } + } + + // TODO: move sprite into Style +// if (sprite && !sprite.isLoaded()) { +// return false; +// } + + return true; +} + } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index dde21173f..849376b56 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -24,6 +24,7 @@ public: ~Style(); void loadJSON(const uint8_t *const data); + bool isLoaded() const; void cascade(const std::vector&); void recalculate(float z, TimePoint now);