[core] Ability to set source-layer setProperty method

This commit is contained in:
Mikhail Pozdnyakov
2020-03-24 15:35:41 +02:00
parent 5f1847d9a2
commit 7234cb3968
10 changed files with 22 additions and 45 deletions

View File

@@ -37,7 +37,6 @@ public:
protected:
optional<std::string> getSource(const style::conversion::Convertible& value) const noexcept;
bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept;
};
} // namespace mbgl

View File

@@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> CircleLayerFactory::createLayer(const std::string&
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::CircleLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::CircleLayer(id, *source));
}
std::unique_ptr<Bucket> CircleLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept {

View File

@@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> FillExtrusionLayerFactory::createLayer(const std::
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::FillExtrusionLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::FillExtrusionLayer(id, *source));
}
std::unique_ptr<Layout> FillExtrusionLayerFactory::createLayout(const LayoutParameters& parameters,

View File

@@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> FillLayerFactory::createLayer(const std::string& i
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::FillLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::FillLayer(id, *source));
}
std::unique_ptr<Layout>

View File

@@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> HeatmapLayerFactory::createLayer(const std::string
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::HeatmapLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::HeatmapLayer(id, *source));
}
std::unique_ptr<Bucket> HeatmapLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept {

View File

@@ -37,16 +37,4 @@ std::unique_ptr<Layout> LayerFactory::createLayout(const LayoutParameters&,
return nullptr;
}
bool LayerFactory::initSourceLayerAndFilter(style::Layer* layer, const style::conversion::Convertible& value) const noexcept {
auto sourceLayerValue = objectMember(value, "source-layer");
if (sourceLayerValue) {
optional<std::string> sourceLayer = toString(*sourceLayerValue);
if (!sourceLayer) {
return false;
}
layer->setSourceLayer(*sourceLayer);
}
return true;
}
} // namespace mbgl

View File

@@ -16,12 +16,7 @@ std::unique_ptr<style::Layer> LineLayerFactory::createLayer(const std::string& i
if (!source) {
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::LineLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::LineLayer(id, *source));
}
std::unique_ptr<Layout> LineLayerFactory::createLayout(const LayoutParameters& parameters,

View File

@@ -16,12 +16,7 @@ std::unique_ptr<style::Layer> SymbolLayerFactory::createLayer(const std::string&
if (!source) {
return nullptr;
}
std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::SymbolLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::SymbolLayer(id, *source));
}
std::unique_ptr<Layout> SymbolLayerFactory::createLayout(const LayoutParameters& parameters,

View File

@@ -68,6 +68,9 @@ optional<std::unique_ptr<Layer>> Converter<std::unique_ptr<Layer>>::operator()(c
if (!setObjectMember(layer, value, "minzoom", error)) return nullopt;
if (!setObjectMember(layer, value, "maxzoom", error)) return nullopt;
if (!setObjectMember(layer, value, "filter", error)) return nullopt;
if (layer->getTypeInfo()->source == LayerTypeInfo::Source::Required) {
if (!setObjectMember(layer, value, "source-layer", error)) return nullopt;
}
auto layoutValue = objectMember(value, "layout");
if (layoutValue) {

View File

@@ -7,6 +7,7 @@
#include <mbgl/tile/tile.hpp>
#include <mbgl/renderer/render_layer.hpp>
#include <mbgl/util/logging.hpp>
namespace mbgl {
namespace style {
@@ -163,6 +164,18 @@ optional<conversion::Error> Layer::setProperty(const std::string& name, const co
setFilter(*filter);
return nullopt;
}
} else if (name == "source-layer") {
if (auto sourceLayer = convert<std::string>(value, *error)) {
if (getTypeInfo()->source != LayerTypeInfo::Source::Required) {
Log::Warning(mbgl::Event::General,
"source-layer property cannot be applied to"
"the layer %s",
baseImpl->id.c_str());
return nullopt;
}
setSourceLayer(*sourceLayer);
return nullopt;
}
}
return error;
}