12
12
#include " tile/tileCache.h"
13
13
#include " labels/labelSet.h"
14
14
#include " labels/textLabel.h"
15
+ #include " marker/marker.h"
15
16
16
17
#include " glm/glm.hpp"
17
18
#include " glm/gtc/matrix_transform.hpp"
@@ -30,9 +31,41 @@ Labels::~Labels() {}
30
31
// return (int) MIN(floor(((log(-_zoom + (_maxZoom + 2)) / log(_maxZoom + 2) * (_maxZoom )) * 0.5)), MAX_LOD);
31
32
// }
32
33
34
+ void Labels::processLabelUpdate (StyledMesh* mesh, Tile* tile,
35
+ const glm::mat4& mvp, const glm::vec2& screen,
36
+ float dt, float dz, bool drawAll,
37
+ bool onlyTransitions, bool isProxy) {
38
+
39
+ if (!mesh) { return ; }
40
+ auto labelMesh = dynamic_cast <const LabelSet*>(mesh);
41
+ if (!labelMesh) { return ; }
42
+
43
+ for (auto & label : labelMesh->getLabels ()) {
44
+ if (!label->update (mvp, screen, dz, drawAll)) {
45
+ // skip dead labels
46
+ continue ;
47
+ }
48
+
49
+ if (onlyTransitions) {
50
+ if (label->occludedLastFrame ()) { label->occlude (); }
51
+
52
+ if (label->visibleState () || !label->canOcclude ()) {
53
+ m_needUpdate |= label->evalState (dt);
54
+ label->pushTransform ();
55
+ }
56
+ } else if (label->canOcclude ()) {
57
+ m_labels.emplace_back (label.get (), tile, isProxy);
58
+ } else {
59
+ m_needUpdate |= label->evalState (dt);
60
+ label->pushTransform ();
61
+ }
62
+ }
63
+ }
64
+
33
65
void Labels::updateLabels (const View& _view, float _dt,
34
66
const std::vector<std::unique_ptr<Style >>& _styles,
35
67
const std::vector<std::shared_ptr<Tile>>& _tiles,
68
+ const std::vector<std::unique_ptr<Marker>>& _markers,
36
69
bool _onlyTransitions) {
37
70
38
71
// Keep labels for debugDraw
@@ -60,30 +93,22 @@ void Labels::updateLabels(const View& _view, float _dt,
60
93
61
94
for (const auto & style : _styles) {
62
95
const auto & mesh = tile->getMesh (*style);
63
- if (!mesh) { continue ; }
96
+ processLabelUpdate (mesh.get (), tile.get (), mvp, screenSize, _dt, dz,
97
+ drawAllLabels, _onlyTransitions, proxyTile);
98
+ }
99
+ }
64
100
65
- auto labelMesh = dynamic_cast <const LabelSet*>(mesh.get ());
66
- if (!labelMesh) { continue ; }
67
- for (auto & label : labelMesh->getLabels ()) {
68
- if (!label->update (mvp, screenSize, dz, drawAllLabels)) {
69
- // skip dead labels
70
- continue ;
71
- }
101
+ for (const auto & marker : _markers) {
72
102
73
- if (_onlyTransitions) {
74
- if (label->occludedLastFrame ()) { label->occlude (); }
75
-
76
- if (label->visibleState () || !label->canOcclude ()) {
77
- m_needUpdate |= label->evalState (_dt);
78
- label->pushTransform ();
79
- }
80
- } else if (label->canOcclude ()) {
81
- m_labels.emplace_back (label.get (), tile.get (), proxyTile);
82
- } else {
83
- m_needUpdate |= label->evalState (_dt);
84
- label->pushTransform ();
85
- }
86
- }
103
+ glm::mat4 mvp = _view.getViewProjectionMatrix () * marker->modelMatrix ();
104
+
105
+ for (const auto & style : _styles) {
106
+
107
+ if (marker->styleId () != style->getID ()) { continue ; }
108
+
109
+ const auto & mesh = marker->mesh ();
110
+ processLabelUpdate (mesh, nullptr , mvp, screenSize, _dt, dz,
111
+ drawAllLabels, _onlyTransitions, false );
87
112
}
88
113
}
89
114
}
@@ -182,6 +207,9 @@ bool Labels::labelComparator(const LabelEntry& _a, const LabelEntry& _b) {
182
207
if (_a.priority != _b.priority ) {
183
208
return _a.priority < _b.priority ;
184
209
}
210
+ if (!_a.tile || !_b.tile ) {
211
+ return (bool )_a.tile ;
212
+ }
185
213
if (_a.tile ->getID ().z != _b.tile ->getID ().z ) {
186
214
return _a.tile ->getID ().z > _b.tile ->getID ().z ;
187
215
}
@@ -323,10 +351,11 @@ bool Labels::withinRepeatDistance(Label *_label) {
323
351
void Labels::updateLabelSet (const View& _view, float _dt,
324
352
const std::vector<std::unique_ptr<Style >>& _styles,
325
353
const std::vector<std::shared_ptr<Tile>>& _tiles,
354
+ const std::vector<std::unique_ptr<Marker>>& _markers,
326
355
TileCache& _cache) {
327
356
328
357
// / Collect and update labels from visible tiles
329
- updateLabels (_view, _dt, _styles, _tiles, false );
358
+ updateLabels (_view, _dt, _styles, _tiles, _markers, false );
330
359
331
360
sortLabels ();
332
361
0 commit comments