summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/layout/symbol_layout.cpp4
-rw-r--r--src/mbgl/style/conversion/stringify.hpp8
-rw-r--r--src/mbgl/style/function/categorical_stops.cpp6
-rw-r--r--src/mbgl/style/function/identity_stops.cpp22
-rw-r--r--src/mbgl/style/layout_property.hpp11
-rw-r--r--src/mbgl/style/paint_property_binder.hpp18
-rw-r--r--src/mbgl/style/possibly_evaluated_property_value.hpp7
7 files changed, 45 insertions, 31 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 5dd36c41bd..665806cb0e 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -129,8 +129,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
if (hasIcon) {
ft.icon = util::replaceTokens(layout.get<IconImage>(), getValue);
- ft.iconOffset = layout.get<IconOffset>().evaluate(zoom, *feature);
- ft.iconRotation = layout.get<IconRotate>().evaluate(zoom, *feature) * util::DEG2RAD;
+ ft.iconOffset = layout.evaluate<IconOffset>(zoom, *feature);
+ ft.iconRotation = layout.evaluate<IconRotate>(zoom, *feature) * util::DEG2RAD;
}
if (ft.text || ft.icon) {
diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp
index 71755bd9d6..5aab1076fd 100644
--- a/src/mbgl/style/conversion/stringify.hpp
+++ b/src/mbgl/style/conversion/stringify.hpp
@@ -330,6 +330,10 @@ void stringify(Writer& writer, const SourceFunction<T>& f) {
writer.Key("property");
writer.String(f.property);
SourceFunction<T>::Stops::visit(f.stops, StringifyStops<Writer> { writer });
+ if (f.defaultValue) {
+ writer.Key("default");
+ stringify(writer, *f.defaultValue);
+ }
writer.EndObject();
}
@@ -339,6 +343,10 @@ void stringify(Writer& writer, const CompositeFunction<T>& f) {
writer.Key("property");
writer.String(f.property);
CompositeFunction<T>::Stops::visit(f.stops, StringifyStops<Writer> { writer });
+ if (f.defaultValue) {
+ writer.Key("default");
+ stringify(writer, *f.defaultValue);
+ }
writer.EndObject();
}
diff --git a/src/mbgl/style/function/categorical_stops.cpp b/src/mbgl/style/function/categorical_stops.cpp
index bcdf170f17..21df4fa9f6 100644
--- a/src/mbgl/style/function/categorical_stops.cpp
+++ b/src/mbgl/style/function/categorical_stops.cpp
@@ -18,13 +18,13 @@ optional<CategoricalValue> categoricalValue(const Value& value) {
}
template <class T>
-T CategoricalStops<T>::evaluate(const Value& value) const {
+optional<T> CategoricalStops<T>::evaluate(const Value& value) const {
auto v = categoricalValue(value);
if (!v) {
- return defaultValue;
+ return {};
}
auto it = stops.find(*v);
- return it == stops.end() ? defaultValue : it->second;
+ return it == stops.end() ? optional<T>() : it->second;
}
template class CategoricalStops<float>;
diff --git a/src/mbgl/style/function/identity_stops.cpp b/src/mbgl/style/function/identity_stops.cpp
index e210b4d773..9bddc3feac 100644
--- a/src/mbgl/style/function/identity_stops.cpp
+++ b/src/mbgl/style/function/identity_stops.cpp
@@ -7,36 +7,34 @@ namespace mbgl {
namespace style {
template <>
-float IdentityStops<float>::evaluate(const Value& value) const {
- return numericValue<float>(value)
- .value_or(0.0f);
+optional<float> IdentityStops<float>::evaluate(const Value& value) const {
+ return numericValue<float>(value);
}
template <>
-Color IdentityStops<Color>::evaluate(const Value& value) const {
+optional<Color> IdentityStops<Color>::evaluate(const Value& value) const {
if (!value.is<std::string>()) {
- return Color::black();
+ return {};
}
- return Color::parse(value.get<std::string>())
- .value_or(Color::black());
+ return Color::parse(value.get<std::string>());
}
template <>
-std::array<float, 2> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const {
+optional<std::array<float, 2>> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const {
if (!value.is<std::vector<Value>>()) {
- return {{ 0, 0 }};
+ return {};
}
const std::vector<Value>& vector = value.get<std::vector<Value>>();
if (vector.size() != 2 || !numericValue<float>(vector[0]) || !numericValue<float>(vector[1])) {
- return {{ 0, 0 }};
+ return {};
}
- return {{
+ return {{{
*numericValue<float>(vector[0]),
*numericValue<float>(vector[1])
- }};
+ }}};
}
} // namespace style
diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp
index 7ce2ecc7b8..25cff4b92d 100644
--- a/src/mbgl/style/layout_property.hpp
+++ b/src/mbgl/style/layout_property.hpp
@@ -17,6 +17,7 @@ public:
using UnevaluatedType = PropertyValue<T>;
using EvaluatorType = PropertyEvaluator<T>;
using EvaluatedType = T;
+ using Type = T;
};
template <class T>
@@ -25,6 +26,7 @@ public:
using UnevaluatedType = DataDrivenPropertyValue<T>;
using EvaluatorType = DataDrivenPropertyEvaluator<T>;
using EvaluatedType = PossiblyEvaluatedPropertyValue<T>;
+ using Type = T;
};
template <class... Ps>
@@ -40,6 +42,15 @@ public:
class Evaluated : public Tuple<EvaluatedTypes> {
public:
using Tuple<EvaluatedTypes>::Tuple;
+
+ template <class P>
+ typename P::Type evaluate(float z, const GeometryTileFeature& feature) const {
+ using T = typename P::Type;
+ return this->template get<P>().match(
+ [&] (const T& t) { return t; },
+ [&] (const SourceFunction<T>& t) { return t.evaluate(feature, P::defaultValue()); },
+ [&] (const CompositeFunction<T>& t) { return t.evaluate(z, feature, P::defaultValue()); });
+ }
};
class Unevaluated : public Tuple<UnevaluatedTypes> {
diff --git a/src/mbgl/style/paint_property_binder.hpp b/src/mbgl/style/paint_property_binder.hpp
index 964f33d2ec..79c7692b2f 100644
--- a/src/mbgl/style/paint_property_binder.hpp
+++ b/src/mbgl/style/paint_property_binder.hpp
@@ -50,12 +50,13 @@ public:
using Attributes = gl::Attributes<Attribute>;
using Vertex = typename Attributes::Vertex;
- SourceFunctionPaintPropertyBinder(SourceFunction<T> function_)
- : function(std::move(function_)) {
+ SourceFunctionPaintPropertyBinder(SourceFunction<T> function_, T defaultValue_)
+ : function(std::move(function_)),
+ defaultValue(std::move(defaultValue_)) {
}
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) {
- AttributeValue value = Attribute::value(function.evaluate(feature));
+ AttributeValue value = Attribute::value(function.evaluate(feature, defaultValue));
for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) {
vertexVector.emplace_back(Vertex { value });
}
@@ -86,6 +87,7 @@ public:
private:
SourceFunction<T> function;
+ T defaultValue;
gl::VertexVector<Vertex> vertexVector;
optional<gl::VertexBuffer<Vertex>> vertexBuffer;
};
@@ -103,13 +105,14 @@ public:
using Attributes = gl::Attributes<MinAttribute, MaxAttribute>;
using Vertex = typename Attributes::Vertex;
- CompositeFunctionPaintPropertyBinder(CompositeFunction<T> function_, float zoom)
+ CompositeFunctionPaintPropertyBinder(CompositeFunction<T> function_, float zoom, T defaultValue_)
: function(std::move(function_)),
+ defaultValue(std::move(defaultValue_)),
coveringRanges(function.coveringRanges(zoom)) {
}
void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) {
- Range<T> range = function.evaluate(std::get<1>(coveringRanges), feature);
+ Range<T> range = function.evaluate(std::get<1>(coveringRanges), feature, defaultValue);
AttributeValue min = Attribute::value(range.min);
AttributeValue max = Attribute::value(range.max);
for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) {
@@ -148,6 +151,7 @@ public:
private:
using InnerStops = typename CompositeFunction<T>::InnerStops;
CompositeFunction<T> function;
+ T defaultValue;
std::tuple<Range<float>, Range<InnerStops>> coveringRanges;
gl::VertexVector<Vertex> vertexVector;
optional<gl::VertexBuffer<Vertex>> vertexBuffer;
@@ -171,10 +175,10 @@ public:
return ConstantPaintPropertyBinder<Type, Attribute>(constant);
},
[&] (const SourceFunction<Type>& function) {
- return SourceFunctionPaintPropertyBinder<Type, Attribute>(function);
+ return SourceFunctionPaintPropertyBinder<Type, Attribute>(function, PaintProperty::defaultValue());
},
[&] (const CompositeFunction<Type>& function) {
- return CompositeFunctionPaintPropertyBinder<Type, Attribute>(function, zoom);
+ return CompositeFunctionPaintPropertyBinder<Type, Attribute>(function, zoom, PaintProperty::defaultValue());
}
)) {
}
diff --git a/src/mbgl/style/possibly_evaluated_property_value.hpp b/src/mbgl/style/possibly_evaluated_property_value.hpp
index bb917442f6..8c3f1780a6 100644
--- a/src/mbgl/style/possibly_evaluated_property_value.hpp
+++ b/src/mbgl/style/possibly_evaluated_property_value.hpp
@@ -43,13 +43,6 @@ public:
auto match(Ts&&... ts) const {
return value.match(std::forward<Ts>(ts)...);
}
-
- T evaluate(float z, const GeometryTileFeature& feature) const {
- return value.match(
- [&] (const T& t) { return t; },
- [&] (const SourceFunction<T>& t) { return t.evaluate(feature); },
- [&] (const CompositeFunction<T>& t) { return t.evaluate(z, feature); });
- }
};
} // namespace style