@@ -33,12 +33,16 @@ export class MeasureManager {
3333 */
3434 private polygonDistance : boolean = true ;
3535
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 ( ) ;
4246
4347 /**
4448 * 面方向图层id
@@ -68,32 +72,12 @@ export class MeasureManager {
6872 this . glManager . on ( 'clear' , ( ) => this . customFeatures = [ ] ) ;
6973 this . glManager . on ( 'all' , ( ) => this . renderMeasure ( ) ) ;
7074
71- this . glManager . addLayer ( this . id_layer_measure_symbol ) ;
72- this . glManager . addLayer ( this . id_layer_polygon_clockwise ) ;
73-
7475 /**
75- * 添加测量数值图层
76+ * 添加数据源
7677 */
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 : [ ] }
9781 } ) ;
9882
9983 /**
@@ -119,7 +103,127 @@ export class MeasureManager {
119103 'text-halo-width' : 3
120104 } ,
121105 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+ } ) ;
123227
124228 this . units = {
125229 area : 'M2KM2' ,
@@ -136,8 +240,15 @@ export class MeasureManager {
136240 }
137241
138242 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+ } ) ;
141252 }
142253
143254 /**
@@ -220,7 +331,8 @@ export class MeasureManager {
220331 * @param val
221332 */
222333 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' ] ) ;
224336 }
225337
226338 /**
@@ -237,8 +349,11 @@ export class MeasureManager {
237349 * @param val
238350 */
239351 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' ] ) ;
242357 }
243358
244359 /**
@@ -248,7 +363,7 @@ export class MeasureManager {
248363 const features = this . glManager . fc . features . concat ( this . customFeatures ) ;
249364
250365 // 设置测量结果数据
251- ( this . glManager . map . getSource ( this . id_layer_measure_symbol ) ) . setData ( {
366+ ( this . glManager . map . getSource ( this . id_source_measure_symbol ) ) . setData ( {
252367 type : 'FeatureCollection' ,
253368 features : Measurement . cal ( features , {
254369 polygon : {
@@ -299,14 +414,18 @@ export class MeasureManager {
299414 } )
300415 } ) ;
301416
302- // 设置方向数据
417+ // 设置面方向数据
303418 ( this . glManager . map . getSource ( this . id_layer_polygon_clockwise ) ) . setData ( {
304419 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+ }
308428 }
309- return x ;
310429 } )
311430 } ) ;
312431 }
0 commit comments