summaryrefslogtreecommitdiff
path: root/platform/default/layer_manager.cpp
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-05 19:49:40 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-07 16:34:20 +0200
commitffdeef3a26306e447f1cc52a8e14d42fb035611d (patch)
tree7e3217d761581161d39b2552072d1b3cef8df67a /platform/default/layer_manager.cpp
parentf560b4f9efebb4d448181724304f63b683a26b67 (diff)
downloadqtlocation-mapboxgl-ffdeef3a26306e447f1cc52a8e14d42fb035611d.tar.gz
Refer corresponding LayerFactory instance from the Layer::Impl
Diffstat (limited to 'platform/default/layer_manager.cpp')
-rw-r--r--platform/default/layer_manager.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/platform/default/layer_manager.cpp b/platform/default/layer_manager.cpp
new file mode 100644
index 0000000000..e497c66729
--- /dev/null
+++ b/platform/default/layer_manager.cpp
@@ -0,0 +1,61 @@
+#include <mbgl/style/layer.hpp>
+#include <mbgl/style/layers/symbol_layer.hpp>
+#include <mbgl/style/layers/background_layer.hpp>
+#include <mbgl/style/layers/circle_layer.hpp>
+#include <mbgl/style/layers/fill_extrusion_layer.hpp>
+#include <mbgl/style/layers/fill_layer.hpp>
+#include <mbgl/style/layers/heatmap_layer.hpp>
+#include <mbgl/style/layers/hillshade_layer.hpp>
+#include <mbgl/style/layers/line_layer.hpp>
+#include <mbgl/style/layers/raster_layer.hpp>
+#include <mbgl/style/layers/symbol_layer.hpp>
+
+#include <memory>
+#include <vector>
+
+namespace mbgl {
+namespace style {
+
+class LayerManagerBase : public LayerManager {
+public:
+ LayerManagerBase();
+private:
+ // LayerManager overrides.
+ std::unique_ptr<Layer> createLayer(const std::string& type, const std::string& id, const conversion::Convertible& value, conversion::Error& error) final;
+ std::vector<std::unique_ptr<LayerFactory>> factories;
+};
+
+LayerManagerBase::LayerManagerBase() {
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new FillLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new LineLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new CircleLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new SymbolLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new RasterLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new BackgroundLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new HillshadeLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new FillExtrusionLayerFactory));
+ factories.emplace_back(std::unique_ptr<LayerFactory>(new HeatmapLayerFactory));
+}
+
+std::unique_ptr<Layer> LayerManagerBase::createLayer(const std::string& type, const std::string& id, const conversion::Convertible& value, conversion::Error& error) {
+ for (const auto& factory: factories) {
+ if (factory->supportsType(type)) {
+ auto layer = factory->createLayer(id, value);
+ if (!layer) {
+ error.message = "Error parsing a layer of type: " + type;
+ }
+ return layer;
+ }
+ }
+ error.message = "Unsupported layer type: " + type;
+ return nullptr;
+}
+
+// static
+LayerManager* LayerManager::get() {
+ static LayerManagerBase impl;
+ return &impl;
+}
+
+} // namespace style
+} // namespace mbgl