add symbol* properties/keys

This commit is contained in:
Konstantin Käfer
2014-07-23 15:37:01 +02:00
parent 6e44e03241
commit 270c24a9a8
8 changed files with 146 additions and 13 deletions

View File

@@ -30,7 +30,14 @@ enum class PropertyKey {
IconOpacity,
IconRotate,
IconRotateAnchor,
IconSize,
IconColor,
IconHaloColor,
IconHaloWidth,
IconHaloBlur,
IconTranslateX,
IconTranslateY,
IconTranslateAnchor,
TextOpacity,
TextSize,
@@ -38,6 +45,9 @@ enum class PropertyKey {
TextHaloColor,
TextHaloWidth,
TextHaloBlur,
TextTranslateX,
TextTranslateY,
TextTranslateAnchor,
CompositeOpacity,

View File

@@ -4,8 +4,10 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/filter_expression.hpp>
#include <mbgl/style/style_source.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <memory>
#include <forward_list>
@@ -59,6 +61,47 @@ public:
bool always_visible = false;
};
class StyleBucketSymbol : util::noncopyable {
public:
PlacementType placement = PlacementType::Default;
float min_distance = 250.0f;
struct {
bool allow_overlap = false;
bool ignore_placement = false;
bool optional = false;
RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport;
float max_size = 1.0f;
std::string image;
float padding = 2.0f;
bool keep_upright = false;
vec2<float> offset = {0, 0};
} icon;
struct {
RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport;
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 */;
TextJustifyType justify = TextJustifyType::Center;
TextHorizontalAlignType horizontal_align = TextHorizontalAlignType::Center;
TextVerticalAlignType vertical_align = TextVerticalAlignType::Center;
float max_angle_delta = 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};
bool allow_overlap = false;
bool ignore_placement = false;
bool optional = false;
} text;
};
class StyleBucketRaster {
public:
};

View File

