summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-02-04 11:05:36 -0800
committerAnsis Brammanis <brammanis@gmail.com>2015-02-04 11:05:36 -0800
commit465b1ac3eb45cbb946476ca73f421f02da225175 (patch)
treee7d29cf8f969250c1e94479b8778e52e10e0af9e /src/mbgl/style
parentc9f8de863dc93e4fd587290357c8a3b572a4f956 (diff)
parent002a709b67ac1ac36d4711a913a3fc082494ff71 (diff)
downloadqtlocation-mapboxgl-465b1ac3eb45cbb946476ca73f421f02da225175.tar.gz
Merge branch 'master' into pattern-functions
Conflicts: src/mbgl/renderer/painter.cpp src/mbgl/renderer/painter.hpp src/mbgl/renderer/painter_fill.cpp src/mbgl/renderer/painter_line.cpp src/mbgl/style/style_layer.cpp src/mbgl/style/style_layer.hpp src/mbgl/style/style_layer_group.cpp src/mbgl/style/style_layer_group.hpp
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/applied_class_properties.cpp10
-rw-r--r--src/mbgl/style/applied_class_properties.hpp14
-rw-r--r--src/mbgl/style/fadedfunction_properties.cpp4
-rw-r--r--src/mbgl/style/fadedfunction_properties.hpp8
-rw-r--r--src/mbgl/style/property_fallback.cpp43
-rw-r--r--src/mbgl/style/property_key.hpp46
-rw-r--r--src/mbgl/style/property_transition.hpp7
-rw-r--r--src/mbgl/style/property_value.hpp9
-rw-r--r--src/mbgl/style/style.cpp9
-rw-r--r--src/mbgl/style/style.hpp9
-rw-r--r--src/mbgl/style/style_bucket.cpp16
-rw-r--r--src/mbgl/style/style_bucket.hpp56
-rw-r--r--src/mbgl/style/style_layer.cpp34
-rw-r--r--src/mbgl/style/style_layer.hpp15
-rw-r--r--src/mbgl/style/style_layer_group.cpp6
-rw-r--r--src/mbgl/style/style_layer_group.hpp5
-rw-r--r--src/mbgl/style/style_parser.cpp226
-rw-r--r--src/mbgl/style/style_parser.hpp4
-rw-r--r--src/mbgl/style/types.hpp12
-rw-r--r--src/mbgl/style/zoom_history.hpp9
20 files changed, 350 insertions, 192 deletions
diff --git a/src/mbgl/style/applied_class_properties.cpp b/src/mbgl/style/applied_class_properties.cpp
index 9037c6ad5d..6e304e69d1 100644
--- a/src/mbgl/style/applied_class_properties.cpp
+++ b/src/mbgl/style/applied_class_properties.cpp
@@ -2,18 +2,18 @@
namespace mbgl {
-AppliedClassProperty::AppliedClassProperty(ClassID class_id, timestamp begin_, timestamp end_, const PropertyValue &value_)
+AppliedClassProperty::AppliedClassProperty(ClassID class_id, std::chrono::steady_clock::time_point begin_, std::chrono::steady_clock::time_point end_, const PropertyValue &value_)
: name(class_id),
begin(begin_),
end(end_),
value(value_) {}
-// Returns thie ID of the most recent
+// Returns the ID of the most recent
ClassID AppliedClassProperties::mostRecent() const {
return properties.size() ? properties.back().name : ClassID::Fallback;
}
-void AppliedClassProperties::add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value) {
+void AppliedClassProperties::add(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value) {
properties.emplace_back(class_id, begin, end, value);
}
@@ -23,7 +23,7 @@ bool AppliedClassProperties::hasTransitions() const {
// Erase all items in the property list that are before a completed transition.
// Then, if the only remaining property is a Fallback value, remove it too.
-void AppliedClassProperties::cleanup(timestamp now) {
+void AppliedClassProperties::cleanup(std::chrono::steady_clock::time_point now) {
// Iterate backwards, but without using the rbegin/rend interface since we need forward
// iterators to use .erase().
for (auto it = properties.end(), begin = properties.begin(); it != begin;) {
@@ -49,4 +49,4 @@ bool AppliedClassProperties::empty() const {
return properties.empty();
}
-} \ No newline at end of file
+}
diff --git a/src/mbgl/style/applied_class_properties.hpp b/src/mbgl/style/applied_class_properties.hpp
index 827f15a2a1..bd84095590 100644
--- a/src/mbgl/style/applied_class_properties.hpp
+++ b/src/mbgl/style/applied_class_properties.hpp
@@ -3,20 +3,20 @@
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/class_dictionary.hpp>
-#include <mbgl/util/time.hpp>
#include <list>
+#include <chrono>
namespace mbgl {
class AppliedClassProperty {
public:
- AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value);
+ AppliedClassProperty(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value);
public:
const ClassID name;
- const timestamp begin;
- const timestamp end;
+ const std::chrono::steady_clock::time_point begin;
+ const std::chrono::steady_clock::time_point end;
const PropertyValue value;
};
@@ -26,11 +26,11 @@ public:
std::list<AppliedClassProperty> properties;
public:
- // Returns thie ID of the most recent
+ // Returns the ID of the most recent
ClassID mostRecent() const;
- void add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value);
+ void add(ClassID class_id, std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, const PropertyValue &value);
bool hasTransitions() const;
- void cleanup(timestamp now);
+ void cleanup(std::chrono::steady_clock::time_point now);
bool empty() const;
};
diff --git a/src/mbgl/style/fadedfunction_properties.cpp b/src/mbgl/style/fadedfunction_properties.cpp
index 8ac4f3be42..21c3267519 100644
--- a/src/mbgl/style/fadedfunction_properties.cpp
+++ b/src/mbgl/style/fadedfunction_properties.cpp
@@ -20,9 +20,7 @@ T FadedStopsFunction<T>::evaluate(float z, const ZoomHistory &zh) const {
T result;
float fraction = std::fmod(z, 1.0f);
- float tDiff = (util::now() - zh.lastIntegerZoomTime) / 1_millisecond;
- float fDuration = duration / 1_millisecond;
- float t = std::min(tDiff / fDuration, 1.0f);
+ float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f);
float scale = 1.0f;
uint32_t low, high;
diff --git a/src/mbgl/style/fadedfunction_properties.hpp b/src/mbgl/style/fadedfunction_properties.hpp
index 23b4411369..7313d32759 100644
--- a/src/mbgl/style/fadedfunction_properties.hpp
+++ b/src/mbgl/style/fadedfunction_properties.hpp
@@ -9,14 +9,14 @@ namespace mbgl {
template <typename T>
struct FadedStopsFunction {
- inline FadedStopsFunction(const std::vector<std::pair<float, T>> &values_, timestamp duration_) : values(values_), duration(duration_) {}
- inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(300_milliseconds) {}
- inline FadedStopsFunction() : values(), duration(300_milliseconds) {}
+ inline FadedStopsFunction(const std::vector<std::pair<float, T>> &values_, std::chrono::duration<float> duration_) : values(values_), duration(duration_) {}
+ inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(300) {}
+ inline FadedStopsFunction() : values(), duration(300) {}
T evaluate(float z, const ZoomHistory &zoomHistory) const;
private:
const std::vector<std::pair<float, T>> values;
- const timestamp duration;
+ const std::chrono::duration<float> duration;
};
}
diff --git a/src/mbgl/style/property_fallback.cpp b/src/mbgl/style/property_fallback.cpp
index dc747b37e6..5fc3ce1f04 100644
--- a/src/mbgl/style/property_fallback.cpp
+++ b/src/mbgl/style/property_fallback.cpp
@@ -1,5 +1,6 @@
#include <mbgl/style/property_fallback.hpp>
#include <mbgl/style/style_properties.hpp>
+#include <mbgl/style/style_bucket.hpp>
namespace mbgl {
@@ -52,6 +53,48 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::BackgroundOpacity, defaultStyleProperties<BackgroundProperties>().opacity },
{ PropertyKey::BackgroundColor, defaultStyleProperties<BackgroundProperties>().color },
+
+ { PropertyKey::LineCap, defaultLayoutProperties<StyleBucketLine>().cap },
+ { PropertyKey::LineJoin, defaultLayoutProperties<StyleBucketLine>().join },
+ { PropertyKey::LineMiterLimit, defaultLayoutProperties<StyleBucketLine>().miter_limit },
+ { PropertyKey::LineRoundLimit, defaultLayoutProperties<StyleBucketLine>().round_limit },
+
+ { PropertyKey::SymbolPlacement, defaultLayoutProperties<StyleBucketSymbol>().placement },
+ { PropertyKey::SymbolMinDistance, defaultLayoutProperties<StyleBucketSymbol>().min_distance },
+ { PropertyKey::SymbolAvoidEdges, defaultLayoutProperties<StyleBucketSymbol>().avoid_edges },
+
+ { PropertyKey::IconAllowOverlap, defaultLayoutProperties<StyleBucketSymbol>().icon.allow_overlap },
+ { PropertyKey::IconIgnorePlacement, defaultLayoutProperties<StyleBucketSymbol>().icon.ignore_placement },
+ { PropertyKey::IconOptional, defaultLayoutProperties<StyleBucketSymbol>().icon.optional },
+ { PropertyKey::IconRotationAlignment, defaultLayoutProperties<StyleBucketSymbol>().icon.rotation_alignment },
+ { PropertyKey::IconMaxSize, defaultLayoutProperties<StyleBucketSymbol>().icon.max_size },
+ { PropertyKey::IconImage, defaultLayoutProperties<StyleBucketSymbol>().icon.image },
+ { PropertyKey::IconRotate, defaultLayoutProperties<StyleBucketSymbol>().icon.rotate },
+ { PropertyKey::IconPadding, defaultLayoutProperties<StyleBucketSymbol>().icon.padding },
+ { PropertyKey::IconKeepUpright, defaultLayoutProperties<StyleBucketSymbol>().icon.keep_upright },
+ { PropertyKey::IconOffsetX, defaultLayoutProperties<StyleBucketSymbol>().icon.offset[0] },
+ { PropertyKey::IconOffsetY, defaultLayoutProperties<StyleBucketSymbol>().icon.offset[1] },
+
+ { PropertyKey::TextRotationAlignment, defaultLayoutProperties<StyleBucketSymbol>().text.rotation_alignment },
+ { PropertyKey::TextField, defaultLayoutProperties<StyleBucketSymbol>().text.field },
+ { PropertyKey::TextFont, defaultLayoutProperties<StyleBucketSymbol>().text.font },
+ { PropertyKey::TextMaxSize, defaultLayoutProperties<StyleBucketSymbol>().text.max_size },
+ { PropertyKey::TextMaxWidth, defaultLayoutProperties<StyleBucketSymbol>().text.max_width },
+ { PropertyKey::TextLineHeight, defaultLayoutProperties<StyleBucketSymbol>().text.line_height },
+ { PropertyKey::TextLetterSpacing, defaultLayoutProperties<StyleBucketSymbol>().text.letter_spacing },
+ { PropertyKey::TextJustify, defaultLayoutProperties<StyleBucketSymbol>().text.justify },
+ { PropertyKey::TextAnchor, defaultLayoutProperties<StyleBucketSymbol>().text.anchor },
+ { PropertyKey::TextMaxAngle, defaultLayoutProperties<StyleBucketSymbol>().text.max_angle },
+ { PropertyKey::TextRotate, defaultLayoutProperties<StyleBucketSymbol>().text.rotate },
+ { PropertyKey::TextPadding, defaultLayoutProperties<StyleBucketSymbol>().text.padding },
+ { PropertyKey::TextKeepUpright, defaultLayoutProperties<StyleBucketSymbol>().text.keep_upright },
+ { PropertyKey::TextTransform, defaultLayoutProperties<StyleBucketSymbol>().text.transform },
+ { PropertyKey::TextOffsetX, defaultLayoutProperties<StyleBucketSymbol>().text.offset[0] },
+ { PropertyKey::TextOffsetY, defaultLayoutProperties<StyleBucketSymbol>().text.offset[1] },
+ { PropertyKey::TextAllowOverlap, defaultLayoutProperties<StyleBucketSymbol>().text.allow_overlap },
+ { PropertyKey::TextIgnorePlacement, defaultLayoutProperties<StyleBucketSymbol>().text.ignore_placement },
+ { PropertyKey::TextOptional, defaultLayoutProperties<StyleBucketSymbol>().text.optional },
+
};
const PropertyValue PropertyFallbackValue::defaultProperty = false;
diff --git a/src/mbgl/style/property_key.hpp b/src/mbgl/style/property_key.hpp
index e283f11579..f10607a7af 100644
--- a/src/mbgl/style/property_key.hpp
+++ b/src/mbgl/style/property_key.hpp
@@ -26,8 +26,16 @@ enum class PropertyKey {
LineDashArray, // for transitions only
LineImage,
+ LineCap,
+ LineJoin,
+ LineMiterLimit,
+ LineRoundLimit,
+
+ SymbolPlacement,
+ SymbolMinDistance,
+ SymbolAvoidEdges,
+
IconOpacity,
- IconRotate,
IconSize,
IconColor,
IconHaloColor,
@@ -38,6 +46,18 @@ enum class PropertyKey {
IconTranslateY,
IconTranslateAnchor,
+ IconAllowOverlap,
+ IconIgnorePlacement,
+ IconOptional,
+ IconRotationAlignment,
+ IconMaxSize,
+ IconImage,
+ IconPadding,
+ IconRotate,
+ IconKeepUpright,
+ IconOffsetX,
+ IconOffsetY,
+
TextOpacity,
TextSize,
TextColor,
@@ -49,6 +69,26 @@ enum class PropertyKey {
TextTranslateY,
TextTranslateAnchor,
+ TextRotationAlignment,
+ TextField,
+ TextFont,
+ TextMaxSize,
+ TextMaxWidth,
+ TextLineHeight,
+ TextLetterSpacing,
+ TextMaxAngle,
+ TextRotate,
+ TextPadding,
+ TextIgnorePlacement,
+ TextOptional,
+ TextJustify,
+ TextAnchor,
+ TextKeepUpright,
+ TextTransform,
+ TextOffsetX,
+ TextOffsetY,
+ TextAllowOverlap,
+
RasterOpacity,
RasterHueRotate,
RasterBrightness, // for transitions only
@@ -60,7 +100,9 @@ enum class PropertyKey {
BackgroundOpacity,
BackgroundColor,
- BackgroundImage
+ BackgroundImage,
+
+ Visibilty
};
}
diff --git a/src/mbgl/style/property_transition.hpp b/src/mbgl/style/property_transition.hpp
index 07b7cfe288..cf9167cc0f 100644
--- a/src/mbgl/style/property_transition.hpp
+++ b/src/mbgl/style/property_transition.hpp
@@ -2,14 +2,15 @@
#define MBGL_STYLE_PROPERTY_TRANSITION
#include <cstdint>
+#include <chrono>
namespace mbgl {
struct PropertyTransition {
- uint16_t duration = 0;
- uint16_t delay = 0;
+ std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero();
+ std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero();
};
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp
index 8dcb8d7371..49e837cf12 100644
--- a/src/mbgl/style/property_value.hpp
+++ b/src/mbgl/style/property_value.hpp
@@ -14,6 +14,15 @@ typedef mapbox::util::variant<
std::string,
TranslateAnchorType,
RotateAnchorType,
+ bool,
+ CapType,
+ JoinType,
+ VisibilityType,
+ PlacementType,
+ RotationAlignmentType,
+ TextTransformType,
+ TextJustifyType,
+ TextAnchorType,
Function<bool>,
Function<float>,
Function<Color>,
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index dc764106ce..45217950f6 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -4,7 +4,6 @@
#include <mbgl/style/style_parser.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/util/time.hpp>
#include <mbgl/util/error.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/uv_detail.hpp>
@@ -26,7 +25,7 @@ Style::Style()
// for deleting the std::unique_ptr<uv::rwlock>.
Style::~Style() {}
-void Style::updateProperties(float z, timestamp now) {
+void Style::updateProperties(float z, std::chrono::steady_clock::time_point now) {
uv::writelock lock(mtx);
zoomHistory.update(z, now);
@@ -46,13 +45,13 @@ const std::string &Style::getSpriteURL() const {
return sprite_url;
}
-void Style::setDefaultTransitionDuration(uint16_t duration_milliseconds) {
- defaultTransition.duration = duration_milliseconds;
+void Style::setDefaultTransitionDuration(std::chrono::steady_clock::duration duration) {
+ defaultTransition.duration = duration;
}
void Style::cascadeClasses(const std::vector<std::string>& classes) {
if (layers) {
- layers->setClasses(classes, util::now(), defaultTransition);
+ layers->setClasses(classes, std::chrono::steady_clock::now(), defaultTransition);
}
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 434b394217..4de827a38c 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -5,7 +5,6 @@
#include <mbgl/style/style_source.hpp>
#include <mbgl/style/zoom_history.hpp>
-#include <mbgl/util/time.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/util/ptr.hpp>
@@ -15,6 +14,7 @@
#include <unordered_map>
#include <vector>
#include <set>
+#include <chrono>
namespace mbgl {
@@ -22,7 +22,7 @@ class Sprite;
class StyleLayer;
class StyleLayerGroup;
-class Style {
+class Style : public util::noncopyable {
public:
struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} };
@@ -32,9 +32,9 @@ public:
void loadJSON(const uint8_t *const data);
size_t layerCount() const;
- void updateProperties(float z, timestamp t);
+ void updateProperties(float z, std::chrono::steady_clock::time_point now);
- void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0);
+ void setDefaultTransitionDuration(std::chrono::steady_clock::duration duration = std::chrono::steady_clock::duration::zero());
void cascadeClasses(const std::vector<std::string>&);
bool hasTransitions() const;
@@ -44,6 +44,7 @@ public:
util::ptr<StyleLayerGroup> layers;
std::vector<std::string> appliedClasses;
std::string glyph_url;
+ std::string base;
private:
std::string sprite_url;
diff --git a/src/mbgl/style/style_bucket.cpp b/src/mbgl/style/style_bucket.cpp
index 9a40c2386b..6e866f3035 100644
--- a/src/mbgl/style/style_bucket.cpp
+++ b/src/mbgl/style/style_bucket.cpp
@@ -2,12 +2,18 @@
namespace mbgl {
-StyleBucket::StyleBucket(StyleLayerType type) {
+template<> const StyleBucketFill &defaultLayoutProperties() { static StyleBucketFill p; return p; }
+template<> const StyleBucketLine &defaultLayoutProperties() { static StyleBucketLine p; return p; }
+template<> const StyleBucketSymbol &defaultLayoutProperties() { static StyleBucketSymbol p; return p; }
+template<> const StyleBucketRaster &defaultLayoutProperties() { static StyleBucketRaster p; return p; }
+template<> const StyleBucketBackground &defaultLayoutProperties() { static StyleBucketBackground p; return p; }
+
+StyleBucket::StyleBucket(StyleLayerType type_) : type(type_) {
switch (type) {
- case StyleLayerType::Fill: render = StyleBucketFill{}; break;
- case StyleLayerType::Line: render = StyleBucketLine{}; break;
- case StyleLayerType::Symbol: render = StyleBucketSymbol{}; break;
- case StyleLayerType::Raster: render = StyleBucketRaster{}; break;
+ case StyleLayerType::Fill: render.set<StyleBucketFill>(); break;
+ case StyleLayerType::Line: render.set<StyleBucketLine>(); break;
+ case StyleLayerType::Symbol: render.set<StyleBucketSymbol>(); break;
+ case StyleLayerType::Raster: render.set<StyleBucketRaster>(); break;
default: break;
}
}
diff --git a/src/mbgl/style/style_bucket.hpp b/src/mbgl/style/style_bucket.hpp
index 7a70e32c34..eac899cb97 100644
--- a/src/mbgl/style/style_bucket.hpp
+++ b/src/mbgl/style/style_bucket.hpp
@@ -9,6 +9,7 @@
#include <mbgl/util/variant.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
+#include <mbgl/style/class_properties.hpp>
#include <forward_list>
@@ -18,11 +19,23 @@ class Source;
class StyleBucketFill {
public:
- WindingType winding = WindingType::NonZero;
+ // Make movable only.
+ StyleBucketFill() = default;
+ StyleBucketFill(StyleBucketFill &&) = default;
+ StyleBucketFill& operator=(StyleBucketFill &&) = default;
+ StyleBucketFill(const StyleBucketFill &) = delete;
+ StyleBucketFill& operator=(const StyleBucketFill &) = delete;
};
class StyleBucketLine {
public:
+ // Make movable only.
+ StyleBucketLine() = default;
+ StyleBucketLine(StyleBucketLine &&) = default;
+ StyleBucketLine& operator=(StyleBucketLine &&) = default;
+ StyleBucketLine(const StyleBucketLine &) = delete;
+ StyleBucketLine& operator=(const StyleBucketLine &) = delete;
+
CapType cap = CapType::Butt;
JoinType join = JoinType::Miter;
float miter_limit = 2.0f;
@@ -32,11 +45,11 @@ public:
class StyleBucketSymbol {
public:
// Make movable only.
- inline StyleBucketSymbol() = default;
- inline StyleBucketSymbol(StyleBucketSymbol &&) = default;
- inline StyleBucketSymbol& operator=(StyleBucketSymbol &&) = default;
- inline StyleBucketSymbol(const StyleBucketSymbol &) = delete;
- inline StyleBucketSymbol& operator=(const StyleBucketSymbol &) = delete;
+ StyleBucketSymbol() = default;
+ StyleBucketSymbol(StyleBucketSymbol &&) = default;
+ StyleBucketSymbol& operator=(StyleBucketSymbol &&) = default;
+ StyleBucketSymbol(const StyleBucketSymbol &) = delete;
+ StyleBucketSymbol& operator=(const StyleBucketSymbol &) = delete;
PlacementType placement = PlacementType::Point;
float min_distance = 250.0f;
@@ -52,7 +65,7 @@ public:
float rotate = 0.0f;
float padding = 2.0f;
bool keep_upright = false;
- vec2<float> offset = {0, 0};
+ std::array<float, 2> offset = {{ 0, 0 }};
} icon;
struct {
@@ -60,18 +73,17 @@ public:
std::string field;
std::string font;
float max_size = 16.0f;
- float max_width = 15.0f * 24 /* em */;
- float line_height = 1.2f * 24 /* em */;
- float letter_spacing = 0.0f * 24 /* em */;
+ float max_width = 15.0f /* em */;
+ float line_height = 1.2f /* em */;
+ float letter_spacing = 0.0f /* em */;
TextJustifyType justify = TextJustifyType::Center;
TextAnchorType anchor = TextAnchorType::Center;
float max_angle = 45.0f /* degrees */;
float rotate = 0.0f;
- float slant = 0.0f;
float padding = 2.0f;
bool keep_upright = true;
TextTransformType transform = TextTransformType::None;
- vec2<float> offset = {0, 0};
+ std::array<float, 2> offset = {{ 0, 0 }};
bool allow_overlap = false;
bool ignore_placement = false;
bool optional = false;
@@ -80,29 +92,41 @@ public:
class StyleBucketRaster {
public:
+ // Make movable only.
+ StyleBucketRaster() = default;
+ StyleBucketRaster(StyleBucketRaster &&) = default;
+ StyleBucketRaster& operator=(StyleBucketRaster &&) = default;
+ StyleBucketRaster(const StyleBucketRaster &) = delete;
+ StyleBucketRaster& operator=(const StyleBucketRaster &) = delete;
+};
+
+class StyleBucketBackground {
+public:
};
typedef mapbox::util::variant<StyleBucketFill, StyleBucketLine, StyleBucketSymbol,
- StyleBucketRaster, std::false_type> StyleBucketRender;
+ StyleBucketRaster, StyleBucketBackground, std::false_type> StyleBucketRender;
-class StyleBucket {
+class StyleBucket : public util::noncopyable {
public:
typedef util::ptr<StyleBucket> Ptr;
StyleBucket(StyleLayerType type);
-
+ StyleLayerType type;
std::string name;
util::ptr<StyleSource> style_source;
std::string source_layer;
FilterExpression filter;
+ ClassProperties layout;
StyleBucketRender render = std::false_type();
float min_zoom = -std::numeric_limits<float>::infinity();
float max_zoom = std::numeric_limits<float>::infinity();
VisibilityType visibility = VisibilityType::Visible;
};
-
+template <typename T>
+const T &defaultLayoutProperties();
};
diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp
index bb9688e574..795c651b85 100644
--- a/src/mbgl/style/style_layer.cpp
+++ b/src/mbgl/style/style_layer.cpp
@@ -14,7 +14,7 @@ bool StyleLayer::isBackground() const {
return type == StyleLayerType::Background;
}
-void StyleLayer::setClasses(const std::vector<std::string> &class_names, const timestamp now,
+void StyleLayer::setClasses(const std::vector<std::string> &class_names, const std::chrono::steady_clock::time_point now,
const PropertyTransition &defaultTransition) {
// Stores all keys that we have already added transitions for.
std::set<PropertyKey> already_applied;
@@ -45,8 +45,8 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t
if (appliedProperties.mostRecent() != ClassID::Fallback) {
// This property key hasn't been set by a previous class, so we need to add a transition
// to the fallback value for that key.
- const timestamp begin = now + defaultTransition.delay * 1_millisecond;
- const timestamp end = begin + defaultTransition.duration * 1_millisecond;
+ const std::chrono::steady_clock::time_point begin = now + defaultTransition.delay;
+ const std::chrono::steady_clock::time_point end = begin + defaultTransition.duration;
const PropertyValue &value = PropertyFallbackValue::Get(key);
appliedProperties.add(ClassID::Fallback, begin, end, value);
}
@@ -55,7 +55,7 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t
// Helper function for applying all properties of a a single class that haven't been applied yet.
void StyleLayer::applyClassProperties(const ClassID class_id,
- std::set<PropertyKey> &already_applied, timestamp now,
+ std::set<PropertyKey> &already_applied, std::chrono::steady_clock::time_point now,
const PropertyTransition &defaultTransition) {
auto style_it = styles.find(class_id);
if (style_it == styles.end()) {
@@ -83,8 +83,8 @@ void StyleLayer::applyClassProperties(const ClassID class_id,
if (appliedProperties.mostRecent() != class_id) {
const PropertyTransition &transition =
class_properties.getTransition(key, defaultTransition);
- const timestamp begin = now + transition.delay * 1_millisecond;
- const timestamp end = begin + transition.duration * 1_millisecond;
+ const std::chrono::steady_clock::time_point begin = now + transition.delay;
+ const std::chrono::steady_clock::time_point end = begin + transition.duration;
const PropertyValue &value = property_pair.second;
appliedProperties.add(class_id, begin, end, value);
}
@@ -120,7 +120,7 @@ private:
};
template <typename T>
-void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
auto it = appliedStyle.find(key);
if (it != appliedStyle.end()) {
AppliedClassProperties &applied = it->second;
@@ -138,7 +138,7 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c
}
template <typename T>
-void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
auto it = appliedStyle.find(key);
if (it != appliedStyle.end()) {
AppliedClassProperties &applied = it->second;
@@ -150,7 +150,7 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons
target = mapbox::util::apply_visitor(evaluator, property.value);
} else if (now >= property.begin) {
// We overwrite the current property partially with the new value.
- float progress = float(now - property.begin) / float(property.end - property.begin);
+ float progress = std::chrono::duration<float>(now - property.begin) / (property.end - property.begin);
target = util::interpolate(target, mapbox::util::apply_visitor(evaluator, property.value), progress);
} else {
// Do not apply this property because its transition hasn't begun yet.
@@ -160,7 +160,7 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons
}
template <>
-void StyleLayer::applyStyleProperties<FillProperties>(const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperties<FillProperties>(const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
properties.set<FillProperties>();
FillProperties &fill = properties.get<FillProperties>();
applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now, zoomHistory);
@@ -174,7 +174,7 @@ void StyleLayer::applyStyleProperties<FillProperties>(const float z, const times
}
template <>
-void StyleLayer::applyStyleProperties<LineProperties>(const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperties<LineProperties>(const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
properties.set<LineProperties>();
LineProperties &line = properties.get<LineProperties>();
applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now, zoomHistory);
@@ -189,11 +189,11 @@ void StyleLayer::applyStyleProperties<LineProperties>(const float z, const times
applyStyleProperty(PropertyKey::LineImage, line.image, z, now, zoomHistory);
// for scaling dasharrays
- applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), now + 10000, zoomHistory);
+ applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), std::chrono::steady_clock::time_point::max(), zoomHistory);
}
template <>
-void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
properties.set<SymbolProperties>();
SymbolProperties &symbol = properties.get<SymbolProperties>();
applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now, zoomHistory);
@@ -219,7 +219,7 @@ void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const tim
}
template <>
-void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
properties.set<RasterProperties>();
RasterProperties &raster = properties.get<RasterProperties>();
applyTransitionedStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now, zoomHistory);
@@ -232,7 +232,7 @@ void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const tim
}
template <>
-void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const timestamp now, const ZoomHistory &zoomHistory) {
+void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory) {
properties.set<BackgroundProperties>();
BackgroundProperties &background = properties.get<BackgroundProperties>();
applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now, zoomHistory);
@@ -240,7 +240,7 @@ void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const
applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now, zoomHistory);
}
-void StyleLayer::updateProperties(float z, const timestamp now, ZoomHistory &zoomHistory) {
+void StyleLayer::updateProperties(float z, const std::chrono::steady_clock::time_point now, ZoomHistory &zoomHistory) {
cleanupAppliedStyleProperties(now);
switch (type) {
@@ -263,7 +263,7 @@ bool StyleLayer::hasTransitions() const {
}
-void StyleLayer::cleanupAppliedStyleProperties(timestamp now) {
+void StyleLayer::cleanupAppliedStyleProperties(std::chrono::steady_clock::time_point now) {
auto it = appliedStyle.begin();
const auto end = appliedStyle.end();
while (it != end) {
diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp
index 8531ad3a05..69af1dc230 100644
--- a/src/mbgl/style/style_layer.hpp
+++ b/src/mbgl/style/style_layer.hpp
@@ -13,6 +13,7 @@
#include <string>
#include <map>
#include <set>
+#include <chrono>
namespace mbgl {
@@ -36,10 +37,10 @@ public:
// Updates the StyleProperties information in this layer by evaluating all
// pending transitions and applied classes in order.
- void updateProperties(float z, timestamp now, ZoomHistory &zoomHistory);
+ void updateProperties(float z, std::chrono::steady_clock::time_point now, ZoomHistory &zoomHistory);
// Sets the list of classes and creates transitions to the currently applied values.
- void setClasses(const std::vector<std::string> &class_names, timestamp now,
+ void setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
const PropertyTransition &defaultTransition);
bool hasTransitions() const;
@@ -47,16 +48,16 @@ public:
private:
// Applies all properties from a class, if they haven't been applied already.
void applyClassProperties(ClassID class_id, std::set<PropertyKey> &already_applied,
- timestamp now, const PropertyTransition &defaultTransition);
+ std::chrono::steady_clock::time_point now, const PropertyTransition &defaultTransition);
// Sets the properties of this object by evaluating all pending transitions and
// aplied classes in order.
- template <typename T> void applyStyleProperties(float z, timestamp now, const ZoomHistory &zoomHistory);
- template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, timestamp now, const ZoomHistory &zoomHistory);
- template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now, const ZoomHistory &zoomHistory);
+ template <typename T> void applyStyleProperties(float z, std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory);
+ template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory);
+ template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, std::chrono::steady_clock::time_point now, const ZoomHistory &zoomHistory);
// Removes all expired style transitions.
- void cleanupAppliedStyleProperties(timestamp now);
+ void cleanupAppliedStyleProperties(std::chrono::steady_clock::time_point now);
public:
// The name of this layer.
diff --git a/src/mbgl/style/style_layer_group.cpp b/src/mbgl/style/style_layer_group.cpp
index 5ca020ee74..f57ec5cc7b 100644
--- a/src/mbgl/style/style_layer_group.cpp
+++ b/src/mbgl/style/style_layer_group.cpp
@@ -2,7 +2,7 @@
namespace mbgl {
-void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, timestamp now,
+void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
const PropertyTransition &defaultTransition) {
for (const util::ptr<StyleLayer> &layer : layers) {
if (layer) {
@@ -11,10 +11,10 @@ void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, ti
}
}
-void StyleLayerGroup::updateProperties(float z, timestamp t, ZoomHistory &zoomHistory) {
+void StyleLayerGroup::updateProperties(float z, std::chrono::steady_clock::time_point now, ZoomHistory &zoomHistory) {
for (const util::ptr<StyleLayer> &layer: layers) {
if (layer) {
- layer->updateProperties(z, t, zoomHistory);
+ layer->updateProperties(z, now, zoomHistory);
}
}
}
diff --git a/src/mbgl/style/style_layer_group.hpp b/src/mbgl/style/style_layer_group.hpp
index 85cfcc6dd6..79b75a55e9 100644
--- a/src/mbgl/style/style_layer_group.hpp
+++ b/src/mbgl/style/style_layer_group.hpp
@@ -4,14 +4,15 @@
#include <mbgl/style/style_layer.hpp>
#include <vector>
+#include <chrono>
namespace mbgl {
class StyleLayerGroup {
public:
- void setClasses(const std::vector<std::string> &class_names, timestamp now,
+ void setClasses(const std::vector<std::string> &class_names, std::chrono::steady_clock::time_point now,
const PropertyTransition &defaultTransition);
- void updateProperties(float z, timestamp t, ZoomHistory &zoomHistory);
+ void updateProperties(float z, std::chrono::steady_clock::time_point now, ZoomHistory &zoomHistory);
bool hasTransitions() const;
public:
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index 454e786573..1fc57e2f7e 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -341,7 +341,7 @@ std::tuple<bool, Function<T>> StyleParser::parseFunction(JSVal value) {
return std::tuple<bool, Function<T>> { true, StopsFunction<T>(std::get<1>(stops), base) };
}
-template <typename T> inline timestamp defaultDurationValue() { return 300_milliseconds; }
+template <typename T> inline std::chrono::duration<float> defaultDurationValue() { return std::chrono::duration<float>(300.0f); }
template <typename T>
std::tuple<bool, FadedStopsFunction<T>> StyleParser::parseFadedStopsFunction(JSVal value) {
@@ -350,13 +350,12 @@ std::tuple<bool, FadedStopsFunction<T>> StyleParser::parseFadedStopsFunction(JSV
return std::tuple<bool, FadedStopsFunction<T>> { false, {} };
}
- timestamp duration = defaultDurationValue<T>();
+ std::chrono::duration<float> duration = defaultDurationValue<T>();
if (value.HasMember("duration")) {
JSVal value_duration = value["duration"];
if (value_duration.IsNumber()) {
- float duration_ = value_duration.GetDouble();
- duration = 1_millisecond * duration_;
+ duration = static_cast<std::chrono::duration<float>>(value_duration.GetDouble());
} else {
Log::Warning(Event::ParseStyle, "duration must be numeric");
}
@@ -381,6 +380,18 @@ bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKe
}
template<typename T>
+void StyleParser::parseVisibility(StyleBucket &bucket, JSVal value) {
+ if (!value.HasMember("visibility")) {
+ return;
+ } else if (!value["visibility"].IsString()) {
+ Log::Warning(Event::ParseStyle, "value of 'visibility' must be a string");
+ bucket.visibility = VisibilityType::Visible;
+ return;
+ }
+ bucket.visibility = VisibilityTypeClass({ value["visibility"].GetString(), value["visibility"].GetStringLength() });
+}
+
+template<typename T>
bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value) {
if (!value.HasMember(property_name)) {
return false;
@@ -398,6 +409,15 @@ template<> std::tuple<bool, std::string> StyleParser::parseProperty(JSVal value,
return std::tuple<bool, std::string> { true, { value.GetString(), value.GetStringLength() } };
}
+template<> std::tuple<bool, bool> StyleParser::parseProperty(JSVal value, const char *property_name) {
+ if (!value.IsBool()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a boolean", property_name);
+ return std::tuple<bool, bool> { false, true };
+ }
+
+ return std::tuple<bool, bool> { true, value.GetBool() };
+}
+
template<> std::tuple<bool, TranslateAnchorType> StyleParser::parseProperty(JSVal value, const char *property_name) {
if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
@@ -416,18 +436,81 @@ template<> std::tuple<bool, RotateAnchorType> StyleParser::parseProperty<RotateA
return std::tuple<bool, RotateAnchorType> { true, RotateAnchorTypeClass({ value.GetString(), value.GetStringLength() }) };
}
+template<> std::tuple<bool, CapType> StyleParser::parseProperty<CapType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, CapType> { false, CapType::Butt };
+ }
+
+ return std::tuple<bool, CapType> { true, CapTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, JoinType> StyleParser::parseProperty<JoinType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, JoinType> { false, JoinType::Miter };
+ }
+
+ return std::tuple<bool, JoinType> { true, JoinTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, PlacementType> StyleParser::parseProperty<PlacementType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, PlacementType> { false, PlacementType::Point };
+ }
+
+ return std::tuple<bool, PlacementType> { true, PlacementTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, TextAnchorType> StyleParser::parseProperty<TextAnchorType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, TextAnchorType> { false, TextAnchorType::Center };
+ }
+
+ return std::tuple<bool, TextAnchorType> { true, TextAnchorTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, TextJustifyType> StyleParser::parseProperty<TextJustifyType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, TextJustifyType> { false, TextJustifyType::Center };
+ }
+
+ return std::tuple<bool, TextJustifyType> { true, TextJustifyTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, TextTransformType> StyleParser::parseProperty<TextTransformType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, TextTransformType> { false, TextTransformType::None };
+ }
+
+ return std::tuple<bool, TextTransformType> { true, TextTransformTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
+template<> std::tuple<bool, RotationAlignmentType> StyleParser::parseProperty<RotationAlignmentType>(JSVal value, const char *property_name) {
+ if (!value.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name);
+ return std::tuple<bool, RotationAlignmentType> { false, RotationAlignmentType::Map };
+ }
+
+ return std::tuple<bool, RotationAlignmentType> { true, RotationAlignmentTypeClass({ value.GetString(), value.GetStringLength() }) };
+}
+
template<> std::tuple<bool, PropertyTransition> StyleParser::parseProperty(JSVal value, const char */*property_name*/) {
PropertyTransition transition;
if (value.IsObject()) {
if (value.HasMember("duration") && value["duration"].IsNumber()) {
- transition.duration = value["duration"].GetUint();
+ transition.duration = std::chrono::milliseconds(value["duration"].GetUint());
}
if (value.HasMember("delay") && value["delay"].IsNumber()) {
- transition.delay = value["delay"].GetUint();
+ transition.delay = std::chrono::milliseconds(value["delay"].GetUint());
}
}
- if (transition.duration == 0 && transition.delay == 0) {
+ if (transition.duration == std::chrono::steady_clock::duration::zero() && transition.delay == std::chrono::steady_clock::duration::zero()) {
return std::tuple<bool, PropertyTransition> { false, std::move(transition) };
}
@@ -710,6 +793,50 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<FadedStopsFunction<Faded<std::string>>>("background-image", Key::BackgroundImage, klass, value);
}
+void StyleParser::parseLayout(JSVal value, util::ptr<StyleBucket> &bucket) {
+ using Key = PropertyKey;
+
+ parseVisibility<VisibilityType>(*bucket, value);
+
+ parseOptionalProperty<CapType>("line-cap", Key::LineCap, bucket->layout, value);
+ parseOptionalProperty<JoinType>("line-join", Key::LineJoin, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("line-miter-limit", Key::LineMiterLimit, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("line-round-limit", Key::LineRoundLimit, bucket->layout, value);
+
+ parseOptionalProperty<PlacementType>("symbol-placement", Key::SymbolPlacement, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("symbol-min-distance", Key::SymbolMinDistance, bucket->layout, value);
+ parseOptionalProperty<bool>("symbol-avoid-edges", Key::SymbolAvoidEdges, bucket->layout, value);
+ parseOptionalProperty<bool>("icon-allow-overlap", Key::IconAllowOverlap, bucket->layout, value);
+ parseOptionalProperty<bool>("icon-ignore-placement", Key::IconIgnorePlacement, bucket->layout, value);
+ parseOptionalProperty<bool>("icon-optional", Key::IconOptional, bucket->layout, value);
+ parseOptionalProperty<RotationAlignmentType>("icon-rotation-alignment", Key::IconRotationAlignment, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("icon-max-size", Key::IconMaxSize, bucket->layout, value);
+ parseOptionalProperty<std::string>("icon-image", Key::IconImage, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("icon-rotate", Key::IconRotate, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("icon-padding", Key::IconPadding, bucket->layout, value);
+ parseOptionalProperty<bool>("icon-keep-upright", Key::IconKeepUpright, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("icon-offset", { Key::IconOffsetX, Key::IconOffsetY }, bucket->layout, value);
+ parseOptionalProperty<RotationAlignmentType>("text-rotation-alignment", Key::TextRotationAlignment, bucket->layout, value);
+ parseOptionalProperty<std::string>("text-field", Key::TextField, bucket->layout, value);
+ parseOptionalProperty<std::string>("text-font", Key::TextFont, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-max-size", Key::TextMaxSize, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-max-width", Key::TextMaxWidth, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-line-height", Key::TextLineHeight, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-letter-spacing", Key::TextLetterSpacing, bucket->layout, value);
+ parseOptionalProperty<TextJustifyType>("text-justify", Key::TextJustify, bucket->layout, value);
+ parseOptionalProperty<TextAnchorType>("text-anchor", Key::TextAnchor, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-max-angle", Key::TextMaxAngle, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-rotate", Key::TextRotate, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-padding", Key::TextPadding, bucket->layout, value);
+ parseOptionalProperty<bool>("text-keep-upright", Key::TextKeepUpright, bucket->layout, value);
+ parseOptionalProperty<TextTransformType>("text-transform", Key::TextTransform, bucket->layout, value);
+ parseOptionalProperty<Function<float>>("text-offset", { Key::TextOffsetX, Key::TextOffsetY }, bucket->layout, value);
+ parseOptionalProperty<bool>("text-allow-overlap", Key::TextAllowOverlap, bucket->layout, value);
+ parseOptionalProperty<bool>("text-ignore-placement", Key::TextIgnorePlacement, bucket->layout, value);
+ parseOptionalProperty<bool>("text-optional", Key::TextOptional, bucket->layout, value);
+
+}
+
void StyleParser::parseReference(JSVal value, util::ptr<StyleLayer> &layer) {
if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "layer ref of '%s' must be a string", layer->id.c_str());
@@ -772,7 +899,7 @@ void StyleParser::parseBucket(JSVal value, util::ptr<StyleLayer> &layer) {
if (value.HasMember("layout")) {
JSVal value_render = replaceConstant(value["layout"]);
- parseLayout(value_render, layer);
+ parseLayout(value_render, layer->bucket);
}
if (value.HasMember("minzoom")) {
@@ -794,89 +921,6 @@ void StyleParser::parseBucket(JSVal value, util::ptr<StyleLayer> &layer) {
}
}
-void StyleParser::parseLayout(JSVal value, util::ptr<StyleLayer> &layer) {
- if (!value.IsObject()) {
- Log::Warning(Event::ParseStyle, "layout property of layer '%s' must be an object", layer->id.c_str());
- return;
- }
-
- StyleBucket &bucket = *layer->bucket;
- parseRenderProperty<VisibilityTypeClass>(value, bucket.visibility, "visibility");
-
- switch (layer->type) {
- case StyleLayerType::Fill: {
- StyleBucketFill &render = bucket.render.get<StyleBucketFill>();
-
- parseRenderProperty<WindingTypeClass>(value, render.winding, "fill-winding");
- } break;
-
- case StyleLayerType::Line: {
- StyleBucketLine &render = bucket.render.get<StyleBucketLine>();
-
- parseRenderProperty<CapTypeClass>(value, render.cap, "line-cap");
- parseRenderProperty<JoinTypeClass>(value, render.join, "line-join");
- parseRenderProperty(value, render.miter_limit, "line-miter-limit");
- parseRenderProperty(value, render.round_limit, "line-round-limit");
- } break;
-
- case StyleLayerType::Symbol: {
- StyleBucketSymbol &render = bucket.render.get<StyleBucketSymbol>();
-
- parseRenderProperty<PlacementTypeClass>(value, render.placement, "symbol-placement");
- if (render.placement == PlacementType::Line) {
- // Change the default value in case of line placement.
- render.text.rotation_alignment = RotationAlignmentType::Map;
- render.icon.rotation_alignment = RotationAlignmentType::Map;
- }
-
- parseRenderProperty(value, render.min_distance, "symbol-min-distance");
- parseRenderProperty(value, render.avoid_edges, "symbol-avoid-edges");
-
- parseRenderProperty(value, render.icon.allow_overlap, "icon-allow-overlap");
- parseRenderProperty(value, render.icon.ignore_placement, "icon-ignore-placement");
- parseRenderProperty(value, render.icon.optional, "icon-optional");
- parseRenderProperty<RotationAlignmentTypeClass>(value, render.icon.rotation_alignment, "icon-rotation-alignment");
- parseRenderProperty(value, render.icon.max_size, "icon-max-size");
- parseRenderProperty(value, render.icon.image, "icon-image");
- parseRenderProperty(value, render.icon.rotate, "icon-rotate");
- parseRenderProperty(value, render.icon.padding, "icon-padding");
- parseRenderProperty(value, render.icon.keep_upright, "icon-keep-upright");
- parseRenderProperty(value, render.icon.offset, "icon-offset");
-
-
- parseRenderProperty<RotationAlignmentTypeClass>(value, render.text.rotation_alignment, "text-rotation-alignment");
- parseRenderProperty(value, render.text.field, "text-field");
- parseRenderProperty(value, render.text.font, "text-font");
- parseRenderProperty(value, render.text.max_size, "text-max-size");
- if (parseRenderProperty(value, render.text.max_width, "text-max-width")) {
- render.text.max_width *= 24; // em
- }
- if (parseRenderProperty(value, render.text.line_height, "text-line-height")) {
- render.text.line_height *= 24; // em
- }
- if (parseRenderProperty(value, render.text.letter_spacing, "text-letter-spacing")) {
- render.text.letter_spacing *= 24; // em
- }
- parseRenderProperty<TextJustifyTypeClass>(value, render.text.justify, "text-justify");
- parseRenderProperty<TextAnchorTypeClass>(value, render.text.anchor, "text-anchor");
- parseRenderProperty(value, render.text.max_angle, "text-max-angle");
- parseRenderProperty(value, render.text.rotate, "text-rotate");
- parseRenderProperty(value, render.text.slant, "text-slant");
- parseRenderProperty(value, render.text.padding, "text-padding");
- parseRenderProperty(value, render.text.keep_upright, "text-keep-upright");
- parseRenderProperty<TextTransformTypeClass>(value, render.text.transform, "text-transform");
- parseRenderProperty(value, render.text.offset, "text-offset");
- parseRenderProperty(value, render.text.allow_overlap, "text-allow-overlap");
- parseRenderProperty(value, render.text.ignore_placement, "text-ignore-placement");
- parseRenderProperty(value, render.text.optional, "text-optional");
- } break;
-
- default:
- // There are no render properties for these layer types.
- break;
- }
-}
-
void StyleParser::parseSprite(JSVal value) {
if (value.IsString()) {
sprite = { value.GetString(), value.GetStringLength() };
diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp
index 482fa0a00b..5b55d6116e 100644
--- a/src/mbgl/style/style_parser.hpp
+++ b/src/mbgl/style/style_parser.hpp
@@ -53,7 +53,7 @@ private:
void parsePaint(JSVal, ClassProperties &properties);
void parseReference(JSVal value, util::ptr<StyleLayer> &layer);
void parseBucket(JSVal value, util::ptr<StyleLayer> &layer);
- void parseLayout(JSVal value, util::ptr<StyleLayer> &layer);
+ void parseLayout(JSVal value, util::ptr<StyleBucket> &bucket);
void parseSprite(JSVal value);
void parseGlyphURL(JSVal value);
@@ -65,6 +65,8 @@ private:
// Parses optional properties into style class properties.
template <typename T>
+ void parseVisibility(StyleBucket &bucket, JSVal value);
+ template <typename T>
bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value);
template <typename T>
bool parseOptionalProperty(const char *property_name, const std::vector<PropertyKey> &keys, ClassProperties &klass, JSVal value);
diff --git a/src/mbgl/style/types.hpp b/src/mbgl/style/types.hpp
index cd9c29d30a..b7d675857a 100644
--- a/src/mbgl/style/types.hpp
+++ b/src/mbgl/style/types.hpp
@@ -72,18 +72,6 @@ MBGL_DEFINE_ENUM_CLASS(VisibilityTypeClass, VisibilityType, {
// -------------------------------------------------------------------------------------------------
-enum class WindingType : bool {
- EvenOdd,
- NonZero,
-};
-
-MBGL_DEFINE_ENUM_CLASS(WindingTypeClass, WindingType, {
- { WindingType::EvenOdd, "even-odd" },
- { WindingType::NonZero, "non-zero" },
-});
-
-// -------------------------------------------------------------------------------------------------
-
enum class CapType : uint8_t {
Round,
Butt,
diff --git a/src/mbgl/style/zoom_history.hpp b/src/mbgl/style/zoom_history.hpp
index 7031068624..eee0d9b443 100644
--- a/src/mbgl/style/zoom_history.hpp
+++ b/src/mbgl/style/zoom_history.hpp
@@ -1,8 +1,7 @@
#ifndef MBGL_STYLE_ZOOM_HISTORY
#define MBGL_STYLE_ZOOM_HISTORY
-#include <mbgl/util/time.hpp>
-
+#include <chrono>
#include <cmath>
namespace mbgl {
@@ -10,15 +9,15 @@ namespace mbgl {
struct ZoomHistory {
float lastZoom;
float lastIntegerZoom;
- timestamp lastIntegerZoomTime;
+ std::chrono::steady_clock::time_point lastIntegerZoomTime;
bool first = true;
- void update(float z, timestamp now) {
+ void update(float z, std::chrono::steady_clock::time_point now) {
if (first) {
first = false;
lastIntegerZoom = std::floor(z);
- lastIntegerZoomTime = 0;
+ lastIntegerZoomTime = std::chrono::steady_clock::time_point::min();
lastZoom = z;
}