summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-09-01 08:34:13 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-06 14:29:22 -0700
commitd6f667a5e762ce1faec80bee774b805fe7ef5e11 (patch)
tree527ae75a142d089203d971d1f909d311f3e51d7b /src/mbgl/style
parent6d770cb40f1231e202b603fcc63d3b00efc3f551 (diff)
downloadqtlocation-mapboxgl-d6f667a5e762ce1faec80bee774b805fe7ef5e11.tar.gz
[core] Observe visibility changes
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/layer.cpp3
-rw-r--r--src/mbgl/style/layer_observer.hpp1
-rw-r--r--src/mbgl/style/style.cpp13
-rw-r--r--src/mbgl/style/style.hpp1
4 files changed, 15 insertions, 3 deletions
diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp
index 4d4e793ec0..a78f8c29bc 100644
--- a/src/mbgl/style/layer.cpp
+++ b/src/mbgl/style/layer.cpp
@@ -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 {
diff --git a/src/mbgl/style/layer_observer.hpp b/src/mbgl/style/layer_observer.hpp
index 1d3d1aef46..4182a1b812 100644
--- a/src/mbgl/style/layer_observer.hpp
+++ b/src/mbgl/style/layer_observer.hpp
@@ -10,6 +10,7 @@ public:
virtual ~LayerObserver() = default;
virtual void onLayerFilterChanged(Layer&) {}
+ virtual void onLayerVisibilityChanged(Layer&) {}
virtual void onLayerPaintPropertyChanged(Layer&) {}
virtual void onLayerLayoutPropertyChanged(Layer&) {}
};
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 7317100bec..42636194e3 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -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);
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index b3f70e1eb2..ef1b427538 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -136,6 +136,7 @@ private:
// LayerObserver implementation.
void onLayerFilterChanged(Layer&) override;
+ void onLayerVisibilityChanged(Layer&) override;
void onLayerPaintPropertyChanged(Layer&) override;
void onLayerLayoutPropertyChanged(Layer&) override;