Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] When a layer is added, reload its source's tiles #8954

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ namespace style {

static Observer nullObserver;

struct QueueSourceReloadVisitor {
UpdateBatch& updateBatch;

// No need to reload sources for these types; their visibility can change but
// they don't participate in layout.
void operator()(CustomLayer&) {}
void operator()(RasterLayer&) {}
void operator()(BackgroundLayer&) {}

template <class VectorLayer>
void operator()(VectorLayer& layer) {
updateBatch.sourceIDs.insert(layer.getSourceID());
}
};

Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio)
: scheduler(scheduler_),
fileSource(fileSource_),
Expand Down Expand Up @@ -248,6 +263,7 @@ Layer* Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> befor
}

layer->baseImpl->setObserver(this);
layer->accept(QueueSourceReloadVisitor { updateBatch });

auto added = layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get();
renderLayers.emplace(before ? findRenderLayer(*before) : renderLayers.end(), added->baseImpl->createRenderLayer());
Expand Down Expand Up @@ -726,21 +742,6 @@ void Style::onSpriteError(std::exception_ptr error) {
observer->onResourceError(error);
}

struct QueueSourceReloadVisitor {
UpdateBatch& updateBatch;

// No need to reload sources for these types; their visibility can change but
// they don't participate in layout.
void operator()(CustomLayer&) {}
void operator()(RasterLayer&) {}
void operator()(BackgroundLayer&) {}

template <class VectorLayer>
void operator()(VectorLayer& layer) {
updateBatch.sourceIDs.insert(layer.getSourceID());
}
};

void Style::onLayerFilterChanged(Layer& layer) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::Repaint);
Expand Down