summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/layer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/conversion/layer.cpp')
-rw-r--r--src/mbgl/style/conversion/layer.cpp114
1 files changed, 2 insertions, 112 deletions
diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp
index 085d7ae4c6..b551f1bfb2 100644
--- a/src/mbgl/style/conversion/layer.cpp
+++ b/src/mbgl/style/conversion/layer.cpp
@@ -2,15 +2,6 @@
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/filter.hpp>
#include <mbgl/style/conversion_impl.hpp>
-#include <mbgl/style/layers/background_layer.hpp>
-#include <mbgl/style/layers/circle_layer.hpp>
-#include <mbgl/style/layers/fill_layer.hpp>
-#include <mbgl/style/layers/fill_extrusion_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>
namespace mbgl {
namespace style {
@@ -29,81 +20,6 @@ optional<Error> setPaintProperties(Layer& layer, const Convertible& value) {
});
}
-template <class LayerType>
-optional<std::unique_ptr<Layer>> convertVectorLayer(const std::string& id, const Convertible& value, Error& error) {
- auto sourceValue = objectMember(value, "source");
- if (!sourceValue) {
- error.message = "layer must have a source";
- return nullopt;
- }
-
- optional<std::string> source = toString(*sourceValue);
- if (!source) {
- error.message = "layer source must be a string";
- return nullopt;
- }
-
- std::unique_ptr<LayerType> layer = std::make_unique<LayerType>(id, *source);
-
- auto sourceLayerValue = objectMember(value, "source-layer");
- if (sourceLayerValue) {
- optional<std::string> sourceLayer = toString(*sourceLayerValue);
- if (!sourceLayer) {
- error.message = "layer source-layer must be a string";
- return nullopt;
- }
- layer->setSourceLayer(*sourceLayer);
- }
-
- auto filterValue = objectMember(value, "filter");
- if (filterValue) {
- optional<Filter> filter = convert<Filter>(*filterValue, error);
- if (!filter) {
- return nullopt;
- }
- layer->setFilter(*filter);
- }
-
- return { std::move(layer) };
-}
-
-static optional<std::unique_ptr<Layer>> convertRasterLayer(const std::string& id, const Convertible& value, Error& error) {
- auto sourceValue = objectMember(value, "source");
- if (!sourceValue) {
- error.message = "layer must have a source";
- return nullopt;
- }
-
- optional<std::string> source = toString(*sourceValue);
- if (!source) {
- error.message = "layer source must be a string";
- return nullopt;
- }
-
- return { std::make_unique<RasterLayer>(id, *source) };
-}
-
-static optional<std::unique_ptr<Layer>> convertHillshadeLayer(const std::string& id, const Convertible& value, Error& error) {
- auto sourceValue = objectMember(value, "source");
- if (!sourceValue) {
- error.message = "layer must have a source";
- return nullopt;
- }
-
- optional<std::string> source = toString(*sourceValue);
- if (!source) {
- error.message = "layer source must be a string";
- return nullopt;
- }
-
- return { std::make_unique<HillshadeLayer>(id, *source) };
-}
-
-
-static optional<std::unique_ptr<Layer>> convertBackgroundLayer(const std::string& id, const Convertible&, Error&) {
- return { std::make_unique<BackgroundLayer>(id) };
-}
-
optional<std::unique_ptr<Layer>> Converter<std::unique_ptr<Layer>>::operator()(const Convertible& value, Error& error) const {
if (!isObject(value)) {
error.message = "layer must be an object";
@@ -134,37 +50,11 @@ optional<std::unique_ptr<Layer>> Converter<std::unique_ptr<Layer>>::operator()(c
return nullopt;
}
- optional<std::unique_ptr<Layer>> converted;
-
- if (*type == "fill") {
- converted = convertVectorLayer<FillLayer>(*id, value, error);
- } else if (*type == "fill-extrusion") {
- converted = convertVectorLayer<FillExtrusionLayer>(*id, value, error);
- } else if (*type == "line") {
- converted = convertVectorLayer<LineLayer>(*id, value, error);
- } else if (*type == "circle") {
- converted = convertVectorLayer<CircleLayer>(*id, value, error);
- } else if (*type == "symbol") {
- converted = convertVectorLayer<SymbolLayer>(*id, value, error);
- } else if (*type == "raster") {
- converted = convertRasterLayer(*id, value, error);
- } else if (*type == "heatmap") {
- converted = convertVectorLayer<HeatmapLayer>(*id, value, error);
- } else if (*type == "hillshade") {
- converted = convertHillshadeLayer(*id, value, error);
- } else if (*type == "background") {
- converted = convertBackgroundLayer(*id, value, error);
- } else {
- error.message = "invalid layer type";
+ std::unique_ptr<Layer> layer = LayerManager::get()->createLayer(*type, *id, value, error);
+ if (!layer) {
return nullopt;
}
- if (!converted) {
- return converted;
- }
-
- std::unique_ptr<Layer> layer = std::move(*converted);
-
auto minzoomValue = objectMember(value, "minzoom");
if (minzoomValue) {
optional<float> minzoom = toNumber(*minzoomValue);