summaryrefslogtreecommitdiff
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
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.
-rw-r--r--CMakeLists.txt3
-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
-rw-r--r--platform/glfw/glfw_view.cpp7
-rwxr-xr-xscripts/generate-style-code.js7
-rw-r--r--scripts/style-spec.js42
-rw-r--r--src/mbgl/renderer/layers/render_location_indicator_layer.cpp3
-rw-r--r--src/mbgl/style/conversion/function.cpp2
-rw-r--r--src/mbgl/style/conversion/property_value.cpp6
-rw-r--r--src/mbgl/style/conversion/rotation.cpp20
-rw-r--r--src/mbgl/style/expression/value.cpp10
-rw-r--r--src/mbgl/style/layers/location_indicator_layer.cpp80
-rw-r--r--src/mbgl/style/layers/location_indicator_layer_properties.hpp11
26 files changed, 231 insertions, 68 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fcce303960..c024d7f6cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -160,6 +160,7 @@ add_library(
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/light.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/position.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/property_value.hpp
+ ${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/rotation.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/source.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/tileset.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/transition_options.hpp
@@ -217,6 +218,7 @@ add_library(
${PROJECT_SOURCE_DIR}/include/mbgl/style/position.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/property_expression.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/property_value.hpp
+ ${PROJECT_SOURCE_DIR}/include/mbgl/style/rotation.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/source.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/custom_geometry_source.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/geojson_source.hpp
@@ -548,6 +550,7 @@ add_library(
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/light.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/position.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/property_value.cpp
+ ${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/rotation.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/source.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/stringify.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/tileset.cpp
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 {
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index e538d934a3..c65df4d1cb 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -988,7 +988,8 @@ void GLFWView::toggleLocationIndicatorLayer() {
puckLayer->setAccuracyRadiusColor(
premultiply(mbgl::Color{0.0, 1.0, 0.0, 0.2})); // Note: these must be fed premultiplied
- puckLayer->setBearing(0);
+ puckLayer->setBearingTransition(mbgl::style::TransitionOptions(mbgl::Duration::zero(), mbgl::Duration::zero()));
+ puckLayer->setBearing(mbgl::style::Rotation(0.0));
puckLayer->setAccuracyRadiusBorderColor(premultiply(mbgl::Color{0.0, 1.0, 0.2, 0.4}));
puckLayer->setTopImageSize(24);
puckLayer->setBearingImageSize(72);
@@ -1038,8 +1039,8 @@ void GLFWView::onWillStartRenderingFrame() {
puck = static_cast<mbgl::style::LocationIndicatorLayer *>(map->getStyle().getLayer("puck"));
if (puck) {
uint64_t ns = mbgl::Clock::now().time_since_epoch().count();
- const float bearing = float(ns % 2000000000) / 2000000000.0 * 360.0;
- puck->setBearing(bearing);
+ const double bearing = double(ns % 2000000000) / 2000000000.0 * 360.0;
+ puck->setBearing(mbgl::style::Rotation(bearing));
}
#endif
}
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index 08fd1fba19..c9191d59e1 100755
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -64,6 +64,13 @@ global.evaluatedType = function (property) {
case 'boolean':
return 'bool';
case 'number':
+ // TODO: Check if 'Rotation' should be used for other properties,
+ // such as icon-rotate
+ if (/bearing$/.test(property.name) &&
+ property.period == 360 &&
+ property.units =='degrees') {
+ return 'Rotation';
+ }
return /location$/.test(property.name) ? 'double' : 'float';
case 'resolvedImage':
return 'expression::Image';
diff --git a/scripts/style-spec.js b/scripts/style-spec.js
index c0acbebd91..15a4c7e0dc 100644
--- a/scripts/style-spec.js
+++ b/scripts/style-spec.js
@@ -47,20 +47,6 @@ referenceSpec["layout_location-indicator"] = {
},
"doc": "The amount of the perspective compensation, between 0 and 1. A value of 1 produces a location indicator of constant width across the screen. A value of 0 makes it scale naturally according to the viewing projection."
},
- "bearing": {
- "type": "number",
- "default": "0",
- "default": 0,
- "period": 360,
- "units": "degrees",
- "property-type": "data-constant",
- "expression": {
- "interpolated": false,
- "parameters": [ ]
- },
- "transition": false,
- "doc": "The bearing of the location indicator."
- },
"image-tilt-displacement": {
"type": "number",
"property-type": "data-constant",
@@ -77,6 +63,20 @@ referenceSpec["layout_location-indicator"] = {
};
referenceSpec["paint_location-indicator"] = {
+ "bearing": {
+ "type": "number",
+ "default": "0",
+ "default": 0,
+ "period": 360,
+ "units": "degrees",
+ "property-type": "data-constant",
+ "expression": {
+ "interpolated": false,
+ "parameters": [ ]
+ },
+ "transition": false,
+ "doc": "The bearing of the location indicator."
+ },
"location": {
"type": "array",
"default": [
@@ -176,6 +176,20 @@ referenceSpec["paint_location-indicator"] = {
},
"transition": true,
"doc": "The color for drawing the accuracy radius border. To adjust transparency, set the alpha component of the color accordingly."
+ },
+ "bearing": {
+ "type": "number",
+ "default": "0",
+ "default": 0,
+ "period": 360,
+ "units": "degrees",
+ "property-type": "data-constant",
+ "expression": {
+ "interpolated": false,
+ "parameters": [ ]
+ },
+ "transition": false,
+ "doc": "The bearing of the location indicator."
}
};
diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
index 20c3bb8cfe..94ac46e216 100644
--- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
+++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
@@ -714,13 +714,12 @@ void RenderLocationIndicatorLayer::evaluate(const PropertyEvaluationParameters&
renderImpl->parameters.puckSizePx = evaluated.get<style::BearingImageSize>();
renderImpl->parameters.puckHatSizePx = evaluated.get<style::TopImageSize>();
renderImpl->parameters.puckShadowSizePx = evaluated.get<style::ShadowImageSize>();
+ renderImpl->parameters.puckBearing = evaluated.get<style::Bearing>().getAngle();
const std::array<double, 3> pos = evaluated.get<style::Location>();
renderImpl->parameters.puckPosition = LatLng{pos[0], pos[1]};
// layout
- if (!layout.get<style::Bearing>().isUndefined())
- renderImpl->parameters.puckBearing = layout.get<style::Bearing>().asConstant();
if (!layout.get<style::BearingImage>().isUndefined())
renderImpl->parameters.puckImagePath = layout.get<style::BearingImage>().asConstant().id();
if (!layout.get<style::ShadowImage>().isUndefined())
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index 6c2bcdf10f..19ad643a23 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -1,5 +1,6 @@
#include <mbgl/style/conversion/function.hpp>
#include <mbgl/style/conversion/position.hpp>
+#include <mbgl/style/conversion/rotation.hpp>
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/style/expression/case.hpp>
#include <mbgl/style/expression/dsl.hpp>
@@ -159,6 +160,7 @@ template optional<PropertyExpression<Formatted>>
template optional<PropertyExpression<std::vector<TextWritingModeType>>>
convertFunctionToExpression<std::vector<TextWritingModeType>>(const Convertible&, Error&, bool);
template optional<PropertyExpression<Image>> convertFunctionToExpression<Image>(const Convertible&, Error&, bool);
+template optional<PropertyExpression<Rotation>> convertFunctionToExpression<Rotation>(const Convertible&, Error&, bool);
// Ad-hoc Converters for double and int64_t. We should replace float with double wholesale,
// and promote the int64_t Converter to general use (and it should check that the input is
diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp
index 1a0e686850..2fbeb4dd44 100644
--- a/src/mbgl/style/conversion/property_value.cpp
+++ b/src/mbgl/style/conversion/property_value.cpp
@@ -1,5 +1,6 @@
-#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/position.hpp>
+#include <mbgl/style/conversion/property_value.hpp>
+#include <mbgl/style/conversion/rotation.hpp>
#include <mbgl/style/conversion_impl.hpp>
namespace mbgl {
@@ -107,6 +108,9 @@ mbgl::style::conversion::Converter<PropertyValue<std::array<double, 3>>, void>::
return r;
}
+template optional<PropertyValue<Rotation>> Converter<PropertyValue<Rotation>>::operator()(
+ conversion::Convertible const&, conversion::Error&, bool, bool) const;
+
} // namespace conversion
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/conversion/rotation.cpp b/src/mbgl/style/conversion/rotation.cpp
new file mode 100644
index 0000000000..11431437dd
--- /dev/null
+++ b/src/mbgl/style/conversion/rotation.cpp
@@ -0,0 +1,20 @@
+#include <mbgl/style/conversion/constant.hpp>
+#include <mbgl/style/conversion/rotation.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+optional<style::Rotation> Converter<style::Rotation>::operator()(const Convertible& value, Error& error) const {
+ optional<double> converted = toDouble(value);
+ if (!converted) {
+ error.message = "value must be a number";
+ return nullopt;
+ }
+ return {*converted};
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index 9f40d17b02..2ceac4588b 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -269,6 +269,15 @@ optional<Position> ValueConverter<Position>::fromExpressionValue(const Value& v)
return pos ? optional<Position>(Position(*pos)) : optional<Position>();
}
+Value ValueConverter<Rotation>::toExpressionValue(const mbgl::style::Rotation& value) {
+ return ValueConverter<float>::toExpressionValue(value.getAngle());
+}
+
+optional<Rotation> ValueConverter<Rotation>::fromExpressionValue(const Value& v) {
+ auto angle = ValueConverter<float>::fromExpressionValue(v);
+ return angle ? optional<Rotation>(Rotation(*angle)) : optional<Rotation>();
+}
+
template <typename T>
Value ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >>::toExpressionValue(const T& value) {
return std::string(Enum<T>::toString(value));
@@ -317,6 +326,7 @@ template struct ValueConverter<std::array<double, 3>>;
// layout/paint property types
template type::Type valueTypeToExpressionType<float>();
template type::Type valueTypeToExpressionType<Position>();
+template type::Type valueTypeToExpressionType<Rotation>();
template type::Type valueTypeToExpressionType<std::array<float, 2>>();
template struct ValueConverter<std::array<float, 2>>;
diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp
index 03b826cc18..178fd104ad 100644
--- a/src/mbgl/style/layers/location_indicator_layer.cpp
+++ b/src/mbgl/style/layers/location_indicator_layer.cpp
@@ -63,21 +63,6 @@ void LocationIndicatorLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::
// Layout properties
-PropertyValue<float> LocationIndicatorLayer::getDefaultBearing() {
- return Bearing::defaultValue();
-}
-
-const PropertyValue<float>& LocationIndicatorLayer::getBearing() const {
- return impl().layout.get<Bearing>();
-}
-
-void LocationIndicatorLayer::setBearing(const PropertyValue<float>& value) {
- if (value == getBearing()) return;
- auto impl_ = mutableImpl();
- impl_->layout.get<Bearing>() = value;
- baseImpl = std::move(impl_);
- observer->onLayerChanged(*this);
-}
PropertyValue<expression::Image> LocationIndicatorLayer::getDefaultBearingImage() {
return BearingImage::defaultValue();
}
@@ -237,6 +222,33 @@ TransitionOptions LocationIndicatorLayer::getAccuracyRadiusColorTransition() con
return impl().paint.template get<AccuracyRadiusColor>().options;
}
+PropertyValue<Rotation> LocationIndicatorLayer::getDefaultBearing() {
+ return {0};
+}
+
+const PropertyValue<Rotation>& LocationIndicatorLayer::getBearing() const {
+ return impl().paint.template get<Bearing>().value;
+}
+
+void LocationIndicatorLayer::setBearing(const PropertyValue<Rotation>& value) {
+ if (value == getBearing())
+ return;
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<Bearing>().value = value;
+ baseImpl = std::move(impl_);
+ observer->onLayerChanged(*this);
+}
+
+void LocationIndicatorLayer::setBearingTransition(const TransitionOptions& options) {
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<Bearing>().options = options;
+ baseImpl = std::move(impl_);
+}
+
+TransitionOptions LocationIndicatorLayer::getBearingTransition() const {
+ return impl().paint.template get<Bearing>().options;
+}
+
PropertyValue<float> LocationIndicatorLayer::getDefaultBearingImageSize() {
return {0};
}
@@ -349,12 +361,13 @@ using namespace conversion;
namespace {
-constexpr uint8_t kPaintPropertyCount = 14u;
+constexpr uint8_t kPaintPropertyCount = 16u;
enum class Property : uint8_t {
AccuracyRadius,
AccuracyRadiusBorderColor,
AccuracyRadiusColor,
+ Bearing,
BearingImageSize,
Location,
ShadowImageSize,
@@ -362,12 +375,12 @@ enum class Property : uint8_t {
AccuracyRadiusTransition,
AccuracyRadiusBorderColorTransition,
AccuracyRadiusColorTransition,
+ BearingTransition,
BearingImageSizeTransition,
LocationTransition,
ShadowImageSizeTransition,
TopImageSizeTransition,
- Bearing = kPaintPropertyCount,
- BearingImage,
+ BearingImage = kPaintPropertyCount,
ImageTiltDisplacement,
PerspectiveCompensation,
ShadowImage,
@@ -383,6 +396,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<
{{"accuracy-radius", toUint8(Property::AccuracyRadius)},
{"accuracy-radius-border-color", toUint8(Property::AccuracyRadiusBorderColor)},
{"accuracy-radius-color", toUint8(Property::AccuracyRadiusColor)},
+ {"bearing", toUint8(Property::Bearing)},
{"bearing-image-size", toUint8(Property::BearingImageSize)},
{"location", toUint8(Property::Location)},
{"shadow-image-size", toUint8(Property::ShadowImageSize)},
@@ -390,11 +404,11 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<
{"accuracy-radius-transition", toUint8(Property::AccuracyRadiusTransition)},
{"accuracy-radius-border-color-transition", toUint8(Property::AccuracyRadiusBorderColorTransition)},
{"accuracy-radius-color-transition", toUint8(Property::AccuracyRadiusColorTransition)},
+ {"bearing-transition", toUint8(Property::BearingTransition)},
{"bearing-image-size-transition", toUint8(Property::BearingImageSizeTransition)},
{"location-transition", toUint8(Property::LocationTransition)},
{"shadow-image-size-transition", toUint8(Property::ShadowImageSizeTransition)},
{"top-image-size-transition", toUint8(Property::TopImageSizeTransition)},
- {"bearing", toUint8(Property::Bearing)},
{"bearing-image", toUint8(Property::BearingImage)},
{"image-tilt-displacement", toUint8(Property::ImageTiltDisplacement)},
{"perspective-compensation", toUint8(Property::PerspectiveCompensation)},
@@ -409,6 +423,8 @@ StyleProperty getLayerProperty(const LocationIndicatorLayer& layer, Property pro
return makeStyleProperty(layer.getAccuracyRadiusBorderColor());
case Property::AccuracyRadiusColor:
return makeStyleProperty(layer.getAccuracyRadiusColor());
+ case Property::Bearing:
+ return makeStyleProperty(layer.getBearing());
case Property::BearingImageSize:
return makeStyleProperty(layer.getBearingImageSize());
case Property::Location:
@@ -423,6 +439,8 @@ StyleProperty getLayerProperty(const LocationIndicatorLayer& layer, Property pro
return makeStyleProperty(layer.getAccuracyRadiusBorderColorTransition());
case Property::AccuracyRadiusColorTransition:
return makeStyleProperty(layer.getAccuracyRadiusColorTransition());
+ case Property::BearingTransition:
+ return makeStyleProperty(layer.getBearingTransition());
case Property::BearingImageSizeTransition:
return makeStyleProperty(layer.getBearingImageSizeTransition());
case Property::LocationTransition:
@@ -431,8 +449,6 @@ StyleProperty getLayerProperty(const LocationIndicatorLayer& layer, Property pro
return makeStyleProperty(layer.getShadowImageSizeTransition());
case Property::TopImageSizeTransition:
return makeStyleProperty(layer.getTopImageSizeTransition());
- case Property::Bearing:
- return makeStyleProperty(layer.getBearing());
case Property::BearingImage:
return makeStyleProperty(layer.getBearingImage());
case Property::ImageTiltDisplacement:
@@ -475,7 +491,7 @@ optional<Error> LocationIndicatorLayer::setPropertyInternal(const std::string& n
auto property = static_cast<Property>(it->second);
if (property == Property::AccuracyRadius || property == Property::BearingImageSize ||
- property == Property::ShadowImageSize || property == Property::TopImageSize || property == Property::Bearing ||
+ property == Property::ShadowImageSize || property == Property::TopImageSize ||
property == Property::ImageTiltDisplacement || property == Property::PerspectiveCompensation) {
Error error;
const auto& typedValue = convert<PropertyValue<float>>(value, error, false, false);
@@ -503,11 +519,6 @@ optional<Error> LocationIndicatorLayer::setPropertyInternal(const std::string& n
return nullopt;
}
- if (property == Property::Bearing) {
- setBearing(*typedValue);
- return nullopt;
- }
-
if (property == Property::ImageTiltDisplacement) {
setImageTiltDisplacement(*typedValue);
return nullopt;
@@ -535,6 +546,16 @@ optional<Error> LocationIndicatorLayer::setPropertyInternal(const std::string& n
return nullopt;
}
}
+ if (property == Property::Bearing) {
+ Error error;
+ const auto& typedValue = convert<PropertyValue<Rotation>>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setBearing(*typedValue);
+ return nullopt;
+ }
if (property == Property::Location) {
Error error;
const auto& typedValue = convert<PropertyValue<std::array<double, 3>>>(value, error, false, false);
@@ -589,6 +610,11 @@ optional<Error> LocationIndicatorLayer::setPropertyInternal(const std::string& n
return nullopt;
}
+ if (property == Property::BearingTransition) {
+ setBearingTransition(*transition);
+ return nullopt;
+ }
+
if (property == Property::BearingImageSizeTransition) {
setBearingImageSizeTransition(*transition);
return nullopt;
diff --git a/src/mbgl/style/layers/location_indicator_layer_properties.hpp b/src/mbgl/style/layers/location_indicator_layer_properties.hpp
index d1f0879f74..d73ce33eb9 100644
--- a/src/mbgl/style/layers/location_indicator_layer_properties.hpp
+++ b/src/mbgl/style/layers/location_indicator_layer_properties.hpp
@@ -16,11 +16,6 @@
namespace mbgl {
namespace style {
-struct Bearing : LayoutProperty<float> {
- static constexpr const char *name() { return "bearing"; }
- static float defaultValue() { return 0; }
-};
-
struct BearingImage : LayoutProperty<expression::Image> {
static constexpr const char *name() { return "bearing-image"; }
static expression::Image defaultValue() { return {}; }
@@ -58,6 +53,10 @@ struct AccuracyRadiusColor : PaintProperty<Color> {
static Color defaultValue() { return Color::white(); }
};
+struct Bearing : PaintProperty<Rotation> {
+ static Rotation defaultValue() { return 0; }
+};
+
struct BearingImageSize : PaintProperty<float> {
static float defaultValue() { return 0; }
};
@@ -75,7 +74,6 @@ struct TopImageSize : PaintProperty<float> {
};
class LocationIndicatorLayoutProperties : public Properties<
- Bearing,
BearingImage,
ImageTiltDisplacement,
PerspectiveCompensation,
@@ -87,6 +85,7 @@ class LocationIndicatorPaintProperties : public Properties<
AccuracyRadius,
AccuracyRadiusBorderColor,
AccuracyRadiusColor,
+ Bearing,
BearingImageSize,
Location,
ShadowImageSize,