11import booleanClockwise from '@turf/boolean-clockwise' ;
2- import { DrawManager , DrawOptions } from './geojson-draw-manager' ;
2+ import { DrawManager } from './geojson-draw-manager' ;
33import { GeoJSONLayerManagerBase } from './geojson-layer-manager' ;
44import { Units , Measurement , Tools } from '../utils' ;
55import { TIdentityGeoJSONFeature } from '../types' ;
@@ -9,24 +9,12 @@ type TMeasureUnits = {
99 length : Units . TUnitsLength | "MKM" ,
1010}
1111
12- interface MeasureOptions extends DrawOptions {
12+ interface MeasureOptions {
1313}
1414
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 {
2916
17+ private glManager : GeoJSONLayerManagerBase ;
3018
3119 private customFeatures : TIdentityGeoJSONFeature [ ] = [ ] ;
3220
@@ -45,6 +33,20 @@ export class MeasureManager extends DrawManager {
4533 */
4634 private polygonDistance : boolean = true ;
4735
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+
4850 /**
4951 * 长度单位
5052 */
@@ -59,17 +61,18 @@ export class MeasureManager extends DrawManager {
5961 return this . units . area ;
6062 }
6163
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 ;
6566
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 ) ;
6871
6972 /**
7073 * 添加测量数值图层
7174 */
72- glManager . map . addLayer ( {
75+ this . glManager . map . addLayer ( {
7376 id : this . id_layer_measure_symbol ,
7477 type : 'symbol' ,
7578 source : {
@@ -94,7 +97,7 @@ export class MeasureManager extends DrawManager {
9497 /**
9598 * 添加面方向图层
9699 */
97- glManager . map . addLayer ( {
100+ this . glManager . map . addLayer ( {
98101 id : this . id_layer_polygon_clockwise ,
99102 type : 'symbol' ,
100103 source : {
@@ -236,15 +239,6 @@ export class MeasureManager extends DrawManager {
236239 val ? undefined : [ '!' , [ 'boolean' , [ 'get' , 'center' ] , false ] ] ) ;
237240 }
238241
239- /**
240- * 清除测量数据
241- */
242- clear ( ) {
243- super . clear ( ) ;
244- this . customFeatures = [ ] ;
245- this . renderMeasure ( ) ;
246- }
247-
248242 /**
249243 * 重绘
250244 */
0 commit comments