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

Commit 5781075

Browse files
committed
[core] Variable labels stick to latest anchor if the view is tilted
This is done in order to improve labels stability and for the performace reasons.
1 parent f29865f commit 5781075

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/mbgl/text/placement.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui
311311
const auto prevAnchor = prevOffset->second.anchor;
312312
auto found = std::find(variableTextAnchors.begin(), variableTextAnchors.end(), prevAnchor);
313313
if (found != variableTextAnchors.begin() && found != variableTextAnchors.end()) {
314-
std::vector<style::TextVariableAnchorType> filtered;
315-
filtered.reserve(variableTextAnchors.size());
316-
filtered.push_back(prevAnchor);
317-
for (auto anchor : variableTextAnchors) {
318-
if (anchor != prevAnchor) {
319-
filtered.push_back(anchor);
314+
std::vector<style::TextVariableAnchorType> filtered{prevAnchor};
315+
if (!isTiltedView()) {
316+
for (auto anchor : variableTextAnchors) {
317+
if (anchor != prevAnchor) {
318+
filtered.push_back(anchor);
319+
}
320320
}
321321
}
322322
variableTextAnchors = std::move(filtered);
@@ -659,22 +659,24 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui
659659

660660
} else {
661661
auto sortedSymbols = bucket.getSymbols(params.sortKeyRange);
662-
if (auto* previousPlacement = getPrevPlacement()) {
663-
std::stable_sort(
664-
sortedSymbols.begin(), sortedSymbols.end(), [&](const SymbolInstance& a, const SymbolInstance& b) {
665-
auto* aPlacement = previousPlacement->getSymbolPlacement(a);
666-
auto* bPlacement = previousPlacement->getSymbolPlacement(b);
667-
if (!aPlacement) {
668-
// a < b, if 'a' is new and if 'b' was previously hidden.
669-
return bPlacement && !bPlacement->placed();
670-
}
671-
if (!bPlacement) {
672-
// a < b, if 'b' is new and 'a' was previously shown.
673-
return aPlacement && aPlacement->placed();
674-
}
675-
// a < b, if 'a' was shown and 'b' was hidden.
676-
return aPlacement->placed() && !bPlacement->placed();
677-
});
662+
auto* previousPlacement = getPrevPlacement();
663+
if (previousPlacement && isTiltedView()) {
664+
std::stable_sort(sortedSymbols.begin(),
665+
sortedSymbols.end(),
666+
[&previousPlacement](const SymbolInstance& a, const SymbolInstance& b) {
667+
auto* aPlacement = previousPlacement->getSymbolPlacement(a);
668+
auto* bPlacement = previousPlacement->getSymbolPlacement(b);
669+
if (!aPlacement) {
670+
// a < b, if 'a' is new and if 'b' was previously hidden.
671+
return bPlacement && !bPlacement->placed();
672+
}
673+
if (!bPlacement) {
674+
// a < b, if 'b' is new and 'a' was previously shown.
675+
return aPlacement && aPlacement->placed();
676+
}
677+
// a < b, if 'a' was shown and 'b' was hidden.
678+
return aPlacement->placed() && !bPlacement->placed();
679+
});
678680
}
679681
for (const SymbolInstance& symbol : sortedSymbols) {
680682
placeSymbol(symbol);
@@ -1201,6 +1203,10 @@ void Placement::markUsedOrientation(SymbolBucket& bucket,
12011203
}
12021204
}
12031205

1206+
bool Placement::isTiltedView() const {
1207+
return updateParameters->transformState.getPitch() != 0.0f;
1208+
}
1209+
12041210
float Placement::symbolFadeChange(TimePoint now) const {
12051211
if (transitionsEnabled() &&
12061212
transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) > Milliseconds(0)) {

src/mbgl/text/placement.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Placement {
137137
style::TextWritingModeType orientation) const;
138138
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&) const;
139139
const Placement* getPrevPlacement() const { return prevPlacement ? prevPlacement->get() : nullptr; }
140+
bool isTiltedView() const;
140141

141142
std::shared_ptr<const UpdateParameters> updateParameters;
142143
CollisionIndex collisionIndex;

0 commit comments

Comments
 (0)