summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-01-07 22:31:25 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-01-08 12:43:26 +0200
commitcf2946c8ffe90662d61f3494d0f9942fcec07aae (patch)
tree3542afd8785db2dac6a489d3c514b5daf6a8c8f9
parent1debf4e05b9710c006856fc14254493b16478bbc (diff)
downloadqtlocation-mapboxgl-cf2946c8ffe90662d61f3494d0f9942fcec07aae.tar.gz
[core] Use only the first variable anchor for the symbols intersecting tile borders
Do not try the following variable anchors, if the first variable anchor placement failed.
-rw-r--r--src/mbgl/text/placement.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 62ac70a0d6..6cf9c93200 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -182,7 +182,6 @@ void Placement::placeBucket(const SymbolBucket& bucket,
layout.get<style::SymbolPlacement>() == style::SymbolPlacementType::Line)) {
avoidEdges = tileBorders;
}
- const bool stickToFirstAnchor = tileBorders && !avoidEdges;
const bool textAllowOverlap = layout.get<style::TextAllowOverlap>();
const bool iconAllowOverlap = layout.get<style::IconAllowOverlap>();
@@ -332,6 +331,8 @@ void Placement::placeBucket(const SymbolBucket& bucket,
const bool doVariableIconPlacement =
hasIconTextFit && !iconAllowOverlap && symbolInstance.placedIconIndex;
+ bool stickToFirstAnchor = false;
+
const auto placeFeatureForVariableAnchors = [&](const CollisionFeature& textCollisionFeature,
style::TextWritingModeType orientation,
const CollisionFeature& iconCollisionFeature) {
@@ -344,8 +345,8 @@ void Placement::placeBucket(const SymbolBucket& bucket,
const size_t placementAttempts = textAllowOverlap ? anchorsSize * 2 : anchorsSize;
for (size_t i = 0u; i < placementAttempts; ++i) {
auto anchor = variableTextAnchors[i % anchorsSize];
- const auto& avoidEdgesForVariableAnchor =
- (stickToFirstAnchor && anchor != variableTextAnchors.front()) ? tileBorders : avoidEdges;
+ const bool isFirstAnchor = (anchor == variableTextAnchors.front());
+ if (stickToFirstAnchor && !isFirstAnchor) continue;
const bool allowOverlap = (i >= anchorsSize);
shift = calculateVariableLayoutOffset(anchor,
@@ -357,6 +358,13 @@ void Placement::placeBucket(const SymbolBucket& bucket,
pitchWithMap,
state.getBearing());
textBoxes.clear();
+
+ if (mapMode == MapMode::Tile && isFirstAnchor) {
+ assert(tileBorders);
+ stickToFirstAnchor = collisionIndex.featureIntersectsTileBorders(
+ textCollisionFeature, shift, posMatrix, pixelRatio, *tileBorders);
+ }
+
placedFeature = collisionIndex.placeFeature(textCollisionFeature,
shift,
posMatrix,
@@ -368,7 +376,7 @@ void Placement::placeBucket(const SymbolBucket& bucket,
allowOverlap,
pitchWithMap,
params.showCollisionBoxes,
- avoidEdgesForVariableAnchor,
+ avoidEdges,
collisionGroup.second,
textBoxes);
@@ -384,7 +392,7 @@ void Placement::placeBucket(const SymbolBucket& bucket,
iconAllowOverlap,
pitchWithMap,
params.showCollisionBoxes,
- avoidEdgesForVariableAnchor,
+ avoidEdges,
collisionGroup.second,
iconBoxes);
iconBoxes.clear();
@@ -553,10 +561,9 @@ void Placement::placeBucket(const SymbolBucket& bucket,
for (auto it = sortedSymbols.rbegin(); it != sortedSymbols.rend(); ++it) {
placeSymbol(*it);
}
- } else if (stickToFirstAnchor) {
+ } else if (mapMode == MapMode::Tile && !avoidEdges) {
// In this case we first try to place symbols, which intersects the tile borders, so that
// those symbols will remain even if each tile is handled independently.
- assert(mapMode == MapMode::Tile);
const auto& symbolInstances = bucket.symbolInstances;
std::vector<std::reference_wrapper<const SymbolInstance>> sorted(symbolInstances.begin(),
symbolInstances.end());