Skip to content

Commit

Permalink
fixes mapbox#1675: abstract annotation tile refresh check/render; tri…
Browse files Browse the repository at this point in the history
…gger post-sprite/sprite store load
  • Loading branch information
incanus committed Sep 9, 2015
1 parent cf175c6 commit a1656a5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/mbgl/map/annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AnnotationManager : private util::noncopyable {
~AnnotationManager();

void markStaleTiles(std::unordered_set<TileID, TileID::Hash>);
size_t getStaleTileCount() const { return staleTiles.size(); }
std::unordered_set<TileID, TileID::Hash> resetStaleTiles();

void setDefaultPointAnnotationSymbol(const std::string& symbol);
Expand Down
10 changes: 8 additions & 2 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)

updateFlags |= Update::DefaultTransition | Update::Classes | Update::Zoom;
asyncUpdate->send();
}

auto staleTiles = data.getAnnotationManager()->resetStaleTiles();
if (!staleTiles.empty()) {
void MapContext::updateAnnotationTilesIfNeeded() {
if (data.getAnnotationManager()->getStaleTileCount()) {
auto staleTiles = data.getAnnotationManager()->resetStaleTiles();
updateAnnotationTiles(staleTiles);
}
}
Expand Down Expand Up @@ -417,4 +419,8 @@ void MapContext::onResourceLoadingFailed(std::exception_ptr error) {
}
}

void MapContext::onSpriteStoreLoaded() {
updateAnnotationTilesIfNeeded();
}

}
2 changes: 2 additions & 0 deletions src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MapContext : public Style::Observer {
bool isLoaded() const;

double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol);
void updateAnnotationTilesIfNeeded();
void updateAnnotationTiles(const std::unordered_set<TileID, TileID::Hash>&);

void setSourceTileCacheSize(size_t size);
Expand All @@ -66,6 +67,7 @@ class MapContext : public Style::Observer {
// Style::Observer implementation.
void onTileDataChanged() override;
void onResourceLoadingFailed(std::exception_ptr error) override;
void onSpriteStoreLoaded() override;

private:
// Update the state indicated by the accumulated Update flags, then render.
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ void Style::onSpriteLoaded(const Sprites& sprites) {
// Add all sprite images to the SpriteStore object
spriteStore->setSprites(sprites);

if (observer) {
observer->onSpriteStoreLoaded();
}

shouldReparsePartialTiles = true;
emitTileDataChanged();
}
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Style : public GlyphStore::Observer,
virtual ~Observer() = default;

virtual void onTileDataChanged() = 0;
virtual void onSpriteStoreLoaded() = 0;
virtual void onResourceLoadingFailed(std::exception_ptr error) = 0;
};

Expand Down
4 changes: 4 additions & 0 deletions test/style/resource_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class MockMapContext : public Style::Observer {
callback_(error);
}

void onSpriteStoreLoaded() override {
// no-op
}

private:
MapData data_;
Transform transform_;
Expand Down

0 comments on commit a1656a5

Please sign in to comment.