diff --git a/mapbox-gl-js b/mapbox-gl-js index f8678421764..b864b069e80 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit f8678421764c39d87fa7d372ee8fdb412e5def37 +Subproject commit b864b069e80fc8af7edc0aa6ab73aaab8b753953 diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index c0fef6c5fb5..08c2e56892a 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -3,6 +3,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. ## master +- Enable variable label placement when `text-allow-overlap` property is set to true [#15354](https://github.com/mapbox/mapbox-gl-native/pull/15354). - Introduce `text-writing-mode` layout property for symbol layer [#14932](https://github.com/mapbox/mapbox-gl-native/pull/14932). The `text-writing-mode` layout property allows control over symbol's preferred writing mode. The new property value is an array, whose values are enumeration values from a ( `horizontal` | `vertical` ) set. ### Features diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 05f13ff0eba..a2b8ab3c9d8 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Styles and rendering +* Enable variable label placement when `text-allow-overlap` property is set to true. ([#15354](https://github.com/mapbox/mapbox-gl-native/pull/15354)) * Introduce `text-writing-mode` layout property for symbol layer ([#14932](https://github.com/mapbox/mapbox-gl-native/pull/14932)). The `text-writing-mode` layout property allows control over symbol's preferred writing mode. The new property value is an array, whose values are enumeration values from a ( `horizontal` | `vertical` ) set. ## 5.3.0 diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index de282acf79c..23d460889db 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -274,7 +274,11 @@ void Placement::placeBucket( const float height = textBox.y2 - textBox.y1; const float textBoxScale = symbolInstance.textBoxScale; std::pair placedFeature = {false, false}; - for (auto anchor : variableTextAnchors) { + const size_t anchorsSize = variableTextAnchors.size(); + const size_t placementAttempts = textAllowOverlap ? anchorsSize * 2 : anchorsSize; + for (size_t i = 0u; i < placementAttempts; ++i) { + auto anchor = variableTextAnchors[i % anchorsSize]; + const bool allowOverlap = (i >= anchorsSize); Point shift = calculateVariableLayoutOffset(anchor, width, height, symbolInstance.radialTextOffset, textBoxScale); if (rotateWithMap) { float angle = pitchWithMap ? state.getBearing() : -state.getBearing(); @@ -285,7 +289,7 @@ void Placement::placeBucket( placedFeature = collisionIndex.placeFeature(collisionFeature, shift, posMatrix, mat4(), pixelRatio, placedSymbol, scale, fontSize, - layout.get(), + allowOverlap, pitchWithMap, params.showCollisionBoxes, avoidEdges, collisionGroup.second, textBoxes); if (placedFeature.first) { @@ -584,15 +588,13 @@ bool Placement::updateBucketDynamicVertices(SymbolBucket& bucket, const Transfor if (pitchWithMap) { shiftedAnchor = project(Point(tileAnchor.x + shift.x, tileAnchor.y + shift.y), labelPlaneMatrix).first; + } else if (rotateWithMap) { + auto rotated = util::rotate(shift, -state.getPitch()); + shiftedAnchor = Point(projectedAnchor.first.x + rotated.x, + projectedAnchor.first.y + rotated.y); } else { - if (rotateWithMap) { - auto rotated = util::rotate(shift, -state.getPitch()); - shiftedAnchor = Point(projectedAnchor.first.x + rotated.x, - projectedAnchor.first.y + rotated.y); - } else { - shiftedAnchor = Point(projectedAnchor.first.x + shift.x, - projectedAnchor.first.y + shift.y); - } + shiftedAnchor = Point(projectedAnchor.first.x + shift.x, + projectedAnchor.first.y + shift.y); } for (std::size_t i = 0; i < symbol.glyphOffsets.size(); ++i) { @@ -806,7 +808,7 @@ const style::TextJustifyType justifyTypes[] = {style::TextJustifyType::Right, st } // namespace -void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableAnchorType placedAnchor, SymbolInstance& symbolInstance, style::TextWritingModeType orientation) { +void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableAnchorType placedAnchor, const SymbolInstance& symbolInstance, style::TextWritingModeType orientation) { style::TextJustifyType anchorJustify = getAnchorJustification(placedAnchor); assert(anchorJustify != style::TextJustifyType::Auto); const optional& autoIndex = justificationToIndex(anchorJustify, symbolInstance, orientation); @@ -826,7 +828,7 @@ void Placement::markUsedJustification(SymbolBucket& bucket, style::TextVariableA } } -void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingModeType orientation, SymbolInstance& symbolInstance) { +void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingModeType orientation, const SymbolInstance& symbolInstance) { auto horizontal = orientation == style::TextWritingModeType::Horizontal ? optional(orientation) : nullopt; auto vertical = orientation == style::TextWritingModeType::Vertical ? diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp index 33bfbd6527c..722a4a0926a 100644 --- a/src/mbgl/text/placement.hpp +++ b/src/mbgl/text/placement.hpp @@ -123,8 +123,8 @@ class Placement { // Returns `true` if bucket vertices were updated; returns `false` otherwise. bool updateBucketDynamicVertices(SymbolBucket&, const TransformState&, const RenderTile& tile) const; void updateBucketOpacities(SymbolBucket&, const TransformState&, std::set&); - void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, SymbolInstance&, style::TextWritingModeType orientation); - void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, SymbolInstance&); + void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, const SymbolInstance&, style::TextWritingModeType orientation); + void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&); CollisionIndex collisionIndex;