@@ -19,24 +19,56 @@ import IndexBuffer from '../gl/index_buffer';
19
19
20
20
export default drawCollisionDebug ;
21
21
22
+ type TileBatch = {
23
+ circleArray : Array < number > ,
24
+ circleOffset : number ,
25
+ transform : mat4 ,
26
+ invTransform : mat4
27
+ } ;
28
+
22
29
let quadTriangles : ?QuadTriangleArray ;
23
30
24
31
function drawCollisionDebug ( painter : Painter , sourceCache : SourceCache , layer : StyleLayer , coords : Array < OverscaledTileID > , translate : [ number , number ] , translateAnchor : 'map' | 'viewport' , isText : boolean ) {
25
32
const context = painter . context ;
26
33
const gl = context . gl ;
27
34
const program = painter . useProgram ( 'collisionBox' ) ;
35
+ const tileBatches : Array < TileBatch > = [];
36
+ let circleCount = 0;
37
+ let circleOffset = 0;
28
38
29
39
for (let i = 0; i < coords . length ; i ++ ) {
30
40
const coord = coords [ i ] ;
31
41
const tile = sourceCache . getTile ( coord ) ;
32
42
const bucket : ?SymbolBucket = ( tile . getBucket ( layer ) : any ) ;
33
43
if ( ! bucket ) continue ;
34
- const buffers = isText ? bucket . textCollisionBox : bucket . iconCollisionBox ;
35
- if ( ! buffers ) continue ;
36
44
let posMatrix = coord . posMatrix ;
37
45
if ( translate [ 0 ] !== 0 || translate [ 1 ] !== 0 ) {
38
46
posMatrix = painter . translatePosMatrix ( coord . posMatrix , tile , translate , translateAnchor ) ;
39
47
}
48
+ const buffers = isText ? bucket . textCollisionBox : bucket . iconCollisionBox ;
49
+ // Get collision circle data of this bucket
50
+ const circleArray : Array < number > = bucket.collisionCircleArray;
51
+ if (circleArray.length > 0 ) {
52
+ // We need to know the projection matrix that was used for projecting collision circles to the screen.
53
+ // This might vary between buckets as the symbol placement is a continous process. This matrix is
54
+ // required for transforming points from previous screen space to the current one
55
+ const invTransform = mat4 . create ( ) ;
56
+ const transform = posMatrix ;
57
+
58
+ mat4 . mul ( invTransform , bucket . placementInvProjMatrix , painter . transform . glCoordMatrix ) ;
59
+ mat4 . mul ( invTransform , invTransform , bucket . placementViewportMatrix ) ;
60
+
61
+ tileBatches . push ( {
62
+ circleArray,
63
+ circleOffset,
64
+ transform,
65
+ invTransform
66
+ } ) ;
67
+
68
+ circleCount += circleArray . length / 4 ; // 4 values per circle
69
+ circleOffset = circleCount ;
70
+ }
71
+ if ( ! buffers ) continue ;
40
72
program . draw ( context , gl . LINES ,
41
73
DepthMode . disabled , StencilMode . disabled ,
42
74
painter . colorModeForRenderPass ( ) ,
@@ -50,65 +82,11 @@ function drawCollisionDebug(painter: Painter, sourceCache: SourceCache, layer: S
50
82
buffers . collisionVertexBuffer ) ;
51
83
}
52
84
53
- if ( isText )
54
- drawCollisionCircles ( painter , sourceCache , layer , coords , translate , translateAnchor ) ;
55
- }
56
-
57
- type TileBatch = {
58
- circleArray : Array < number > ,
59
- circleOffset : number ,
60
- transform : mat4 ,
61
- invTransform : mat4
62
- } ;
63
-
64
- function drawCollisionCircles ( painter : Painter , sourceCache : SourceCache , layer : StyleLayer , coords : Array < OverscaledTileID > , translate : [ number , number ] , translateAnchor : 'map' | 'viewport' ) {
65
-
66
- const tileBatches : Array < TileBatch > = [];
67
- let circleCount = 0;
68
- let circleOffset = 0;
69
-
70
- for (let i = 0; i < coords . length ; i ++ ) {
71
- const coord = coords [ i ] ;
72
- const tile = sourceCache . getTile ( coord ) ;
73
- const bucket : ?SymbolBucket = ( tile . getBucket ( layer ) : any ) ;
74
- if ( ! bucket ) continue ;
75
-
76
- const circleArray : Array < number > = bucket.collisionCircleArray;
77
-
78
- if (!circleArray.length)
79
- continue;
80
-
81
- let posMatrix = coord.posMatrix;
82
-
83
- if (translate[0] !== 0 || translate[1] !== 0) {
84
- posMatrix = painter . translatePosMatrix ( coord . posMatrix , tile , translate , translateAnchor ) ;
85
- }
86
-
87
- // We need to know the projection matrix that was used for projecting collision circles to the screen.
88
- // This might vary between buckets as the symbol placement is a continous process. This matrix is
89
- // required for transforming points from previous screen space to the current one
90
- const invTransform = mat4.create();
91
- const transform = posMatrix;
92
-
93
- mat4.mul(invTransform, bucket.placementInvProjMatrix, painter.transform.glCoordMatrix);
94
- mat4.mul(invTransform, invTransform, bucket.placementViewportMatrix);
95
-
96
- tileBatches.push({
97
- circleArray ,
98
- circleOffset ,
99
- transform ,
100
- invTransform
101
- } );
102
-
103
- circleCount += circleArray.length / 4; // 4 values per circle
104
- circleOffset = circleCount;
105
- }
106
-
107
- if ( ! tileBatches . length )
85
+ if ( ! isText || ! tileBatches . length ) {
108
86
return ;
87
+ }
109
88
110
- const context = painter . context ;
111
- const gl = context . gl ;
89
+ // Render collision circles
112
90
const circleProgram = painter . useProgram ( 'collisionCircle' ) ;
113
91
114
92
// Construct vertex data
0 commit comments