summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/hillshade_layer.cpp
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2020-02-25 10:21:46 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-02-26 18:15:23 +0200
commit8785f77cd633be92123464310f85ea671689473c (patch)
treec3c845eb3feafeb8a02a392f2340fdfe4bd3d216 /src/mbgl/style/layers/hillshade_layer.cpp
parent713299c429ab494e4cc3347d9dcd76b67ba2522c (diff)
downloadqtlocation-mapboxgl-8785f77cd633be92123464310f85ea671689473c.tar.gz
[core] Generate layer code
Diffstat (limited to 'src/mbgl/style/layers/hillshade_layer.cpp')
-rw-r--r--src/mbgl/style/layers/hillshade_layer.cpp85
1 files changed, 53 insertions, 32 deletions
diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp
index 26ecfadfcc..bfbd3d1d14 100644
--- a/src/mbgl/style/layers/hillshade_layer.cpp
+++ b/src/mbgl/style/layers/hillshade_layer.cpp
@@ -229,6 +229,8 @@ using namespace conversion;
namespace {
+constexpr uint8_t kPaintPropertyCount = 12u;
+
enum class Property : uint8_t {
HillshadeAccentColor,
HillshadeExaggeration,
@@ -262,8 +264,58 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<
{"hillshade-illumination-anchor-transition", toUint8(Property::HillshadeIlluminationAnchorTransition)},
{"hillshade-illumination-direction-transition", toUint8(Property::HillshadeIlluminationDirectionTransition)},
{"hillshade-shadow-color-transition", toUint8(Property::HillshadeShadowColorTransition)}});
+
+StyleProperty getLayerProperty(const HillshadeLayer& layer, Property property) {
+ switch (property) {
+ case Property::HillshadeAccentColor:
+ return makeStyleProperty(layer.getHillshadeAccentColor());
+ case Property::HillshadeExaggeration:
+ return makeStyleProperty(layer.getHillshadeExaggeration());
+ case Property::HillshadeHighlightColor:
+ return makeStyleProperty(layer.getHillshadeHighlightColor());
+ case Property::HillshadeIlluminationAnchor:
+ return makeStyleProperty(layer.getHillshadeIlluminationAnchor());
+ case Property::HillshadeIlluminationDirection:
+ return makeStyleProperty(layer.getHillshadeIlluminationDirection());
+ case Property::HillshadeShadowColor:
+ return makeStyleProperty(layer.getHillshadeShadowColor());
+ case Property::HillshadeAccentColorTransition:
+ return makeStyleProperty(layer.getHillshadeAccentColorTransition());
+ case Property::HillshadeExaggerationTransition:
+ return makeStyleProperty(layer.getHillshadeExaggerationTransition());
+ case Property::HillshadeHighlightColorTransition:
+ return makeStyleProperty(layer.getHillshadeHighlightColorTransition());
+ case Property::HillshadeIlluminationAnchorTransition:
+ return makeStyleProperty(layer.getHillshadeIlluminationAnchorTransition());
+ case Property::HillshadeIlluminationDirectionTransition:
+ return makeStyleProperty(layer.getHillshadeIlluminationDirectionTransition());
+ case Property::HillshadeShadowColorTransition:
+ return makeStyleProperty(layer.getHillshadeShadowColorTransition());
+ }
+ return {};
+}
+
+StyleProperty getLayerProperty(const HillshadeLayer& layer, const std::string& name) {
+ const auto it = layerProperties.find(name.c_str());
+ if (it == layerProperties.end()) {
+ return {};
+ }
+ return getLayerProperty(layer, static_cast<Property>(it->second));
+}
+
} // namespace
+Value HillshadeLayer::serialize() const {
+ auto result = Layer::serialize();
+ assert(result.getObject());
+ for (const auto& property : layerProperties) {
+ auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second));
+ if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue;
+ serializeProperty(result, styleProperty, property.first.c_str(), property.second < kPaintPropertyCount);
+ }
+ return result;
+}
+
optional<Error> HillshadeLayer::setProperty(const std::string& name, const Convertible& value) {
const auto it = layerProperties.find(name.c_str());
if (it == layerProperties.end()) {
@@ -364,38 +416,7 @@ optional<Error> HillshadeLayer::setProperty(const std::string& name, const Conve
}
StyleProperty HillshadeLayer::getProperty(const std::string& name) const {
- const auto it = layerProperties.find(name.c_str());
- if (it == layerProperties.end()) {
- return {};
- }
-
- switch (static_cast<Property>(it->second)) {
- case Property::HillshadeAccentColor:
- return makeStyleProperty(getHillshadeAccentColor());
- case Property::HillshadeExaggeration:
- return makeStyleProperty(getHillshadeExaggeration());
- case Property::HillshadeHighlightColor:
- return makeStyleProperty(getHillshadeHighlightColor());
- case Property::HillshadeIlluminationAnchor:
- return makeStyleProperty(getHillshadeIlluminationAnchor());
- case Property::HillshadeIlluminationDirection:
- return makeStyleProperty(getHillshadeIlluminationDirection());
- case Property::HillshadeShadowColor:
- return makeStyleProperty(getHillshadeShadowColor());
- case Property::HillshadeAccentColorTransition:
- return makeStyleProperty(getHillshadeAccentColorTransition());
- case Property::HillshadeExaggerationTransition:
- return makeStyleProperty(getHillshadeExaggerationTransition());
- case Property::HillshadeHighlightColorTransition:
- return makeStyleProperty(getHillshadeHighlightColorTransition());
- case Property::HillshadeIlluminationAnchorTransition:
- return makeStyleProperty(getHillshadeIlluminationAnchorTransition());
- case Property::HillshadeIlluminationDirectionTransition:
- return makeStyleProperty(getHillshadeIlluminationDirectionTransition());
- case Property::HillshadeShadowColorTransition:
- return makeStyleProperty(getHillshadeShadowColorTransition());
- }
- return {};
+ return getLayerProperty(*this, name);
}
Mutable<Layer::Impl> HillshadeLayer::mutableBaseImpl() const {