Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Favor previous anchor only when still in the text-variable-anchor options #15129

Merged
merged 2 commits into from
Jul 17, 2019
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 mapbox-gl-js
Submodule mapbox-gl-js updated 222 files
20 changes: 11 additions & 9 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ MGL_EXPORT
The default value of this property is an expression that evaluates to `center`.
Set this property to `nil` to reset it to the default value.

This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
This property is only applied to the style if `text` is non-`nil`, and
`textVariableAnchor` is set to `nil`. Otherwise, it is ignored.

You can set this property to an expression containing any of the following:

Expand Down Expand Up @@ -1380,7 +1380,8 @@ MGL_EXPORT
ems downward. Set this property to `nil` to reset it to the default value.

This property is only applied to the style if `text` is non-`nil`, and
`textRadialOffset` is set to `nil`. Otherwise, it is ignored.
`textRadialOffset` is set to `nil`, and `textVariableAnchor` is set to `nil`.
Otherwise, it is ignored.

You can set this property to an expression containing any of the following:

Expand All @@ -1403,7 +1404,8 @@ MGL_EXPORT
ems upward. Set this property to `nil` to reset it to the default value.

This property is only applied to the style if `text` is non-`nil`, and
`textRadialOffset` is set to `nil`. Otherwise, it is ignored.
`textRadialOffset` is set to `nil`, and `textVariableAnchor` is set to `nil`.
Otherwise, it is ignored.

You can set this property to an expression containing any of the following:

Expand Down Expand Up @@ -1503,8 +1505,8 @@ MGL_EXPORT
The default value of this property is an expression that evaluates to the float
`0`. Set this property to `nil` to reset it to the default value.

This property is only applied to the style if `textOffset` is set to `nil`.
Otherwise, it is ignored.
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.

You can set this property to an expression containing any of the following:

Expand Down Expand Up @@ -1611,9 +1613,9 @@ MGL_EXPORT
an offset, use the `textRadialOffset` instead of the two-dimensional
`textOffset`.

This property is only applied to the style if `textAnchor` is set to `nil`, and
`textOffset` is set to `nil`, and `symbolPlacement` is set to an expression
that evaluates to or `MGLSymbolPlacementPoint`. Otherwise, it is ignored.
This property is only applied to the style if `text` is non-`nil`, and
`symbolPlacement` is set to an expression that evaluates to or
`MGLSymbolPlacementPoint`. Otherwise, it is ignored.

You can set this property to an expression containing any of the following:

Expand Down
24 changes: 14 additions & 10 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,24 @@ void Placement::placeBucket(
const float textBoxScale = symbolInstance.textBoxScale;

// If this symbol was in the last placement, shift the previously used
// anchor to the front of the anchor list.
// anchor to the front of the anchor list, only if the previous anchor
// is still in the anchor list.
if (prevPlacement) {
auto prevOffset = prevPlacement->variableOffsets.find(symbolInstance.crossTileID);
if (prevOffset != prevPlacement->variableOffsets.end() &&
variableTextAnchors.front() != prevOffset->second.anchor) {
std::vector<style::TextVariableAnchorType> filtered;
filtered.reserve(variableTextAnchors.size());
filtered.push_back(prevOffset->second.anchor);
for (auto anchor : variableTextAnchors) {
if (anchor != prevOffset->second.anchor) {
filtered.push_back(anchor);
if (prevOffset != prevPlacement->variableOffsets.end()) {
const auto prevAnchor = prevOffset->second.anchor;
auto found = std::find(variableTextAnchors.begin(), variableTextAnchors.end(), prevAnchor);
if (found != variableTextAnchors.begin() && found != variableTextAnchors.end()) {
std::vector<style::TextVariableAnchorType> filtered;
filtered.reserve(variableTextAnchors.size());
filtered.push_back(prevAnchor);
for (auto anchor : variableTextAnchors) {
if (anchor != prevAnchor) {
filtered.push_back(anchor);
}
}
variableTextAnchors = std::move(filtered);
}
variableTextAnchors = std::move(filtered);
}
}

Expand Down