1
1
import booleanClockwise from '@turf/boolean-clockwise' ;
2
- import { DrawManager , DrawOptions } from './geojson-draw-manager' ;
2
+ import { DrawManager } from './geojson-draw-manager' ;
3
3
import { GeoJSONLayerManagerBase } from './geojson-layer-manager' ;
4
4
import { Units , Measurement , Tools } from '../utils' ;
5
5
import { TIdentityGeoJSONFeature } from '../types' ;
@@ -9,24 +9,12 @@ type TMeasureUnits = {
9
9
length : Units . TUnitsLength | "MKM" ,
10
10
}
11
11
12
- interface MeasureOptions extends DrawOptions {
12
+ interface MeasureOptions {
13
13
}
14
14
15
- export class MeasureManager extends DrawManager {
16
- /**
17
- * 测量id
18
- *
19
- * 用于创建标注文字id
20
- */
21
- readonly id_layer_measure_symbol = Tools . uuid ( ) ;
22
-
23
- /**
24
- * 面方向图层id
25
- *
26
- * 用于创建面方向layer和source
27
- */
28
- readonly id_layer_polygon_clockwise = Tools . uuid ( ) ;
15
+ export class MeasureManager {
29
16
17
+ private glManager : GeoJSONLayerManagerBase ;
30
18
31
19
private customFeatures : TIdentityGeoJSONFeature [ ] = [ ] ;
32
20
@@ -45,6 +33,20 @@ export class MeasureManager extends DrawManager {
45
33
*/
46
34
private polygonDistance : boolean = true ;
47
35
36
+ /**
37
+ * 测量id
38
+ *
39
+ * 用于创建标注文字id
40
+ */
41
+ readonly id_layer_measure_symbol = Tools . uuid ( ) ;
42
+
43
+ /**
44
+ * 面方向图层id
45
+ *
46
+ * 用于创建面方向layer和source
47
+ */
48
+ readonly id_layer_polygon_clockwise = Tools . uuid ( ) ;
49
+
48
50
/**
49
51
* 长度单位
50
52
*/
@@ -59,17 +61,18 @@ export class MeasureManager extends DrawManager {
59
61
return this . units . area ;
60
62
}
61
63
62
- constructor ( glManager : GeoJSONLayerManagerBase , options : MeasureOptions ) {
63
- super ( glManager , options ) ;
64
- glManager . on ( 'all' , ( ) => this . renderMeasure ( ) ) ;
64
+ constructor ( dataSource : DrawManager | GeoJSONLayerManagerBase , options : MeasureOptions = { } ) {
65
+ this . glManager = dataSource instanceof DrawManager ? dataSource . glManager : dataSource ;
65
66
66
- glManager . addLayer ( this . id_layer_measure_symbol ) ;
67
- glManager . addLayer ( this . id_layer_polygon_clockwise ) ;
67
+ this . glManager . on ( 'all' , ( ) => this . renderMeasure ( ) ) ;
68
+
69
+ this . glManager . addLayer ( this . id_layer_measure_symbol ) ;
70
+ this . glManager . addLayer ( this . id_layer_polygon_clockwise ) ;
68
71
69
72
/**
70
73
* 添加测量数值图层
71
74
*/
72
- glManager . map . addLayer ( {
75
+ this . glManager . map . addLayer ( {
73
76
id : this . id_layer_measure_symbol ,
74
77
type : 'symbol' ,
75
78
source : {
@@ -94,7 +97,7 @@ export class MeasureManager extends DrawManager {
94
97
/**
95
98
* 添加面方向图层
96
99
*/
97
- glManager . map . addLayer ( {
100
+ this . glManager . map . addLayer ( {
98
101
id : this . id_layer_polygon_clockwise ,
99
102
type : 'symbol' ,
100
103
source : {
@@ -236,15 +239,6 @@ export class MeasureManager extends DrawManager {
236
239
val ? undefined : [ '!' , [ 'boolean' , [ 'get' , 'center' ] , false ] ] ) ;
237
240
}
238
241
239
- /**
240
- * 清除测量数据
241
- */
242
- clear ( ) {
243
- super . clear ( ) ;
244
- this . customFeatures = [ ] ;
245
- this . renderMeasure ( ) ;
246
- }
247
-
248
242
/**
249
243
* 重绘
250
244
*/
0 commit comments