diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 764ff24ed..f8e082f69 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -30,7 +30,6 @@ class LayerDescription; class Sprite; class Style; class StyleLayer; -class StyleSource; class TexturePool; class FileSource; class View; @@ -175,7 +174,6 @@ private: void setup(); void updateTiles(); - void updateSources(); // Triggered by triggerUpdate(); void update(); @@ -249,8 +247,6 @@ private: const std::unique_ptr data; - std::set> activeSources; - std::atomic updated; std::mutex mutexTask; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ac2be3f06..5db4d7e51 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -90,7 +90,6 @@ Map::~Map() { "MapandMain"); // Explicitly reset all pointers. - activeSources.clear(); sprite.reset(); glyphStore.reset(); style.reset(); @@ -129,11 +128,6 @@ void Map::start(bool startPaused) { // Remove all of these to make sure they are destructed in the correct thread. style.reset(); - // Since we don't have a stylesheet anymore, this will disable all Sources and cancel - // their associated requests. - updateSources(); - assert(activeSources.empty()); - // It's now safe to destroy/join the workers since there won't be any more callbacks that // could dispatch to the worker pool. workers.reset(); @@ -624,9 +618,10 @@ LatLngBounds Map::getBoundsForAnnotations(const std::vector& annotatio void Map::updateAnnotationTiles(const std::vector& ids) { assert(Environment::currentlyOn(ThreadType::Map)); - for (const auto &source : activeSources) { + if (!style) return; + for (const auto &source : style->sources) { if (source->info.type == SourceType::Annotations) { - source->source->invalidateTiles(*this, ids); + source->invalidateTiles(*this, ids); return; } } @@ -689,45 +684,11 @@ Duration Map::getDefaultTransitionDuration() { return data->getDefaultTransitionDuration(); } -void Map::updateSources() { - assert(Environment::currentlyOn(ThreadType::Map)); - - // First, disable all existing sources. - for (const auto& source : activeSources) { - source->enabled = false; - } - - // Then, reenable all of those that we actually use when drawing this layer. - if (style) { - for (const auto& layer : style->layers) { - if (layer->bucket && layer->bucket->style_source) { - (*activeSources.emplace(layer->bucket->style_source).first)->enabled = true; - } - } - } - - // Then, construct or destroy the actual source object, depending on enabled state. - for (const auto& source : activeSources) { - if (source->enabled) { - if (!source->source) { - source->source = std::make_shared(source->info); - source->source->load(*this, *env); - } - } else { - source->source.reset(); - } - } - - // Finally, remove all sources that are disabled. - util::erase_if(activeSources, [](util::ptr source){ - return !source->enabled; - }); -} - void Map::updateTiles() { assert(Environment::currentlyOn(ThreadType::Map)); - for (const auto& source : activeSources) { - source->source->update(*this, getWorker(), style, *glyphAtlas, *glyphStore, + if (!style) return; + for (const auto& source : style->sources) { + source->update(*this, getWorker(), style, *glyphAtlas, *glyphStore, *spriteAtlas, getSprite(), *texturePool, [this]() { assert(Environment::currentlyOn(ThreadType::Map)); triggerUpdate(); @@ -779,6 +740,10 @@ void Map::loadStyleJSON(const std::string& json, const std::string& base) { const std::string glyphURL = util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken()); glyphStore->setURL(glyphURL); + for (const auto& source : style->sources) { + source->load(*this, *env); + } + triggerUpdate(Update::Zoom); } @@ -821,8 +786,6 @@ void Map::prepare() { style->recalculate(state.getNormalizedZoom(), now); } - updateSources(); - // Allow the sprite atlas to potentially pull new sprite images if needed. spriteAtlas->resize(state.getPixelRatio()); spriteAtlas->setSprite(getSprite()); @@ -843,8 +806,8 @@ void Map::render() { assert(style); assert(painter); - painter->render(*style, activeSources, - state, data->getAnimationTime()); + + painter->render(*style, state, data->getAnimationTime()); // Schedule another rerender when we definitely need a next frame. if (transform.needsTransition() || style->hasTransitions()) { diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index dbe88e654..0b8760b56 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -27,8 +27,7 @@ namespace mbgl { -Source::Source(SourceInfo& info_) - : info(info_) +Source::Source() { } diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 5c38636a2..0831f7b0b 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -32,7 +32,7 @@ struct box; class Source : public std::enable_shared_from_this, private util::noncopyable { public: - Source(SourceInfo&); + Source(); void load(Map &, Environment &); void update(Map &, uv::worker &, util::ptr