[core] Favor previous anchor only when still in the text-variable-anchor options

Port of https://github.com/mapbox/mapbox-gl-js/pull/8473
This commit is contained in:
Mikhail Pozdnyakov
2019-07-16 17:24:09 +03:00
parent 5f6f20e667
commit 8574b8b726

View File

@@ -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);
}
}