summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorGali Nelle <galinelle.mapbox@gmail.com>2020-04-06 10:12:56 +0300
committergalinelle <paolo.angelelli@mapbox.com>2020-04-08 14:00:26 +0300
commit8e581c88ea855998a2746e57f1a5fc46ee62faee (patch)
tree9a158b1a4281a6c894025cc6758a0c9c59dfd5b0 /include/mbgl
parent9a55c282fecfdd76b1acdf64cef0ce2ed99472ef (diff)
downloadqtlocation-mapboxgl-8e581c88ea855998a2746e57f1a5fc46ee62faee.tar.gz
Make location indicator bearing a paint property
This change introduces a new property type, Rotation, that uses a custom interpolator, and that is currently applied to all style properties named "bearing", with a period attribute.
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/style/conversion/rotation.hpp18
-rw-r--r--include/mbgl/style/conversion_impl.hpp6
-rw-r--r--include/mbgl/style/expression/value.hpp8
-rw-r--r--include/mbgl/style/layers/background_layer.hpp1
-rw-r--r--include/mbgl/style/layers/circle_layer.hpp1
-rw-r--r--include/mbgl/style/layers/fill_extrusion_layer.hpp1
-rw-r--r--include/mbgl/style/layers/fill_layer.hpp1
-rw-r--r--include/mbgl/style/layers/heatmap_layer.hpp1
-rw-r--r--include/mbgl/style/layers/hillshade_layer.hpp1
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs5
-rw-r--r--include/mbgl/style/layers/line_layer.hpp1
-rw-r--r--include/mbgl/style/layers/location_indicator_layer.hpp12
-rw-r--r--include/mbgl/style/layers/raster_layer.hpp1
-rw-r--r--include/mbgl/style/rotation.hpp25
-rw-r--r--include/mbgl/util/interpolate.hpp26
15 files changed, 93 insertions, 15 deletions
diff --git a/include/mbgl/style/conversion/rotation.hpp b/include/mbgl/style/conversion/rotation.hpp
new file mode 100644
index 0000000000..86d67240fd
--- /dev/null
+++ b/include/mbgl/style/conversion/rotation.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/rotation.hpp>
+#include <mbgl/util/optional.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <>
+struct Converter<style::Rotation> {
+ optional<style::Rotation> operator()(const Convertible& value, Error& error) const;
+};
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp
index 79e9301842..8652a355f1 100644
--- a/include/mbgl/style/conversion_impl.hpp
+++ b/include/mbgl/style/conversion_impl.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/expression/image.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/style/property_value.hpp>
+#include <mbgl/style/rotation.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geojson.hpp>
@@ -343,6 +344,11 @@ struct ValueFactory<Position> {
}
};
+template <>
+struct ValueFactory<Rotation> {
+ static Value make(const Rotation& rotation) { return {rotation.getAngle()}; }
+};
+
template <typename T>
Value makeValue(T&& arg) {
return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg));
diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp
index 902f5ae209..6f12bb9336 100644
--- a/include/mbgl/style/expression/value.hpp
+++ b/include/mbgl/style/expression/value.hpp
@@ -5,6 +5,7 @@
#include <mbgl/style/expression/image.hpp>
#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/position.hpp>
+#include <mbgl/style/rotation.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
@@ -147,6 +148,13 @@ std::vector<optional<T>> fromExpressionValues(const std::vector<optional<Value>>
return result;
}
+template <>
+struct ValueConverter<Rotation> {
+ static type::Type expressionType() { return type::Number; }
+ static Value toExpressionValue(const mbgl::style::Rotation& value);
+ static optional<Rotation> fromExpressionValue(const Value& v);
+};
+
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp
index 9fdfd3ac92..2a46b2fc21 100644
--- a/include/mbgl/style/layers/background_layer.hpp
+++ b/include/mbgl/style/layers/background_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp
index dd5b674002..f0e9787caa 100644
--- a/include/mbgl/style/layers/circle_layer.hpp
+++ b/include/mbgl/style/layers/circle_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp
index ca33c6c3f8..3e4973b82c 100644
--- a/include/mbgl/style/layers/fill_extrusion_layer.hpp
+++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp
index 4a1f09cca0..fb386c4b11 100644
--- a/include/mbgl/style/layers/fill_layer.hpp
+++ b/include/mbgl/style/layers/fill_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp
index 588aaa81df..371e9a8aa4 100644
--- a/include/mbgl/style/layers/heatmap_layer.hpp
+++ b/include/mbgl/style/layers/heatmap_layer.hpp
@@ -8,7 +8,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp
index c501e80b8d..7149fb46dd 100644
--- a/include/mbgl/style/layers/hillshade_layer.hpp
+++ b/include/mbgl/style/layers/hillshade_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
index a083829f60..a81aaa9e16 100644
--- a/include/mbgl/style/layers/layer.hpp.ejs
+++ b/include/mbgl/style/layers/layer.hpp.ejs
@@ -15,7 +15,12 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
+<% if (type === 'location-indicator') { -%>
+#include <mbgl/style/rotation.hpp>
+<% } -%>
+<% if (type === 'symbol') { -%>
#include <mbgl/style/expression/formatted.hpp>
+<% } -%>
#include <mbgl/util/color.hpp>
<% if (type === 'line' || type === 'symbol') { -%>
diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp
index 2186f16669..7d7da47bf9 100644
--- a/include/mbgl/style/layers/line_layer.hpp
+++ b/include/mbgl/style/layers/line_layer.hpp
@@ -8,7 +8,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
#include <vector>
diff --git a/include/mbgl/style/layers/location_indicator_layer.hpp b/include/mbgl/style/layers/location_indicator_layer.hpp
index e9e67c1a20..f112664dab 100644
--- a/include/mbgl/style/layers/location_indicator_layer.hpp
+++ b/include/mbgl/style/layers/location_indicator_layer.hpp
@@ -7,7 +7,7 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
+#include <mbgl/style/rotation.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
@@ -22,10 +22,6 @@ public:
// Layout properties
- static PropertyValue<float> getDefaultBearing();
- const PropertyValue<float>& getBearing() const;
- void setBearing(const PropertyValue<float>&);
-
static PropertyValue<expression::Image> getDefaultBearingImage();
const PropertyValue<expression::Image>& getBearingImage() const;
void setBearingImage(const PropertyValue<expression::Image>&);
@@ -66,6 +62,12 @@ public:
void setAccuracyRadiusColorTransition(const TransitionOptions&);
TransitionOptions getAccuracyRadiusColorTransition() const;
+ static PropertyValue<Rotation> getDefaultBearing();
+ const PropertyValue<Rotation>& getBearing() const;
+ void setBearing(const PropertyValue<Rotation>&);
+ void setBearingTransition(const TransitionOptions&);
+ TransitionOptions getBearingTransition() const;
+
static PropertyValue<float> getDefaultBearingImageSize();
const PropertyValue<float>& getBearingImageSize() const;
void setBearingImageSize(const PropertyValue<float>&);
diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp
index df82c93660..78fa3db23b 100644
--- a/include/mbgl/style/layers/raster_layer.hpp
+++ b/include/mbgl/style/layers/raster_layer.hpp
@@ -7,7 +7,6 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
diff --git a/include/mbgl/style/rotation.hpp b/include/mbgl/style/rotation.hpp
new file mode 100644
index 0000000000..862ede93b7
--- /dev/null
+++ b/include/mbgl/style/rotation.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+namespace mbgl {
+namespace style {
+
+// Could be made a template class if needed
+// template <size_t Period>
+// size_t period() const noexcept { return Period; }
+class Rotation {
+public:
+ Rotation() = default;
+ Rotation(double angle_) : angle(angle_) {}
+ double period() const noexcept { return 360.0; }
+ double getAngle() const noexcept { return angle; }
+
+ friend bool operator==(const Rotation& lhs, const Rotation& rhs) { return lhs.angle == rhs.angle; }
+
+ friend bool operator!=(const Rotation& lhs, const Rotation& rhs) { return !(lhs == rhs); }
+
+private:
+ double angle;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp
index aff730a0a2..566f2b0a6b 100644
--- a/include/mbgl/util/interpolate.hpp
+++ b/include/mbgl/util/interpolate.hpp
@@ -1,9 +1,10 @@
#pragma once
+#include <mbgl/style/expression/value.hpp>
+#include <mbgl/style/position.hpp>
+#include <mbgl/style/rotation.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/range.hpp>
-#include <mbgl/style/position.hpp>
-#include <mbgl/style/expression/value.hpp>
#include <array>
#include <vector>
@@ -102,6 +103,27 @@ public:
}
};
+template <>
+struct Interpolator<style::Rotation> {
+public:
+ style::Rotation operator()(const style::Rotation& a, const style::Rotation& b, const double t) {
+ assert(a.period() == b.period());
+ auto period = a.period();
+ auto aAngle = std::fmod(a.getAngle(), period);
+ auto bAngle = std::fmod(b.getAngle(), period);
+
+ if (aAngle - bAngle > period * 0.5) {
+ return {std::fmod(aAngle * (1.0 - t) + (bAngle + period) * t, period)};
+ }
+
+ if (aAngle - bAngle < period * -0.5) {
+ return {std::fmod((aAngle + period) * (1.0 - t) + bAngle * t, period)};
+ }
+
+ return {aAngle * (1.0 - t) + bAngle * t};
+ }
+};
+
struct Uninterpolated {
template <class T>
T operator()(const T& a, const T&, const double) const {