Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement repeat group logic for point based styles #1228

Merged
merged 2 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/data/rasterSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RasterSource : public TileSource {
TextureOptions _options, bool genMipmap = false);


void loadTileData(std::shared_ptr<TileTask> _task, TileTaskCb _cb);
void loadTileData(std::shared_ptr<TileTask> _task, TileTaskCb _cb) override;

virtual std::shared_ptr<TileTask> createTask(TileID _tile, int _subTask) override;

Expand Down
8 changes: 6 additions & 2 deletions core/src/scene/styleParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const std::map<std::string, StyleParamKey> s_StyleParamMap = {
{"placement_spacing", StyleParamKey::placement_spacing},
{"placement_min_length_ratio", StyleParamKey::placement_min_length_ratio},
{"priority", StyleParamKey::priority},
{"repeat_distance", StyleParamKey::text_repeat_distance},
{"repeat_group", StyleParamKey::text_repeat_group},
{"repeat_distance", StyleParamKey::repeat_distance},
{"repeat_group", StyleParamKey::repeat_group},
{"size", StyleParamKey::size},
{"sprite", StyleParamKey::sprite},
{"sprite_default", StyleParamKey::sprite_default},
Expand Down Expand Up @@ -234,6 +234,7 @@ StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string&
case StyleParamKey::sprite_default:
case StyleParamKey::style:
case StyleParamKey::outline_style:
case StyleParamKey::repeat_group:
case StyleParamKey::text_repeat_group:
return _value;
case StyleParamKey::text_font_size: {
Expand Down Expand Up @@ -290,6 +291,7 @@ StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string&

return Width(placementSpacing);
}
case StyleParamKey::repeat_distance:
case StyleParamKey::text_repeat_distance: {
ValueUnitPair repeatDistance;
repeatDistance.unit = Unit::pixel;
Expand Down Expand Up @@ -385,6 +387,7 @@ std::string StyleParam::toString() const {
auto p = value.get<glm::vec2>();
return k + "(" + std::to_string(p.x) + "px, " + std::to_string(p.y) + "px)";
}
case StyleParamKey::repeat_group:
case StyleParamKey::transition_hide_time:
case StyleParamKey::text_transition_hide_time:
case StyleParamKey::transition_show_time:
Expand Down Expand Up @@ -433,6 +436,7 @@ std::string StyleParam::toString() const {
case StyleParamKey::color:
case StyleParamKey::outline_color:
case StyleParamKey::outline_style:
case StyleParamKey::repeat_distance:
case StyleParamKey::text_font_fill:
case StyleParamKey::text_font_stroke_color:
case StyleParamKey::text_repeat_distance:
Expand Down
2 changes: 2 additions & 0 deletions core/src/scene/styleParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum class StyleParamKey : uint8_t {
placement_spacing,
placement_min_length_ratio,
priority,
repeat_distance,
repeat_group,
text_order,
text_priority,
text_repeat_distance,
Expand Down
19 changes: 19 additions & 0 deletions core/src/style/pointStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ auto PointStyleBuilder::applyRule(const DrawRule& _rule, const Properties& _prop
_rule.get(StyleParamKey::offset, p.labelOptions.offset);

uint32_t priority;
size_t repeatGroupHash = 0;
std::string repeatGroup;
StyleParam::Width repeatDistance;

if (_rule.get(StyleParamKey::priority, priority)) {
p.labelOptions.priority = (float)priority;
}
Expand Down Expand Up @@ -149,6 +153,21 @@ auto PointStyleBuilder::applyRule(const DrawRule& _rule, const Properties& _prop
_rule.get(StyleParamKey::flat, p.labelOptions.flat);
_rule.get(StyleParamKey::anchor, p.labelOptions.anchors);

if (_rule.get(StyleParamKey::repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}

p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
}

if (p.labelOptions.anchors.count == 0) {
p.labelOptions.anchors.anchor = { {LabelProperty::Anchor::center} };
p.labelOptions.anchors.count = 1;
Expand Down
56 changes: 40 additions & 16 deletions core/src/style/textStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
_rule.get(StyleParamKey::transition_show_time, p.labelOptions.showTransition.time);

uint32_t priority;
size_t repeatGroupHash = 0;
std::string repeatGroup;
StyleParam::Width repeatDistance;

if (_iconText) {

if (_rule.get(StyleParamKey::text_priority, priority)) {
Expand All @@ -330,6 +334,24 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
p.labelOptions.anchors.count = 4;
}

// child text's repeat group params
if (_rule.get(StyleParamKey::text_repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::text_repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) { //inherit from parent point
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add

p.labelOptions.repeatDistance *= m_style.pixelScale();

around here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no this is done later on.

}


_rule.get(StyleParamKey::text_transition_hide_time, p.labelOptions.hideTransition.time);
_rule.get(StyleParamKey::text_transition_selected_time, p.labelOptions.selectTransition.time);
_rule.get(StyleParamKey::text_transition_show_time, p.labelOptions.showTransition.time);
Expand All @@ -348,28 +370,30 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
p.labelOptions.anchors.anchor = { {LabelProperty::Anchor::center} };
p.labelOptions.anchors.count = 1;
}
}

_rule.get(StyleParamKey::text_wrap, p.maxLineWidth);
if (_rule.get(StyleParamKey::repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}
}

size_t repeatGroupHash = 0;
std::string repeatGroup;
if (_rule.get(StyleParamKey::text_repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}

StyleParam::Width repeatDistance;
if (_rule.get(StyleParamKey::text_repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
if (p.labelOptions.repeatDistance > 0.f) {
hash_combine(repeatGroupHash, p.text);
p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
}

hash_combine(repeatGroupHash, p.text);
p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
_rule.get(StyleParamKey::text_wrap, p.maxLineWidth);

if (auto* transform = _rule.get<std::string>(StyleParamKey::text_transform)) {
TextLabelProperty::transform(*transform, p.transform);
Expand Down