From 8e581c88ea855998a2746e57f1a5fc46ee62faee Mon Sep 17 00:00:00 2001 From: Gali Nelle Date: Mon, 6 Apr 2020 10:12:56 +0300 Subject: [PATCH] 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. --- CMakeLists.txt | 3 + include/mbgl/style/conversion/rotation.hpp | 18 +++++ include/mbgl/style/conversion_impl.hpp | 6 ++ include/mbgl/style/expression/value.hpp | 8 ++ .../mbgl/style/layers/background_layer.hpp | 1 - include/mbgl/style/layers/circle_layer.hpp | 1 - .../style/layers/fill_extrusion_layer.hpp | 1 - include/mbgl/style/layers/fill_layer.hpp | 1 - include/mbgl/style/layers/heatmap_layer.hpp | 1 - include/mbgl/style/layers/hillshade_layer.hpp | 1 - include/mbgl/style/layers/layer.hpp.ejs | 5 ++ include/mbgl/style/layers/line_layer.hpp | 1 - .../style/layers/location_indicator_layer.hpp | 12 +-- include/mbgl/style/layers/raster_layer.hpp | 1 - include/mbgl/style/rotation.hpp | 25 ++++++ include/mbgl/util/interpolate.hpp | 26 +++++- platform/glfw/glfw_view.cpp | 7 +- scripts/generate-style-code.js | 7 ++ scripts/style-spec.js | 42 ++++++---- .../render_location_indicator_layer.cpp | 3 +- src/mbgl/style/conversion/function.cpp | 2 + src/mbgl/style/conversion/property_value.cpp | 6 +- src/mbgl/style/conversion/rotation.cpp | 20 +++++ src/mbgl/style/expression/value.cpp | 10 +++ .../style/layers/location_indicator_layer.cpp | 80 ++++++++++++------- .../location_indicator_layer_properties.hpp | 11 ++- 26 files changed, 231 insertions(+), 68 deletions(-) create mode 100644 include/mbgl/style/conversion/rotation.hpp create mode 100644 include/mbgl/style/rotation.hpp create mode 100644 src/mbgl/style/conversion/rotation.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fcce30396..c024d7f6c 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 000000000..86d67240f --- /dev/null +++ b/include/mbgl/style/conversion/rotation.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { + optional 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 79e930184..8652a355f 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -343,6 +344,11 @@ struct ValueFactory { } }; +template <> +struct ValueFactory { + static Value make(const Rotation& rotation) { return {rotation.getAngle()}; } +}; + template Value makeValue(T&& arg) { return ValueFactory>::make(std::forward(arg)); diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index 902f5ae20..6f12bb933 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -147,6 +148,13 @@ std::vector> fromExpressionValues(const std::vector> return result; } +template <> +struct ValueConverter { + static type::Type expressionType() { return type::Number; } + static Value toExpressionValue(const mbgl::style::Rotation& value); + static optional 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 9fdfd3ac9..2a46b2fc2 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index dd5b67400..f0e9787ca 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index ca33c6c3f..3e4973b82 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 4a1f09cca..fb386c4b1 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 588aaa81d..371e9a8aa 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index c501e80b8..7149fb46d 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index a083829f6..a81aaa9e1 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -15,7 +15,12 @@ #include #include #include +<% if (type === 'location-indicator') { -%> +#include +<% } -%> +<% if (type === 'symbol') { -%> #include +<% } -%> #include <% if (type === 'line' || type === 'symbol') { -%> diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 2186f1666..7d7da47bf 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/include/mbgl/style/layers/location_indicator_layer.hpp b/include/mbgl/style/layers/location_indicator_layer.hpp index e9e67c1a2..f112664da 100644 --- a/include/mbgl/style/layers/location_indicator_layer.hpp +++ b/include/mbgl/style/layers/location_indicator_layer.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include namespace mbgl { @@ -22,10 +22,6 @@ public: // Layout properties - static PropertyValue getDefaultBearing(); - const PropertyValue& getBearing() const; - void setBearing(const PropertyValue&); - static PropertyValue getDefaultBearingImage(); const PropertyValue& getBearingImage() const; void setBearingImage(const PropertyValue&); @@ -66,6 +62,12 @@ public: void setAccuracyRadiusColorTransition(const TransitionOptions&); TransitionOptions getAccuracyRadiusColorTransition() const; + static PropertyValue getDefaultBearing(); + const PropertyValue& getBearing() const; + void setBearing(const PropertyValue&); + void setBearingTransition(const TransitionOptions&); + TransitionOptions getBearingTransition() const; + static PropertyValue getDefaultBearingImageSize(); const PropertyValue& getBearingImageSize() const; void setBearingImageSize(const PropertyValue&); diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index df82c9366..78fa3db23 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/rotation.hpp b/include/mbgl/style/rotation.hpp new file mode 100644 index 000000000..862ede93b --- /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() 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 aff730a0a..566f2b0a6 100644 --- a/include/mbgl/util/interpolate.hpp +++ b/include/mbgl/util/interpolate.hpp @@ -1,9 +1,10 @@ #pragma once +#include +#include +#include #include #include -#include -#include #include #include @@ -102,6 +103,27 @@ public: } }; +template <> +struct Interpolator { +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 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 e538d934a..c65df4d1c 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(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 08fd1fba1..c9191d59e 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 c0acbebd9..15a4c7e0d 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 20c3bb8cf..94ac46e21 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(); renderImpl->parameters.puckHatSizePx = evaluated.get(); renderImpl->parameters.puckShadowSizePx = evaluated.get(); + renderImpl->parameters.puckBearing = evaluated.get().getAngle(); const std::array pos = evaluated.get(); renderImpl->parameters.puckPosition = LatLng{pos[0], pos[1]}; // layout - if (!layout.get().isUndefined()) - renderImpl->parameters.puckBearing = layout.get().asConstant(); if (!layout.get().isUndefined()) renderImpl->parameters.puckImagePath = layout.get().asConstant().id(); if (!layout.get().isUndefined()) diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index 6c2bcdf10..19ad643a2 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -159,6 +160,7 @@ template optional> template optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); template optional> convertFunctionToExpression(const Convertible&, Error&, bool); +template optional> convertFunctionToExpression(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 1a0e68685..2fbeb4dd4 100644 --- a/src/mbgl/style/conversion/property_value.cpp +++ b/src/mbgl/style/conversion/property_value.cpp @@ -1,5 +1,6 @@ -#include #include +#include +#include #include namespace mbgl { @@ -107,6 +108,9 @@ mbgl::style::conversion::Converter>, void>:: return r; } +template optional> Converter>::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 000000000..11431437d --- /dev/null +++ b/src/mbgl/style/conversion/rotation.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +optional Converter::operator()(const Convertible& value, Error& error) const { + optional 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 9f40d17b0..2ceac4588 100644 --- a/src/mbgl/style/expression/value.cpp +++ b/src/mbgl/style/expression/value.cpp @@ -269,6 +269,15 @@ optional ValueConverter::fromExpressionValue(const Value& v) return pos ? optional(Position(*pos)) : optional(); } +Value ValueConverter::toExpressionValue(const mbgl::style::Rotation& value) { + return ValueConverter::toExpressionValue(value.getAngle()); +} + +optional ValueConverter::fromExpressionValue(const Value& v) { + auto angle = ValueConverter::fromExpressionValue(v); + return angle ? optional(Rotation(*angle)) : optional(); +} + template Value ValueConverter::value >>::toExpressionValue(const T& value) { return std::string(Enum::toString(value)); @@ -317,6 +326,7 @@ template struct ValueConverter>; // layout/paint property types template type::Type valueTypeToExpressionType(); template type::Type valueTypeToExpressionType(); +template type::Type valueTypeToExpressionType(); template type::Type valueTypeToExpressionType>(); template struct ValueConverter>; diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp index 03b826cc1..178fd104a 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 LocationIndicatorLayer::getDefaultBearing() { - return Bearing::defaultValue(); -} - -const PropertyValue& LocationIndicatorLayer::getBearing() const { - return impl().layout.get(); -} - -void LocationIndicatorLayer::setBearing(const PropertyValue& value) { - if (value == getBearing()) return; - auto impl_ = mutableImpl(); - impl_->layout.get() = value; - baseImpl = std::move(impl_); - observer->onLayerChanged(*this); -} PropertyValue LocationIndicatorLayer::getDefaultBearingImage() { return BearingImage::defaultValue(); } @@ -237,6 +222,33 @@ TransitionOptions LocationIndicatorLayer::getAccuracyRadiusColorTransition() con return impl().paint.template get().options; } +PropertyValue LocationIndicatorLayer::getDefaultBearing() { + return {0}; +} + +const PropertyValue& LocationIndicatorLayer::getBearing() const { + return impl().paint.template get().value; +} + +void LocationIndicatorLayer::setBearing(const PropertyValue& value) { + if (value == getBearing()) + return; + auto impl_ = mutableImpl(); + impl_->paint.template get().value = value; + baseImpl = std::move(impl_); + observer->onLayerChanged(*this); +} + +void LocationIndicatorLayer::setBearingTransition(const TransitionOptions& options) { + auto impl_ = mutableImpl(); + impl_->paint.template get().options = options; + baseImpl = std::move(impl_); +} + +TransitionOptions LocationIndicatorLayer::getBearingTransition() const { + return impl().paint.template get().options; +} + PropertyValue 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 LocationIndicatorLayer::setPropertyInternal(const std::string& n auto property = static_cast(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>(value, error, false, false); @@ -503,11 +519,6 @@ optional 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 LocationIndicatorLayer::setPropertyInternal(const std::string& n return nullopt; } } + if (property == Property::Bearing) { + Error error; + const auto& typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + setBearing(*typedValue); + return nullopt; + } if (property == Property::Location) { Error error; const auto& typedValue = convert>>(value, error, false, false); @@ -589,6 +610,11 @@ optional 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 d1f0879f7..d73ce33eb 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 { - static constexpr const char *name() { return "bearing"; } - static float defaultValue() { return 0; } -}; - struct BearingImage : LayoutProperty { static constexpr const char *name() { return "bearing-image"; } static expression::Image defaultValue() { return {}; } @@ -58,6 +53,10 @@ struct AccuracyRadiusColor : PaintProperty { static Color defaultValue() { return Color::white(); } }; +struct Bearing : PaintProperty { + static Rotation defaultValue() { return 0; } +}; + struct BearingImageSize : PaintProperty { static float defaultValue() { return 0; } }; @@ -75,7 +74,6 @@ struct TopImageSize : PaintProperty { }; class LocationIndicatorLayoutProperties : public Properties< - Bearing, BearingImage, ImageTiltDisplacement, PerspectiveCompensation, @@ -87,6 +85,7 @@ class LocationIndicatorPaintProperties : public Properties< AccuracyRadius, AccuracyRadiusBorderColor, AccuracyRadiusColor, + Bearing, BearingImageSize, Location, ShadowImageSize,