@@ -69,6 +69,39 @@ struct TextProperties {
}
};
struct SymbolProperties {
inline SymbolProperties() {}
struct {
float opacity = 1.0f;
float rotate = 0.0f;
float size = 1.0f;
Color color = {{ 0, 0, 0, 1 }};
Color halo_color = {{ 0, 0, 0, 0 }};
float halo_width = 0.0f;
float halo_blur = 0.0f;
std::array<float, 2> translate = {{ 0, 0 }};
TranslateAnchorType translate_anchor = TranslateAnchorType::Map;
} icon;
struct {
float opacity = 1.0f;
float size = 12.0f;
Color color = {{ 0, 0, 0, 1 }};
Color halo_color = {{ 0, 0, 0, 0 }};
float halo_width = 0.0f;
float halo_blur = 0.0f;
std::array<float, 2> translate = {{ 0, 0 }};
TranslateAnchorType translate_anchor = TranslateAnchorType::Map;
} text;
inline bool isVisible() const {
return (icon.opacity > 0 && (icon.color[3] > 0 || icon.halo_color[3] > 0) && icon.size > 0) ||
(text.opacity > 0 && (text.color[3] > 0 || text.halo_color[3] > 0) && text.size > 0);
}
};
struct CompositeProperties {
inline CompositeProperties() {}
float opacity = 1.0f;

View File

@@ -61,6 +61,12 @@ enum class TextPathType : uint8_t {
Default = Horizontal
};
enum class PlacementType : bool {
Point,
Line,
Default = Point
};
enum class TextTransformType : uint8_t {
None,
Uppercase,
@@ -80,6 +86,33 @@ enum class RotateAnchorType : uint8_t {
Default = Viewport
};
enum class RotationAlignmentType : bool {
Map,
Viewport,
Default = Viewport
};
enum class TextJustifyType : uint8_t {
Center,
Left,
Right,
Default = Center
};
enum class TextHorizontalAlignType : uint8_t {
Left,
Center,
Right,
Default = Center
};
enum class TextVerticalAlignType : uint8_t {
Top,
Center,
Bottom,
Default = Center
};
enum class SourceType : uint8_t {
Vector,
Raster,
@@ -114,6 +147,12 @@ inline TextPathType parseTextPathType(const std::string &path) {
return TextPathType::Default;
}
inline PlacementType parsePlacementType(const std::string &path) {
if (path == "point") return PlacementType::Point;
if (path == "line") return PlacementType::Line;
return PlacementType::Default;
}
inline TextTransformType parseTextTransformType(const std::string& transform) {
if (transform == "uppercase") return TextTransformType::Uppercase;
if (transform == "lowercase") return TextTransformType::Lowercase;

View File

@@ -23,16 +23,25 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::LineDashLand, defaultStyleProperties<LineProperties>().dash_array[0] },
{ PropertyKey::LineDashGap, defaultStyleProperties<LineProperties>().dash_array[1] },
{ PropertyKey::IconOpacity, defaultStyleProperties<IconProperties>().opacity },
{ PropertyKey::IconRotate, defaultStyleProperties<IconProperties>().rotate },
{ PropertyKey::IconRotateAnchor, defaultStyleProperties<IconProperties>().rotate_anchor },
{ PropertyKey::TextOpacity, defaultStyleProperties<TextProperties>().opacity },
{ PropertyKey::TextSize, defaultStyleProperties<TextProperties>().size },
{ PropertyKey::TextColor, defaultStyleProperties<TextProperties>().color },
{ PropertyKey::TextHaloColor, defaultStyleProperties<TextProperties>().halo_color },
{ PropertyKey::TextHaloWidth, defaultStyleProperties<TextProperties>().halo_width },
{ PropertyKey::TextHaloBlur, defaultStyleProperties<TextProperties>().halo_blur },
{ PropertyKey::IconOpacity, defaultStyleProperties<SymbolProperties>().icon.opacity },
{ PropertyKey::IconRotate, defaultStyleProperties<SymbolProperties>().icon.rotate },
{ PropertyKey::IconSize, defaultStyleProperties<SymbolProperties>().icon.size },
{ PropertyKey::IconColor, defaultStyleProperties<SymbolProperties>().icon.color },
{ PropertyKey::IconHaloColor, defaultStyleProperties<SymbolProperties>().icon.halo_color },
{ PropertyKey::IconHaloWidth, defaultStyleProperties<SymbolProperties>().icon.halo_width },
{ PropertyKey::IconHaloBlur, defaultStyleProperties<SymbolProperties>().icon.halo_blur },
{ PropertyKey::IconTranslateX, defaultStyleProperties<SymbolProperties>().icon.translate[0] },
{ PropertyKey::IconTranslateY, defaultStyleProperties<SymbolProperties>().icon.translate[1] },
{ PropertyKey::IconTranslateAnchor, defaultStyleProperties<SymbolProperties>().icon.translate_anchor },
{ PropertyKey::TextOpacity, defaultStyleProperties<SymbolProperties>().text.opacity },
{ PropertyKey::TextSize, defaultStyleProperties<SymbolProperties>().text.size },
{ PropertyKey::TextColor, defaultStyleProperties<SymbolProperties>().text.color },
{ PropertyKey::TextHaloColor, defaultStyleProperties<SymbolProperties>().text.halo_color },
{ PropertyKey::TextHaloWidth, defaultStyleProperties<SymbolProperties>().text.halo_width },
{ PropertyKey::TextHaloBlur, defaultStyleProperties<SymbolProperties>().text.halo_blur },
{ PropertyKey::TextTranslateX, defaultStyleProperties<SymbolProperties>().text.translate[0] },
{ PropertyKey::TextTranslateY, defaultStyleProperties<SymbolProperties>().text.translate[1] },
{ PropertyKey::TextTranslateAnchor, defaultStyleProperties<SymbolProperties>().text.translate_anchor },
{ PropertyKey::CompositeOpacity, defaultStyleProperties<CompositeProperties>().opacity },

View File

@@ -196,7 +196,6 @@ void StyleLayer::applyStyleProperties<IconProperties>(const float z, const times
IconProperties &icon = properties.get<IconProperties>();
applyStyleProperty(PropertyKey::IconOpacity, icon.opacity, z, now);
applyStyleProperty(PropertyKey::IconRotate, icon.rotate, z, now);
applyStyleProperty(PropertyKey::IconRotateAnchor, icon.rotate_anchor, z, now);
}
template <>

View File

@@ -592,7 +592,6 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) {
parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value);
parseOptionalProperty<PropertyTransition>("transition-icon-opacity", Key::IconOpacity, klass, value);
parseOptionalProperty<Function<float>>("icon-rotate", Key::IconRotate, klass, value);
parseOptionalProperty<RotateAnchorType>("icon-rotate-anchor", Key::IconRotateAnchor, klass, value);
parseOptionalProperty<Function<float>>("text-opacity", Key::TextOpacity, klass, value);
parseOptionalProperty<PropertyTransition>("transition-text-opacity", Key::TextOpacity, klass, value);

View File

@@ -6,6 +6,7 @@ template<> const FillProperties &defaultStyleProperties() { static const FillPro
template<> const LineProperties &defaultStyleProperties() { static const LineProperties p; return p; }
template<> const IconProperties &defaultStyleProperties() { static const IconProperties p; return p; }
template<> const TextProperties &defaultStyleProperties() { static const TextProperties p; return p; }
template<> const SymbolProperties &defaultStyleProperties() { static const SymbolProperties p; return p; }
template<> const CompositeProperties &defaultStyleProperties() { static const CompositeProperties p; return p; }
template<> const RasterProperties &defaultStyleProperties() { static const RasterProperties p; return p; }
template<> const BackgroundProperties &defaultStyleProperties() { static const BackgroundProperties p; return p; }