summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-03-09 16:41:58 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-03-12 23:35:55 +0200
commit57810759ef7f82b8af6b3d47ded47b7ecd3cd846 (patch)
tree44810da084f0c97901e5297e916e960e048a9ad9
parentf29865f31ddd9e6293053e810a65c6c093b7d597 (diff)
downloadqtlocation-mapboxgl-57810759ef7f82b8af6b3d47ded47b7ecd3cd846.tar.gz
[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.
-rw-r--r--src/mbgl/text/placement.cpp50
-rw-r--r--src/mbgl/text/placement.hpp1
2 files changed, 29 insertions, 22 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index d8cf4653c6..4eaf08f34a 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -311,12 +311,12 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui
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);
+ std::vector<style::TextVariableAnchorType> filtered{prevAnchor};
+ if (!isTiltedView()) {
+ for (auto anchor : variableTextAnchors) {
+ if (anchor != prevAnchor) {
+ filtered.push_back(anchor);
+ }
}
}
variableTextAnchors = std::move(filtered);
@@ -659,22 +659,24 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set<ui
} else {
auto sortedSymbols = bucket.getSymbols(params.sortKeyRange);
- if (auto* previousPlacement = getPrevPlacement()) {
- std::stable_sort(
- sortedSymbols.begin(), sortedSymbols.end(), [&](const SymbolInstance& a, const SymbolInstance& b) {
- auto* aPlacement = previousPlacement->getSymbolPlacement(a);
- auto* bPlacement = previousPlacement->getSymbolPlacement(b);
- if (!aPlacement) {
- // a < b, if 'a' is new and if 'b' was previously hidden.
- return bPlacement && !bPlacement->placed();
- }
- if (!bPlacement) {
- // a < b, if 'b' is new and 'a' was previously shown.
- return aPlacement && aPlacement->placed();
- }
- // a < b, if 'a' was shown and 'b' was hidden.
- return aPlacement->placed() && !bPlacement->placed();
- });
+ auto* previousPlacement = getPrevPlacement();
+ if (previousPlacement && isTiltedView()) {
+ std::stable_sort(sortedSymbols.begin(),
+ sortedSymbols.end(),
+ [&previousPlacement](const SymbolInstance& a, const SymbolInstance& b) {
+ auto* aPlacement = previousPlacement->getSymbolPlacement(a);
+ auto* bPlacement = previousPlacement->getSymbolPlacement(b);
+ if (!aPlacement) {
+ // a < b, if 'a' is new and if 'b' was previously hidden.
+ return bPlacement && !bPlacement->placed();
+ }
+ if (!bPlacement) {
+ // a < b, if 'b' is new and 'a' was previously shown.
+ return aPlacement && aPlacement->placed();
+ }
+ // a < b, if 'a' was shown and 'b' was hidden.
+ return aPlacement->placed() && !bPlacement->placed();
+ });
}
for (const SymbolInstance& symbol : sortedSymbols) {
placeSymbol(symbol);
@@ -1201,6 +1203,10 @@ void Placement::markUsedOrientation(SymbolBucket& bucket,
}
}
+bool Placement::isTiltedView() const {
+ return updateParameters->transformState.getPitch() != 0.0f;
+}
+
float Placement::symbolFadeChange(TimePoint now) const {
if (transitionsEnabled() &&
transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) > Milliseconds(0)) {
diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp
index 2ceb531d44..d3f92eb068 100644
--- a/src/mbgl/text/placement.hpp
+++ b/src/mbgl/text/placement.hpp
@@ -137,6 +137,7 @@ private:
style::TextWritingModeType orientation) const;
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&) const;
const Placement* getPrevPlacement() const { return prevPlacement ? prevPlacement->get() : nullptr; }
+ bool isTiltedView() const;
std::shared_ptr<const UpdateParameters> updateParameters;
CollisionIndex collisionIndex;