diff --git a/src/mbgl/map/annotation.hpp b/src/mbgl/map/annotation.hpp index 745fc779cde..5adec162f74 100644 --- a/src/mbgl/map/annotation.hpp +++ b/src/mbgl/map/annotation.hpp @@ -52,6 +52,7 @@ class AnnotationManager : private util::noncopyable { ~AnnotationManager(); void markStaleTiles(std::unordered_set); + size_t getStaleTileCount() const { return staleTiles.size(); } std::unordered_set resetStaleTiles(); void setDefaultPointAnnotationSymbol(const std::string& symbol); diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 94aedb46da6..0ebcd73f8b4 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -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); } } @@ -417,4 +419,8 @@ void MapContext::onResourceLoadingFailed(std::exception_ptr error) { } } +void MapContext::onSpriteStoreLoaded() { + updateAnnotationTilesIfNeeded(); +} + } diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index f1bfb01e442..449a0f1d1ce 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -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&); void setSourceTileCacheSize(size_t size); @@ -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. diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 76862153010..d4c9bd4e560 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -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(); } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index cbc0ee2db2f..3f9696ffbf3 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -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; }; diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index 0562434586d..5ed09065a14 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -63,6 +63,10 @@ class MockMapContext : public Style::Observer { callback_(error); } + void onSpriteStoreLoaded() override { + // no-op + } + private: MapData data_; Transform transform_;