summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/style/light.hpp4
-rw-r--r--include/mbgl/style/light.hpp.ejs4
-rw-r--r--src/mbgl/style/light.cpp119
-rw-r--r--src/mbgl/style/light.cpp.ejs77
4 files changed, 204 insertions, 0 deletions
diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp
index 0b65df9f1b..21a05cf4c8 100644
--- a/include/mbgl/style/light.hpp
+++ b/include/mbgl/style/light.hpp
@@ -2,6 +2,7 @@
#pragma once
+#include <mbgl/style/conversion.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
@@ -17,6 +18,9 @@ public:
Light();
~Light();
+ // Dynamic properties
+ optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
+
static LightAnchorType getDefaultAnchor();
PropertyValue<LightAnchorType> getAnchor() const;
void setAnchor(PropertyValue<LightAnchorType>);
diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs
index adc5b651e3..c3001d982b 100644
--- a/include/mbgl/style/light.hpp.ejs
+++ b/include/mbgl/style/light.hpp.ejs
@@ -5,6 +5,7 @@
#pragma once
+#include <mbgl/style/conversion.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
@@ -20,6 +21,9 @@ public:
Light();
~Light();
+ // Dynamic properties
+ optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
+
<% for (const property of properties) { -%>
static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>();
<%- propertyValueType(property) %> get<%- camelize(property.name) %>() const;
diff --git a/src/mbgl/style/light.cpp b/src/mbgl/style/light.cpp
index a88cc02bd7..cc8897acee 100644
--- a/src/mbgl/style/light.cpp
+++ b/src/mbgl/style/light.cpp
@@ -3,6 +3,13 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/light_impl.hpp>
#include <mbgl/style/light_observer.hpp>
+#include <mbgl/style/conversion/light.hpp>
+#include <mbgl/style/conversion/property_value.hpp>
+#include <mbgl/style/conversion/transition_options.hpp>
+#include <mbgl/style/conversion/json.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+
+#include <mapbox/eternal.hpp>
namespace mbgl {
namespace style {
@@ -24,6 +31,118 @@ Mutable<Light::Impl> Light::mutableImpl() const {
return makeMutable<Impl>(*impl);
}
+using namespace conversion;
+
+optional<Error> Light::setProperty(const std::string& name, const Convertible& value) {
+ enum class Property : uint8_t {
+ Anchor,
+ Color,
+ Intensity,
+ Position,
+ AnchorTransition,
+ ColorTransition,
+ IntensityTransition,
+ PositionTransition,
+ };
+
+ MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({
+ { "anchor", static_cast<uint8_t>(Property::Anchor) },
+ { "color", static_cast<uint8_t>(Property::Color) },
+ { "intensity", static_cast<uint8_t>(Property::Intensity) },
+ { "position", static_cast<uint8_t>(Property::Position) },
+ { "anchor-transition", static_cast<uint8_t>(Property::AnchorTransition) },
+ { "color-transition", static_cast<uint8_t>(Property::ColorTransition) },
+ { "intensity-transition", static_cast<uint8_t>(Property::IntensityTransition) },
+ { "position-transition", static_cast<uint8_t>(Property::PositionTransition) }
+ });
+
+ const auto it = properties.find(name.c_str());
+ if (it == properties.end()) {
+ return Error { "light doesn't support this property" };
+ }
+
+ auto property = static_cast<Property>(it->second);
+
+
+ if (property == Property::Anchor) {
+ Error error;
+ optional<PropertyValue<LightAnchorType>> typedValue = convert<PropertyValue<LightAnchorType>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setAnchor(*typedValue);
+ return nullopt;
+
+ }
+
+ if (property == Property::Color) {
+ Error error;
+ optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setColor(*typedValue);
+ return nullopt;
+
+ }
+
+ if (property == Property::Intensity) {
+ Error error;
+ optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setIntensity(*typedValue);
+ return nullopt;
+
+ }
+
+ if (property == Property::Position) {
+ Error error;
+ optional<PropertyValue<Position>> typedValue = convert<PropertyValue<Position>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setPosition(*typedValue);
+ return nullopt;
+
+ }
+
+
+ Error error;
+ optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
+ if (!transition) {
+ return error;
+ }
+
+ if (property == Property::AnchorTransition) {
+ setAnchorTransition(*transition);
+ return nullopt;
+ }
+
+ if (property == Property::ColorTransition) {
+ setColorTransition(*transition);
+ return nullopt;
+ }
+
+ if (property == Property::IntensityTransition) {
+ setIntensityTransition(*transition);
+ return nullopt;
+ }
+
+ if (property == Property::PositionTransition) {
+ setPositionTransition(*transition);
+ return nullopt;
+ }
+
+
+ return Error { "light doesn't support this property" };
+}
+
LightAnchorType Light::getDefaultAnchor() {
return LightAnchor::defaultValue();
}
diff --git a/src/mbgl/style/light.cpp.ejs b/src/mbgl/style/light.cpp.ejs
index 45241c60fd..93e487f7a8 100644
--- a/src/mbgl/style/light.cpp.ejs
+++ b/src/mbgl/style/light.cpp.ejs
@@ -6,6 +6,13 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/light_impl.hpp>
#include <mbgl/style/light_observer.hpp>
+#include <mbgl/style/conversion/light.hpp>
+#include <mbgl/style/conversion/property_value.hpp>
+#include <mbgl/style/conversion/transition_options.hpp>
+#include <mbgl/style/conversion/json.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+
+#include <mapbox/eternal.hpp>
namespace mbgl {
namespace style {
@@ -27,6 +34,76 @@ Mutable<Light::Impl> Light::mutableImpl() const {
return makeMutable<Impl>(*impl);
}
+using namespace conversion;
+
+optional<Error> Light::setProperty(const std::string& name, const Convertible& value) {
+ enum class Property : uint8_t {
+<% for (const property of properties) { -%>
+ <%- camelize(property.name) %>,
+<% } -%>
+<% for (const property of properties) { -%>
+ <%- camelize(property.name) %>Transition,
+<% } -%>
+ };
+
+ MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({
+ <%- properties.map(p => `{ "${p.name}", static_cast<uint8_t>(Property::${camelize(p.name)}) }`).join(',\n ') %>,
+ <%- properties.map(p => `{ "${p.name}-transition", static_cast<uint8_t>(Property::${camelize(p.name)}Transition) }`).join(',\n ') %>
+ });
+
+ const auto it = properties.find(name.c_str());
+ if (it == properties.end()) {
+ return Error { "light doesn't support this property" };
+ }
+
+ auto property = static_cast<Property>(it->second);
+
+ <%
+ const conversions = {};
+ for (const property of properties) {
+ const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven';
+ const convertTokens = property.name === 'icon-image' || property.name === 'text-field';
+ const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`;
+ conversions[conversion] = conversions[conversion] || [];
+ conversions[conversion].push(property);
+ }
+ -%>
+ <% for (const key in conversions) {
+ const properties = conversions[key];
+ %>
+ if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) {
+ Error error;
+ <%- key %>;
+ if (!typedValue) {
+ return error;
+ }
+ <% if (properties.length == 1) { %>
+ set<%- camelize(properties[0].name) %>(*typedValue);
+ return nullopt;
+ <% } else for (const property of properties) { %>
+ if (property == Property::<%- camelize(property.name) %>) {
+ set<%- camelize(property.name) %>(*typedValue);
+ return nullopt;
+ }
+ <% } %>
+ }
+ <% } %>
+
+ Error error;
+ optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
+ if (!transition) {
+ return error;
+ }
+ <% for (const property of properties) { %>
+ if (property == Property::<%- camelize(property.name) %>Transition) {
+ set<%- camelize(property.name) %>Transition(*transition);
+ return nullopt;
+ }
+ <% } %>
+
+ return Error { "light doesn't support this property" };
+}
+
<% for (const property of properties) { -%>
<%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() {
return Light<%- camelize(property.name) %>::defaultValue();