summaryrefslogtreecommitdiff
path: root/src/mbgl/style
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 /src/mbgl/style
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 'src/mbgl/style')
-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
6 files changed, 95 insertions, 34 deletions
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,