This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathsymbol_layer_impl.cpp
87 lines (68 loc) · 3.35 KB
/
symbol_layer_impl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/style/bucket_parameters.hpp>
namespace mbgl {
namespace style {
void SymbolLayer::Impl::parseLayout(const JSValue& value) {
layout.parse(value);
}
void SymbolLayer::Impl::parsePaints(const JSValue& layer) {
paint.parse(layer);
}
void SymbolLayer::Impl::cascade(const CascadeParameters& parameters) {
paint.cascade(parameters);
}
bool SymbolLayer::Impl::recalculate(const CalculationParameters& parameters) {
bool hasTransitions = paint.recalculate(parameters);
// text-size and icon-size are layout properties but they also need to be evaluated as paint properties:
layout.iconSize.calculate(parameters);
layout.textSize.calculate(parameters);
iconSize = layout.iconSize;
textSize = layout.textSize;
passes = ((paint.iconOpacity > 0 && (paint.iconColor.value[3] > 0 || paint.iconHaloColor.value[3] > 0) && iconSize > 0)
|| (paint.textOpacity > 0 && (paint.textColor.value[3] > 0 || paint.textHaloColor.value[3] > 0) && textSize > 0))
? RenderPass::Translucent : RenderPass::None;
return hasTransitions;
}
std::unique_ptr<Bucket> SymbolLayer::Impl::createBucket(BucketParameters& parameters) const {
auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaleFactor(),
parameters.tileID.overscaledZ,
parameters.mode,
id,
parameters.layer.getName());
bucket->layout = layout;
CalculationParameters p(parameters.tileID.overscaledZ);
bucket->layout.symbolPlacement.calculate(p);
if (bucket->layout.symbolPlacement.value == SymbolPlacementType::Line) {
bucket->layout.iconRotationAlignment.value = AlignmentType::Map;
bucket->layout.textRotationAlignment.value = AlignmentType::Map;
};
// If unspecified `text-pitch-alignment` inherits `text-rotation-alignment`
if (bucket->layout.textPitchAlignment.value == AlignmentType::Undefined) {
bucket->layout.textPitchAlignment.value = bucket->layout.textRotationAlignment.value;
};
bucket->layout.recalculate(p);
bucket->layout.iconSize.calculate(CalculationParameters(18));
bucket->layout.textSize.calculate(CalculationParameters(18));
bucket->iconMaxSize = bucket->layout.iconSize;
bucket->textMaxSize = bucket->layout.textSize;
bucket->layout.iconSize.calculate(CalculationParameters(p.z + 1));
bucket->layout.textSize.calculate(CalculationParameters(p.z + 1));
bucket->parseFeatures(parameters.layer, filter);
if (bucket->needsDependencies(parameters.glyphStore, parameters.spriteStore)) {
parameters.partialParse = true;
}
// We do not add features if the parser is in a "partial" state because
// the layer ordering needs to be respected when calculating text
// collisions. Although, at this point, we requested all the resources
// needed by this tile.
if (!parameters.partialParse) {
bucket->addFeatures(parameters.tileUID,
*spriteAtlas,
parameters.glyphAtlas,
parameters.glyphStore);
}
return std::move(bucket);
}
} // namespace style
} // namespace mbgl