Implement Style::isLoaded

This commit is contained in:
John Firebaugh
2015-04-21 17:36:50 -07:00
parent 6c7a01a503
commit ec7588f1fd
5 changed files with 37 additions and 1 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -60,6 +60,7 @@ public:
void load(const std::string& accessToken,
Environment&,
std::function<void()> callback);
bool isLoaded() const;
void load(MapData&, Environment&, std::function<void()> callback);
void update(MapData&,

View File

@@ -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;
}
}

View File

@@ -24,6 +24,7 @@ public:
~Style();
void loadJSON(const uint8_t *const data);
bool isLoaded() const;
void cascade(const std::vector<std::string>&);
void recalculate(float z, TimePoint now);