summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-16 17:24:09 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-17 14:52:47 +0300
commit8574b8b72696352852defbcae99c6ab46ecb2e3d (patch)
treed0bf15a9929eedd6759f8b0e2f04f46dc6d5a532
parent5f6f20e667d36fd2f2475756c55d17bade8ee3e2 (diff)
downloadqtlocation-mapboxgl-8574b8b72696352852defbcae99c6ab46ecb2e3d.tar.gz
[core] Favor previous anchor only when still in the `text-variable-anchor` options
Port of https://github.com/mapbox/mapbox-gl-js/pull/8473
-rw-r--r--src/mbgl/text/placement.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 62110fefa7..130c2d050c 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -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);
}
}