diff options
Diffstat (limited to 'src/mbgl/style/layers/custom_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/custom_layer.cpp | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index cda8a157f0..f7c349b3d8 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -1,6 +1,6 @@ #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/style/layers/custom_layer_impl.hpp> -#include <mbgl/util/logging.hpp> +#include <mbgl/style/layer_observer.hpp> namespace mbgl { namespace style { @@ -10,21 +10,52 @@ CustomLayer::CustomLayer(const std::string& layerID, CustomLayerRenderFunction render, CustomLayerDeinitializeFunction deinit, void* context) - : Layer(LayerType::Custom, std::make_unique<Impl>(layerID, init, render, deinit, context)) - , impl(static_cast<Impl*>(baseImpl.get())) { - Log::Info(Event::General, "New custom layer: %s", layerID.c_str()); + : Layer(makeMutable<Impl>(layerID, init, render, deinit, context)) { } -CustomLayer::CustomLayer(const Impl& other) - : Layer(LayerType::Custom, std::make_unique<Impl>(other)) - , impl(static_cast<Impl*>(baseImpl.get())) { +CustomLayer::~CustomLayer() = default; + +const CustomLayer::Impl& CustomLayer::impl() const { + return static_cast<const Impl&>(*baseImpl); } -CustomLayer::~CustomLayer() = default; +Mutable<CustomLayer::Impl> CustomLayer::mutableImpl() const { + return makeMutable<Impl>(impl()); +} + +std::unique_ptr<Layer> CustomLayer::cloneRef(const std::string&) const { + assert(false); + return nullptr; +} + +// Visibility + +void CustomLayer::setVisibility(VisibilityType value) { + if (value == getVisibility()) + return; + auto impl_ = mutableImpl(); + impl_->visibility = value; + baseImpl = std::move(impl_); + observer->onLayerVisibilityChanged(*this); +} + +// Zoom range + +void CustomLayer::setMinZoom(float minZoom) { + auto impl_ = mutableImpl(); + impl_->minZoom = minZoom; + baseImpl = std::move(impl_); +} + +void CustomLayer::setMaxZoom(float maxZoom) { + auto impl_ = mutableImpl(); + impl_->maxZoom = maxZoom; + baseImpl = std::move(impl_); +} template <> bool Layer::is<CustomLayer>() const { - return type == LayerType::Custom; + return getType() == LayerType::Custom; } } // namespace style |