[core] Observe visibility changes

This commit is contained in:
John Firebaugh
2016-09-01 08:34:13 -07:00
parent 6d770cb40f
commit d6f667a5e7
7 changed files with 35 additions and 4 deletions

View File

@@ -19,7 +19,10 @@ VisibilityType Layer::getVisibility() const {
}
void Layer::setVisibility(VisibilityType value) {
if (value == getVisibility())
return;
baseImpl->visibility = value;
baseImpl->observer->onLayerVisibilityChanged(*this);
}
float Layer::getMinZoom() const {

View File

@@ -10,6 +10,7 @@ public:
virtual ~LayerObserver() = default;
virtual void onLayerFilterChanged(Layer&) {}
virtual void onLayerVisibilityChanged(Layer&) {}
virtual void onLayerPaintPropertyChanged(Layer&) {}
virtual void onLayerLayoutPropertyChanged(Layer&) {}
};

View File

@@ -506,9 +506,11 @@ void Style::onSpriteError(std::exception_ptr error) {
struct QueueSourceReloadVisitor {
UpdateBatch& updateBatch;
void operator()(CustomLayer&) { assert(false); }
void operator()(RasterLayer&) { assert(false); }
void operator()(BackgroundLayer&) { assert(false); }
// 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) {
@@ -521,6 +523,11 @@ void Style::onLayerFilterChanged(Layer& layer) {
observer->onUpdate(Update::Layout);
}
void Style::onLayerVisibilityChanged(Layer& layer) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::Layout);
}
void Style::onLayerPaintPropertyChanged(Layer&) {
observer->onUpdate(Update::RecalculateStyle | Update::Classes);
}

View File

@@ -136,6 +136,7 @@ private:
// LayerObserver implementation.
void onLayerFilterChanged(Layer&) override;
void onLayerVisibilityChanged(Layer&) override;
void onLayerPaintPropertyChanged(Layer&) override;
void onLayerLayoutPropertyChanged(Layer&) override;