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.
This commit is contained in:
@@ -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
|
||||
|
||||
18
include/mbgl/style/conversion/rotation.hpp
Normal file
18
include/mbgl/style/conversion/rotation.hpp
Normal file
@@ -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
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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') { -%>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>&);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
25
include/mbgl/style/rotation.hpp
Normal file
25
include/mbgl/style/rotation.hpp
Normal file
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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."
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
20
src/mbgl/style/conversion/rotation.cpp
Normal file
20
src/mbgl/style/conversion/rotation.cpp
Normal file
@@ -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
|
||||
@@ -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>>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user