diff options
author | Ansis Brammanis <brammanis@gmail.com> | 2016-02-05 16:26:08 -0800 |
---|---|---|
committer | Ansis Brammanis <brammanis@gmail.com> | 2016-02-09 15:01:34 -0800 |
commit | d9244cc973cacb454960838287c8c47482b20e34 (patch) | |
tree | 5d89cd846704ba1916b5f3202bd1d463eeb0f74c /src | |
parent | 61e63b718c9a315684d4b25def76c5a1c21cb1ca (diff) | |
download | qtlocation-mapboxgl-d9244cc973cacb454960838287c8c47482b20e34.tar.gz |
[core] make sure icons fit before the ends of the line
This skips anchors if there is not enough room before the beginning or
end of the line for the icon to fit.
-js: https://github.com/mapbox/mapbox-gl-js/pull/2077/files
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/text/get_anchors.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp index 1a2142bfb2..7a129d692c 100644 --- a/src/mbgl/text/get_anchors.cpp +++ b/src/mbgl/text/get_anchors.cpp @@ -10,14 +10,19 @@ namespace mbgl { Anchors resample(const std::vector<Coordinate> &line, const float offset, const float spacing, const float angleWindowSize, const float maxAngle, const float labelLength, const bool continuedLine, const bool placeAtMiddle) { + const float halfLabelLength = labelLength / 2.0f; + float lineLength = 0; + for (auto it = line.begin(), end = line.end() - 1; it != end; it++) { + lineLength += util::dist<float>(*(it), *(it + 1)); + } + float distance = 0; float markedDistance = offset - spacing; Anchors anchors; - auto end = line.end() - 1; int i = 0; - for (auto it = line.begin(); it != end; it++, i++) { + for (auto it = line.begin(), end = line.end() - 1; it != end; it++, i++) { const Coordinate &a = *(it); const Coordinate &b = *(it + 1); @@ -31,7 +36,12 @@ Anchors resample(const std::vector<Coordinate> &line, const float offset, const x = util::interpolate(float(a.x), float(b.x), t), y = util::interpolate(float(a.y), float(b.y), t); - if (x >= 0 && x < util::EXTENT && y >= 0 && y < util::EXTENT) { + // Check that the point is within the tile boundaries and that + // the label would fit before the beginning and end of the line + // if placed at this point. + if (x >= 0 && x < util::EXTENT && y >= 0 && y < util::EXTENT && + markedDistance - halfLabelLength >= 0.0f && + markedDistance + halfLabelLength <= lineLength) { Anchor anchor(::round(x), ::round(y), angle, 0.5f, i); if (!angleWindowSize || checkMaxAngle(line, anchor, labelLength, angleWindowSize, maxAngle)) { |