@@ -33,12 +33,16 @@ export class MeasureManager {
33
33
*/
34
34
private polygonDistance : boolean = true ;
35
35
36
- /**
37
- * 测量id
38
- *
39
- * 用于创建标注文字id
40
- */
41
- readonly id_layer_measure_symbol = Tools . uuid ( ) ;
36
+
37
+ readonly id_source_measure_symbol = Tools . uuid ( ) ;
38
+
39
+
40
+ readonly id_layer_measrue_point = Tools . uuid ( ) ;
41
+ readonly id_layer_measrue_line = Tools . uuid ( ) ;
42
+ readonly id_layer_measrue_line_segment = Tools . uuid ( ) ;
43
+ readonly id_layer_measrue_polygon = Tools . uuid ( ) ;
44
+ readonly id_layer_measrue_polygon_line = Tools . uuid ( ) ;
45
+ readonly id_layer_measure_polygon_line_segment = Tools . uuid ( ) ;
42
46
43
47
/**
44
48
* 面方向图层id
@@ -68,32 +72,12 @@ export class MeasureManager {
68
72
this . glManager . on ( 'clear' , ( ) => this . customFeatures = [ ] ) ;
69
73
this . glManager . on ( 'all' , ( ) => this . renderMeasure ( ) ) ;
70
74
71
- this . glManager . addLayer ( this . id_layer_measure_symbol ) ;
72
- this . glManager . addLayer ( this . id_layer_polygon_clockwise ) ;
73
-
74
75
/**
75
- * 添加测量数值图层
76
+ * 添加数据源
76
77
*/
77
- this . glManager . map . addLayer ( {
78
- id : this . id_layer_measure_symbol ,
79
- type : 'symbol' ,
80
- source : {
81
- type : 'geojson' ,
82
- data : { type : 'FeatureCollection' , features : [ ] }
83
- } ,
84
- layout : {
85
- "text-field" : [ 'get' , 'value' ] ,
86
- 'text-size' : [ 'case' ,
87
- [ 'boolean' , [ 'get' , 'center' ] , false ] , 12 ,
88
- [ '==' , [ 'get' , 'type' ] , 'Polygon' ] , 16 , 14 ] ,
89
- 'text-offset' : [ 0 , - 1 ]
90
- } ,
91
- paint : {
92
- 'text-color' : [ 'case' ,
93
- [ 'boolean' , [ 'get' , 'center' ] , false ] , 'red' , 'black' ] ,
94
- 'text-halo-color' : 'white' ,
95
- 'text-halo-width' : 2
96
- }
78
+ this . glManager . map . addSource ( this . id_source_measure_symbol , {
79
+ type : 'geojson' ,
80
+ data : { type : 'FeatureCollection' , features : [ ] }
97
81
} ) ;
98
82
99
83
/**
@@ -119,7 +103,127 @@ export class MeasureManager {
119
103
'text-halo-width' : 3
120
104
} ,
121
105
filter : [ '==' , '$type' , 'Polygon' ]
122
- } , this . id_layer_measure_symbol ) ;
106
+ } ) ;
107
+
108
+ /**
109
+ * 测量点结果的图层
110
+ */
111
+ this . glManager . map . addLayer ( {
112
+ id : this . id_layer_measrue_point ,
113
+ type : 'symbol' ,
114
+ source : this . id_source_measure_symbol ,
115
+ layout : {
116
+ "text-field" : [ 'get' , 'value' ] ,
117
+ 'text-size' : 14 ,
118
+ 'text-offset' : [ 0 , - 1 ]
119
+ } ,
120
+ paint : {
121
+ 'text-color' : 'black' ,
122
+ 'text-halo-color' : 'white' ,
123
+ 'text-halo-width' : 2
124
+ } ,
125
+ filter : [ '==' , [ 'get' , 'type' ] , 'point' ]
126
+ } ) ;
127
+
128
+ /**
129
+ * 添加线测量总结果图层
130
+ */
131
+ this . glManager . map . addLayer ( {
132
+ id : this . id_layer_measrue_line ,
133
+ type : 'symbol' ,
134
+ source : this . id_source_measure_symbol ,
135
+ layout : {
136
+ "text-field" : [ 'get' , 'value' ] ,
137
+ 'text-size' : 14 ,
138
+ 'text-offset' : [ 0 , - 1 ]
139
+ } ,
140
+ paint : {
141
+ 'text-color' : 'black' ,
142
+ 'text-halo-color' : 'white' ,
143
+ 'text-halo-width' : 2
144
+ } ,
145
+ filter : [ '==' , [ 'get' , 'type' ] , 'line' ]
146
+ } ) ;
147
+
148
+ /**
149
+ * 添加线测量线段结果图层
150
+ */
151
+ this . glManager . map . addLayer ( {
152
+ id : this . id_layer_measrue_line_segment ,
153
+ type : 'symbol' ,
154
+ source : this . id_source_measure_symbol ,
155
+ layout : {
156
+ "text-field" : [ 'get' , 'value' ] ,
157
+ 'text-size' : 12 ,
158
+ 'text-offset' : [ 0 , - 1 ]
159
+ } ,
160
+ paint : {
161
+ 'text-color' : 'red' ,
162
+ 'text-halo-color' : 'white' ,
163
+ 'text-halo-width' : 2
164
+ } ,
165
+ filter : [ '==' , [ 'get' , 'type' ] , 'line-segment' ]
166
+ } ) ;
167
+
168
+ /**
169
+ * 添加面测量结果图层
170
+ */
171
+ this . glManager . map . addLayer ( {
172
+ id : this . id_layer_measrue_polygon ,
173
+ type : 'symbol' ,
174
+ source : this . id_source_measure_symbol ,
175
+ layout : {
176
+ "text-field" : [ 'get' , 'value' ] ,
177
+ 'text-size' : 18 ,
178
+ 'text-offset' : [ 0 , - 1 ]
179
+ } ,
180
+ paint : {
181
+ 'text-color' : 'black' ,
182
+ 'text-halo-color' : 'white' ,
183
+ 'text-halo-width' : 2
184
+ } ,
185
+ filter : [ '==' , [ 'get' , 'type' ] , 'polygon' ]
186
+ } ) ;
187
+
188
+ /**
189
+ * 添加面测量外侧线结果图层
190
+ */
191
+ this . glManager . map . addLayer ( {
192
+ id : this . id_layer_measrue_polygon_line ,
193
+ type : 'symbol' ,
194
+ source : this . id_source_measure_symbol ,
195
+ layout : {
196
+ "text-field" : [ 'get' , 'value' ] ,
197
+ 'text-size' : 14 ,
198
+ 'text-offset' : [ 0 , - 1 ]
199
+ } ,
200
+ paint : {
201
+ 'text-color' : 'black' ,
202
+ 'text-halo-color' : 'white' ,
203
+ 'text-halo-width' : 2
204
+ } ,
205
+ filter : [ '==' , [ 'get' , 'type' ] , 'polygon-line' ]
206
+ } ) ;
207
+
208
+ /**
209
+ * 添加面测量外侧线段结果图层
210
+ */
211
+ this . glManager . map . addLayer ( {
212
+ id : this . id_layer_measure_polygon_line_segment ,
213
+ type : 'symbol' ,
214
+ source : this . id_source_measure_symbol ,
215
+ layout : {
216
+ "text-field" : [ 'get' , 'value' ] ,
217
+ 'text-size' : 12 ,
218
+ 'text-offset' : [ 0 , - 1 ]
219
+ } ,
220
+ paint : {
221
+ 'text-color' : 'red' ,
222
+ 'text-halo-color' : 'white' ,
223
+ 'text-halo-width' : 2
224
+ } ,
225
+ filter : [ '==' , [ 'get' , 'type' ] , 'polygon-line-segment' ]
226
+ } ) ;
123
227
124
228
this . units = {
125
229
area : 'M2KM2' ,
@@ -136,8 +240,15 @@ export class MeasureManager {
136
240
}
137
241
138
242
setVisible ( visible : boolean ) {
139
- this . glManager . map . setLayoutProperty ( this . id_layer_measure_symbol , 'visibility' , visible ? 'visible' : 'none' ) ;
140
- this . glManager . map . setLayoutProperty ( this . id_layer_polygon_clockwise , 'visibility' , visible ? 'visible' : 'none' ) ;
243
+ [ this . id_layer_measrue_point ,
244
+ this . id_layer_measrue_line ,
245
+ this . id_layer_measrue_line_segment ,
246
+ this . id_layer_measrue_polygon ,
247
+ this . id_layer_measrue_polygon_line ,
248
+ this . id_layer_measure_polygon_line_segment ,
249
+ this . id_layer_polygon_clockwise ] . forEach ( id => {
250
+ this . glManager . map . setLayoutProperty ( id , 'visibility' , visible ? 'visible' : 'none' ) ;
251
+ } ) ;
141
252
}
142
253
143
254
/**
@@ -220,7 +331,8 @@ export class MeasureManager {
220
331
* @param val
221
332
*/
222
333
showPolygonDirection ( val : boolean ) {
223
- this . glManager . map . setLayoutProperty ( this . id_layer_polygon_clockwise , "visibility" , val ? "visible" : 'none' ) ;
334
+ this . glManager . map . setFilter ( this . id_layer_polygon_clockwise ,
335
+ val ? [ '==' , '$type' , 'Polygon' ] : [ '==' , '1' , '0' ] ) ;
224
336
}
225
337
226
338
/**
@@ -237,8 +349,11 @@ export class MeasureManager {
237
349
* @param val
238
350
*/
239
351
showSegment ( val : boolean ) {
240
- this . glManager . map . setFilter ( this . id_layer_measure_symbol ,
241
- val ? undefined : [ '!' , [ 'boolean' , [ 'get' , 'center' ] , false ] ] ) ;
352
+ this . glManager . map . setFilter ( this . id_layer_measrue_line_segment ,
353
+ val ? [ '==' , [ 'get' , 'type' ] , 'line-segment' ] : [ '==' , '1' , '0' ] ) ;
354
+
355
+ this . glManager . map . setFilter ( this . id_layer_measure_polygon_line_segment ,
356
+ val ? [ '==' , [ 'get' , 'type' ] , 'polygon-line-segment' ] : [ '==' , '1' , '0' ] ) ;
242
357
}
243
358
244
359
/**
@@ -248,7 +363,7 @@ export class MeasureManager {
248
363
const features = this . glManager . fc . features . concat ( this . customFeatures ) ;
249
364
250
365
// 设置测量结果数据
251
- ( this . glManager . map . getSource ( this . id_layer_measure_symbol ) ) . setData ( {
366
+ ( this . glManager . map . getSource ( this . id_source_measure_symbol ) ) . setData ( {
252
367
type : 'FeatureCollection' ,
253
368
features : Measurement . cal ( features , {
254
369
polygon : {
@@ -299,14 +414,18 @@ export class MeasureManager {
299
414
} )
300
415
} ) ;
301
416
302
- // 设置方向数据
417
+ // 设置面方向数据
303
418
( this . glManager . map . getSource ( this . id_layer_polygon_clockwise ) ) . setData ( {
304
419
type : 'FeatureCollection' ,
305
- features : features . map ( x => {
306
- if ( x . geometry . type === 'Polygon' ) {
307
- ( x . properties as any ) . clockwise = booleanClockwise ( x . geometry . coordinates [ 0 ] ) ;
420
+ features : features . filter ( x => x . geometry . type === 'Polygon' ) . map ( x => {
421
+ return {
422
+ type : 'Feature' ,
423
+ geometry : x . geometry ,
424
+ properties : {
425
+ ...x . properties ,
426
+ clockwise : booleanClockwise ( ( x . geometry as any ) . coordinates [ 0 ] )
427
+ }
308
428
}
309
- return x ;
310
429
} )
311
430
} ) ;
312
431
}
0 commit comments