improve line label density
Place the first label as close to the beginning of the line as possible. js: 316ed0bd9bff8cd430ad81d0b6397f396fbce124
This commit is contained in:
@@ -17,17 +17,18 @@ const std::array<std::vector<float>, 4> minScaleArrays = {{
|
||||
|
||||
Anchors resample(const std::vector<Coordinate> &vertices, float spacing,
|
||||
const float /*minScale*/, float maxScale, const float tilePixelRatio,
|
||||
const int start) {
|
||||
int offset) {
|
||||
|
||||
maxScale = std::round(std::fmax(std::fmin(8.0f, maxScale / 2.0f), 1.0f));
|
||||
spacing *= tilePixelRatio / maxScale;
|
||||
offset *= tilePixelRatio / maxScale;
|
||||
const size_t index = util::clamp<size_t>(std::floor(std::log(maxScale) / std::log(2)), 0, minScaleArrays.size() - 1);
|
||||
const std::vector<float> &minScales = minScaleArrays[index];
|
||||
const size_t len = minScales.size();
|
||||
|
||||
float distance = 0.0f;
|
||||
float distance = spacing - offset;;
|
||||
float markedDistance = 0.0f;
|
||||
int added = start;
|
||||
int added = 0;
|
||||
|
||||
Anchors points;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
Anchors resample(const std::vector<Coordinate> &vertices, float spacing,
|
||||
float minScale, float maxScale, float tilePixelRatio, int start = 0);
|
||||
float minScale, float maxScale, float tilePixelRatio, int offset);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -238,9 +238,26 @@ void SymbolBucket::addFeature(const std::vector<Coordinate> &line, const Shaping
|
||||
Anchors anchors;
|
||||
|
||||
if (properties.placement == PlacementType::Line) {
|
||||
float textResampleOffset = 0;
|
||||
float iconResampleOffset = 0;
|
||||
|
||||
if (shaping.size()) {
|
||||
float minX = std::numeric_limits<float>::infinity();
|
||||
float maxX = -std::numeric_limits<float>::infinity();
|
||||
for (const auto &glyph : shaping) {
|
||||
minX = std::min(minX, glyph.x);
|
||||
maxX = std::max(maxX, glyph.x);
|
||||
}
|
||||
const float labelLength = maxX - minX;
|
||||
textResampleOffset = (labelLength / 2.0 + glyphSize) * fontScale;
|
||||
}
|
||||
if (image) {
|
||||
iconResampleOffset = image.w;
|
||||
}
|
||||
|
||||
// Line labels
|
||||
anchors = resample(line, properties.min_distance, minScale, collision.maxPlacementScale,
|
||||
collision.tilePixelRatio);
|
||||
collision.tilePixelRatio, std::max(iconResampleOffset, textResampleOffset));
|
||||
|
||||
// Sort anchors by segment so that we can start placement with the
|
||||
// anchors that can be shown at the lowest zoom levels.
|
||||
|
||||
Reference in New Issue
Block a user