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

Commit

Permalink
[core] Favor previous anchor only when still in the `text-variable-an…
Browse files Browse the repository at this point in the history
…chor` options

Port of mapbox/mapbox-gl-js#8473
  • Loading branch information
pozdnyakov committed Jul 16, 2019
1 parent d2434d0 commit 6ba0f80
Showing 1 changed file with 14 additions and 10 deletions.
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

0 comments on commit 6ba0f80

Please sign in to comment.