diff --git a/src/mbgl/geometry/resample.cpp b/src/mbgl/geometry/resample.cpp index abb3ef1e3..ed086fefd 100644 --- a/src/mbgl/geometry/resample.cpp +++ b/src/mbgl/geometry/resample.cpp @@ -17,17 +17,18 @@ const std::array, 4> minScaleArrays = {{ Anchors resample(const std::vector &vertices, float spacing, const float /*minScale*/, float maxScale, const float tilePixelRatio, - const int start) { + float offset) { maxScale = std::round(std::fmax(std::fmin(8.0f, maxScale / 2.0f), 1.0f)); spacing *= tilePixelRatio / maxScale; + offset *= tilePixelRatio; const size_t index = util::clamp(std::floor(std::log(maxScale) / std::log(2)), 0, minScaleArrays.size() - 1); const std::vector &minScales = minScaleArrays[index]; const size_t len = minScales.size(); float distance = 0.0f; - float markedDistance = 0.0f; - int added = start; + float markedDistance = offset != 0.0f ? offset - spacing : offset; + int added = 0; Anchors points; diff --git a/src/mbgl/geometry/resample.hpp b/src/mbgl/geometry/resample.hpp index bcfe4ca53..ce7eba2f1 100644 --- a/src/mbgl/geometry/resample.hpp +++ b/src/mbgl/geometry/resample.hpp @@ -7,7 +7,7 @@ namespace mbgl { Anchors resample(const std::vector &vertices, float spacing, - float minScale, float maxScale, float tilePixelRatio, int start = 0); + float minScale, float maxScale, float tilePixelRatio, float offset); } #endif diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index f53bbfa95..44cc3816a 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -238,9 +238,22 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping Anchors anchors; if (properties.placement == PlacementType::Line) { + float resampleOffset = 0; + + if (shaping.size()) { + float minX = std::numeric_limits::infinity(); + float maxX = -std::numeric_limits::infinity(); + for (const auto &glyph : shaping) { + minX = std::min(minX, glyph.x); + maxX = std::max(maxX, glyph.x); + } + const float labelLength = maxX - minX; + resampleOffset = (labelLength / 2.0 + glyphSize * 2.0) * fontScale; + } + // Line labels anchors = resample(line, properties.min_distance, minScale, collision.maxPlacementScale, - collision.tilePixelRatio); + collision.tilePixelRatio, resampleOffset); // Sort anchors by segment so that we can start placement with the // anchors that can be shown at the lowest zoom levels. diff --git a/test/suite b/test/suite index dba0f2b1f..7423bba25 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit dba0f2b1fa749691435d06a251d733173d41e3f5 +Subproject commit 7423bba25d7b62a31475a3ab2e99c68f37374442