summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-06 16:56:57 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-08 11:19:37 +0300
commit88337c23f7abd71a8a12401b2e24312f32846634 (patch)
tree0d08ff0eb3431afefd8729d19856cfa74ee2bc8e /src/mbgl/text
parent8165b7dee1119c09daeda4a82b7c0eb51ad06915 (diff)
downloadqtlocation-mapboxgl-88337c23f7abd71a8a12401b2e24312f32846634.tar.gz
[core][tile mode] Improve placement algorithm for variable labels
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/placement.cpp31
-rw-r--r--src/mbgl/text/placement.hpp12
2 files changed, 26 insertions, 17 deletions
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index e825fc3305..fa7436cfcc 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -390,7 +390,6 @@ void Placement::placeSymbol(const SymbolInstance& symbolInstance,
const size_t placementAttempts = ctx.textAllowOverlap ? anchorsSize * 2 : anchorsSize;
for (size_t i = 0u; i < placementAttempts; ++i) {
auto anchor = variableTextAnchors[i % anchorsSize];
- const bool isFirstAnchor = (anchor == variableTextAnchors.front());
const bool allowOverlap = (i >= anchorsSize);
shift = calculateVariableLayoutOffset(anchor,
width,
@@ -401,9 +400,8 @@ void Placement::placeSymbol(const SymbolInstance& symbolInstance,
ctx.pitchTextWithMap,
ctx.getTransformState().getBearing());
textBoxes.clear();
- if (!isFirstAnchor &&
- stickToFirstVariableAnchor(
- symbolInstance.textCollisionFeature.boxes.front(), shift, posMatrix, ctx.pixelRatio)) {
+ if (!canPlaceAtVariableAnchor(
+ textBox, anchor, shift, variableTextAnchors, posMatrix, ctx.pixelRatio)) {
continue;
}
@@ -1263,10 +1261,12 @@ private:
const std::vector<PlacedSymbolData>& getPlacedSymbolsData() const override { return placedSymbolsData; }
optional<CollisionBoundaries> getAvoidEdges(const SymbolBucket&, const mat4&) override;
- bool stickToFirstVariableAnchor(const CollisionBox& box,
- Point<float> shift,
- const mat4& posMatrix,
- float textPixelRatio) override;
+ bool canPlaceAtVariableAnchor(const CollisionBox& box,
+ TextVariableAnchorType anchor,
+ Point<float> shift,
+ std::vector<style::TextVariableAnchorType>& anchors,
+ const mat4& posMatrix,
+ float textPixelRatio) override;
void newSymbolPlaced(const SymbolInstance&,
const JointPlacement&,
style::SymbolPlacementType,
@@ -1438,12 +1438,19 @@ void TilePlacement::placeSymbolBucket(const BucketPlacementData& params, std::se
}
}
-bool TilePlacement::stickToFirstVariableAnchor(const CollisionBox& box,
- Point<float> shift,
- const mat4& posMatrix,
- float textPixelRatio) {
+bool TilePlacement::canPlaceAtVariableAnchor(const CollisionBox& box,
+ TextVariableAnchorType anchor,
+ Point<float> shift,
+ std::vector<style::TextVariableAnchorType>& anchors,
+ const mat4& posMatrix,
+ float textPixelRatio) {
assert(tileBorders);
auto status = collisionIndex.intersectsTileEdges(box, shift, posMatrix, textPixelRatio, *tileBorders);
+ if (status.flags == IntersectStatus::None) return true;
+
+ if (anchor != anchors.front()) return false;
+
+ status = collisionIndex.intersectsTileEdges(box, {}, posMatrix, textPixelRatio, *tileBorders);
return status.flags != IntersectStatus::None;
}
diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp
index 12a147e984..e62d2bdf3d 100644
--- a/src/mbgl/text/placement.hpp
+++ b/src/mbgl/text/placement.hpp
@@ -157,11 +157,13 @@ protected:
return nullopt;
}
SymbolInstanceReferences getSortedSymbols(const BucketPlacementData&, float pixelRatio);
- virtual bool stickToFirstVariableAnchor(const CollisionBox&,
- Point<float> /*shift*/,
- const mat4& /*posMatrix*/,
- float /*textPixelRatio*/) {
- return false;
+ virtual bool canPlaceAtVariableAnchor(const CollisionBox&,
+ style::TextVariableAnchorType,
+ Point<float> /*shift*/,
+ std::vector<style::TextVariableAnchorType>&,
+ const mat4& /*posMatrix*/,
+ float /*textPixelRatio*/) {
+ return true;
}
// Returns `true` if bucket vertices were updated; returns `false` otherwise.